Index.h revision dca8ee8b7bc86076916a3a80f553f7a4e98c14af
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 121/** 122 * \defgroup CINDEX_STRING String manipulation routines 123 * 124 * @{ 125 */ 126 127/** 128 * \brief A character string. 129 * 130 * The \c CXString type is used to return strings from the interface when 131 * the ownership of that string might different from one call to the next. 132 * Use \c clang_getCString() to retrieve the string data and, once finished 133 * with the string data, call \c clang_disposeString() to free the string. 134 */ 135typedef struct { 136 void *data; 137 unsigned private_flags; 138} CXString; 139 140/** 141 * \brief Retrieve the character data associated with the given string. 142 */ 143CINDEX_LINKAGE const char *clang_getCString(CXString string); 144 145/** 146 * \brief Free the given string, 147 */ 148CINDEX_LINKAGE void clang_disposeString(CXString string); 149 150/** 151 * @} 152 */ 153 154/** 155 * \brief clang_createIndex() provides a shared context for creating 156 * translation units. It provides two options: 157 * 158 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 159 * declarations (when loading any new translation units). A "local" declaration 160 * is one that belongs in the translation unit itself and not in a precompiled 161 * header that was used by the translation unit. If zero, all declarations 162 * will be enumerated. 163 * 164 * Here is an example: 165 * 166 * // excludeDeclsFromPCH = 1, displayDiagnostics=1 167 * Idx = clang_createIndex(1, 1); 168 * 169 * // IndexTest.pch was produced with the following command: 170 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 171 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 172 * 173 * // This will load all the symbols from 'IndexTest.pch' 174 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 175 * TranslationUnitVisitor, 0); 176 * clang_disposeTranslationUnit(TU); 177 * 178 * // This will load all the symbols from 'IndexTest.c', excluding symbols 179 * // from 'IndexTest.pch'. 180 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 181 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 182 * 0, 0); 183 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 184 * TranslationUnitVisitor, 0); 185 * clang_disposeTranslationUnit(TU); 186 * 187 * This process of creating the 'pch', loading it separately, and using it (via 188 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 189 * (which gives the indexer the same performance benefit as the compiler). 190 */ 191CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 192 int displayDiagnostics); 193 194/** 195 * \brief Destroy the given index. 196 * 197 * The index must not be destroyed until all of the translation units created 198 * within that index have been destroyed. 199 */ 200CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 201 202/** 203 * \defgroup CINDEX_FILES File manipulation routines 204 * 205 * @{ 206 */ 207 208/** 209 * \brief A particular source file that is part of a translation unit. 210 */ 211typedef void *CXFile; 212 213 214/** 215 * \brief Retrieve the complete file and path name of the given file. 216 */ 217CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); 218 219/** 220 * \brief Retrieve the last modification time of the given file. 221 */ 222CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 223 224/** 225 * \brief Determine whether the given header is guarded against 226 * multiple inclusions, either with the conventional 227 * #ifndef/#define/#endif macro guards or with #pragma once. 228 */ 229CINDEX_LINKAGE unsigned 230clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file); 231 232/** 233 * \brief Retrieve a file handle within the given translation unit. 234 * 235 * \param tu the translation unit 236 * 237 * \param file_name the name of the file. 238 * 239 * \returns the file handle for the named file in the translation unit \p tu, 240 * or a NULL file handle if the file was not a part of this translation unit. 241 */ 242CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 243 const char *file_name); 244 245/** 246 * @} 247 */ 248 249/** 250 * \defgroup CINDEX_LOCATIONS Physical source locations 251 * 252 * Clang represents physical source locations in its abstract syntax tree in 253 * great detail, with file, line, and column information for the majority of 254 * the tokens parsed in the source code. These data types and functions are 255 * used to represent source location information, either for a particular 256 * point in the program or for a range of points in the program, and extract 257 * specific location information from those data types. 258 * 259 * @{ 260 */ 261 262/** 263 * \brief Identifies a specific source location within a translation 264 * unit. 265 * 266 * Use clang_getInstantiationLocation() or clang_getSpellingLocation() 267 * to map a source location to a particular file, line, and column. 268 */ 269typedef struct { 270 void *ptr_data[2]; 271 unsigned int_data; 272} CXSourceLocation; 273 274/** 275 * \brief Identifies a half-open character range in the source code. 276 * 277 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 278 * starting and end locations from a source range, respectively. 279 */ 280typedef struct { 281 void *ptr_data[2]; 282 unsigned begin_int_data; 283 unsigned end_int_data; 284} CXSourceRange; 285 286/** 287 * \brief Retrieve a NULL (invalid) source location. 288 */ 289CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); 290 291/** 292 * \determine Determine whether two source locations, which must refer into 293 * the same translation unit, refer to exactly the same point in the source 294 * code. 295 * 296 * \returns non-zero if the source locations refer to the same location, zero 297 * if they refer to different locations. 298 */ 299CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 300 CXSourceLocation loc2); 301 302/** 303 * \brief Retrieves the source location associated with a given file/line/column 304 * in a particular translation unit. 305 */ 306CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 307 CXFile file, 308 unsigned line, 309 unsigned column); 310/** 311 * \brief Retrieves the source location associated with a given character offset 312 * in a particular translation unit. 313 */ 314CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, 315 CXFile file, 316 unsigned offset); 317 318/** 319 * \brief Retrieve a NULL (invalid) source range. 320 */ 321CINDEX_LINKAGE CXSourceRange clang_getNullRange(); 322 323/** 324 * \brief Retrieve a source range given the beginning and ending source 325 * locations. 326 */ 327CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 328 CXSourceLocation end); 329 330/** 331 * \brief Retrieve the file, line, column, and offset represented by 332 * the given source location. 333 * 334 * If the location refers into a macro instantiation, retrieves the 335 * location of the macro instantiation. 336 * 337 * \param location the location within a source file that will be decomposed 338 * into its parts. 339 * 340 * \param file [out] if non-NULL, will be set to the file to which the given 341 * source location points. 342 * 343 * \param line [out] if non-NULL, will be set to the line to which the given 344 * source location points. 345 * 346 * \param column [out] if non-NULL, will be set to the column to which the given 347 * source location points. 348 * 349 * \param offset [out] if non-NULL, will be set to the offset into the 350 * buffer to which the given source location points. 351 */ 352CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 353 CXFile *file, 354 unsigned *line, 355 unsigned *column, 356 unsigned *offset); 357 358/** 359 * \brief Retrieve the file, line, column, and offset represented by 360 * the given source location. 361 * 362 * If the location refers into a macro instantiation, return where the 363 * location was originally spelled in the source file. 364 * 365 * \param location the location within a source file that will be decomposed 366 * into its parts. 367 * 368 * \param file [out] if non-NULL, will be set to the file to which the given 369 * source location points. 370 * 371 * \param line [out] if non-NULL, will be set to the line to which the given 372 * source location points. 373 * 374 * \param column [out] if non-NULL, will be set to the column to which the given 375 * source location points. 376 * 377 * \param offset [out] if non-NULL, will be set to the offset into the 378 * buffer to which the given source location points. 379 */ 380CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location, 381 CXFile *file, 382 unsigned *line, 383 unsigned *column, 384 unsigned *offset); 385 386/** 387 * \brief Retrieve a source location representing the first character within a 388 * source range. 389 */ 390CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 391 392/** 393 * \brief Retrieve a source location representing the last character within a 394 * source range. 395 */ 396CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 397 398/** 399 * @} 400 */ 401 402/** 403 * \defgroup CINDEX_DIAG Diagnostic reporting 404 * 405 * @{ 406 */ 407 408/** 409 * \brief Describes the severity of a particular diagnostic. 410 */ 411enum CXDiagnosticSeverity { 412 /** 413 * \brief A diagnostic that has been suppressed, e.g., by a command-line 414 * option. 415 */ 416 CXDiagnostic_Ignored = 0, 417 418 /** 419 * \brief This diagnostic is a note that should be attached to the 420 * previous (non-note) diagnostic. 421 */ 422 CXDiagnostic_Note = 1, 423 424 /** 425 * \brief This diagnostic indicates suspicious code that may not be 426 * wrong. 427 */ 428 CXDiagnostic_Warning = 2, 429 430 /** 431 * \brief This diagnostic indicates that the code is ill-formed. 432 */ 433 CXDiagnostic_Error = 3, 434 435 /** 436 * \brief This diagnostic indicates that the code is ill-formed such 437 * that future parser recovery is unlikely to produce useful 438 * results. 439 */ 440 CXDiagnostic_Fatal = 4 441}; 442 443/** 444 * \brief A single diagnostic, containing the diagnostic's severity, 445 * location, text, source ranges, and fix-it hints. 446 */ 447typedef void *CXDiagnostic; 448 449/** 450 * \brief Determine the number of diagnostics produced for the given 451 * translation unit. 452 */ 453CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); 454 455/** 456 * \brief Retrieve a diagnostic associated with the given translation unit. 457 * 458 * \param Unit the translation unit to query. 459 * \param Index the zero-based diagnostic number to retrieve. 460 * 461 * \returns the requested diagnostic. This diagnostic must be freed 462 * via a call to \c clang_disposeDiagnostic(). 463 */ 464CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, 465 unsigned Index); 466 467/** 468 * \brief Destroy a diagnostic. 469 */ 470CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 471 472/** 473 * \brief Options to control the display of diagnostics. 474 * 475 * The values in this enum are meant to be combined to customize the 476 * behavior of \c clang_displayDiagnostic(). 477 */ 478enum CXDiagnosticDisplayOptions { 479 /** 480 * \brief Display the source-location information where the 481 * diagnostic was located. 482 * 483 * When set, diagnostics will be prefixed by the file, line, and 484 * (optionally) column to which the diagnostic refers. For example, 485 * 486 * \code 487 * test.c:28: warning: extra tokens at end of #endif directive 488 * \endcode 489 * 490 * This option corresponds to the clang flag \c -fshow-source-location. 491 */ 492 CXDiagnostic_DisplaySourceLocation = 0x01, 493 494 /** 495 * \brief If displaying the source-location information of the 496 * diagnostic, also include the column number. 497 * 498 * This option corresponds to the clang flag \c -fshow-column. 499 */ 500 CXDiagnostic_DisplayColumn = 0x02, 501 502 /** 503 * \brief If displaying the source-location information of the 504 * diagnostic, also include information about source ranges in a 505 * machine-parsable format. 506 * 507 * This option corresponds to the clang flag 508 * \c -fdiagnostics-print-source-range-info. 509 */ 510 CXDiagnostic_DisplaySourceRanges = 0x04, 511 512 /** 513 * \brief Display the option name associated with this diagnostic, if any. 514 * 515 * The option name displayed (e.g., -Wconversion) will be placed in brackets 516 * after the diagnostic text. This option corresponds to the clang flag 517 * \c -fdiagnostics-show-option. 518 */ 519 CXDiagnostic_DisplayOption = 0x08, 520 521 /** 522 * \brief Display the category number associated with this diagnostic, if any. 523 * 524 * The category number is displayed within brackets after the diagnostic text. 525 * This option corresponds to the clang flag 526 * \c -fdiagnostics-show-category=id. 527 */ 528 CXDiagnostic_DisplayCategoryId = 0x10, 529 530 /** 531 * \brief Display the category name associated with this diagnostic, if any. 532 * 533 * The category name is displayed within brackets after the diagnostic text. 534 * This option corresponds to the clang flag 535 * \c -fdiagnostics-show-category=name. 536 */ 537 CXDiagnostic_DisplayCategoryName = 0x20 538}; 539 540/** 541 * \brief Format the given diagnostic in a manner that is suitable for display. 542 * 543 * This routine will format the given diagnostic to a string, rendering 544 * the diagnostic according to the various options given. The 545 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 546 * options that most closely mimics the behavior of the clang compiler. 547 * 548 * \param Diagnostic The diagnostic to print. 549 * 550 * \param Options A set of options that control the diagnostic display, 551 * created by combining \c CXDiagnosticDisplayOptions values. 552 * 553 * \returns A new string containing for formatted diagnostic. 554 */ 555CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, 556 unsigned Options); 557 558/** 559 * \brief Retrieve the set of display options most similar to the 560 * default behavior of the clang compiler. 561 * 562 * \returns A set of display options suitable for use with \c 563 * clang_displayDiagnostic(). 564 */ 565CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); 566 567/** 568 * \brief Determine the severity of the given diagnostic. 569 */ 570CINDEX_LINKAGE enum CXDiagnosticSeverity 571clang_getDiagnosticSeverity(CXDiagnostic); 572 573/** 574 * \brief Retrieve the source location of the given diagnostic. 575 * 576 * This location is where Clang would print the caret ('^') when 577 * displaying the diagnostic on the command line. 578 */ 579CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 580 581/** 582 * \brief Retrieve the text of the given diagnostic. 583 */ 584CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); 585 586/** 587 * \brief Retrieve the name of the command-line option that enabled this 588 * diagnostic. 589 * 590 * \param Diag The diagnostic to be queried. 591 * 592 * \param Disable If non-NULL, will be set to the option that disables this 593 * diagnostic (if any). 594 * 595 * \returns A string that contains the command-line option used to enable this 596 * warning, such as "-Wconversion" or "-pedantic". 597 */ 598CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag, 599 CXString *Disable); 600 601/** 602 * \brief Retrieve the category number for this diagnostic. 603 * 604 * Diagnostics can be categorized into groups along with other, related 605 * diagnostics (e.g., diagnostics under the same warning flag). This routine 606 * retrieves the category number for the given diagnostic. 607 * 608 * \returns The number of the category that contains this diagnostic, or zero 609 * if this diagnostic is uncategorized. 610 */ 611CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic); 612 613/** 614 * \brief Retrieve the name of a particular diagnostic category. 615 * 616 * \param Category A diagnostic category number, as returned by 617 * \c clang_getDiagnosticCategory(). 618 * 619 * \returns The name of the given diagnostic category. 620 */ 621CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category); 622 623/** 624 * \brief Determine the number of source ranges associated with the given 625 * diagnostic. 626 */ 627CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); 628 629/** 630 * \brief Retrieve a source range associated with the diagnostic. 631 * 632 * A diagnostic's source ranges highlight important elements in the source 633 * code. On the command line, Clang displays source ranges by 634 * underlining them with '~' characters. 635 * 636 * \param Diagnostic the diagnostic whose range is being extracted. 637 * 638 * \param Range the zero-based index specifying which range to 639 * 640 * \returns the requested source range. 641 */ 642CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, 643 unsigned Range); 644 645/** 646 * \brief Determine the number of fix-it hints associated with the 647 * given diagnostic. 648 */ 649CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 650 651/** 652 * \brief Retrieve the replacement information for a given fix-it. 653 * 654 * Fix-its are described in terms of a source range whose contents 655 * should be replaced by a string. This approach generalizes over 656 * three kinds of operations: removal of source code (the range covers 657 * the code to be removed and the replacement string is empty), 658 * replacement of source code (the range covers the code to be 659 * replaced and the replacement string provides the new code), and 660 * insertion (both the start and end of the range point at the 661 * insertion location, and the replacement string provides the text to 662 * insert). 663 * 664 * \param Diagnostic The diagnostic whose fix-its are being queried. 665 * 666 * \param FixIt The zero-based index of the fix-it. 667 * 668 * \param ReplacementRange The source range whose contents will be 669 * replaced with the returned replacement string. Note that source 670 * ranges are half-open ranges [a, b), so the source code should be 671 * replaced from a and up to (but not including) b. 672 * 673 * \returns A string containing text that should be replace the source 674 * code indicated by the \c ReplacementRange. 675 */ 676CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, 677 unsigned FixIt, 678 CXSourceRange *ReplacementRange); 679 680/** 681 * @} 682 */ 683 684/** 685 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 686 * 687 * The routines in this group provide the ability to create and destroy 688 * translation units from files, either by parsing the contents of the files or 689 * by reading in a serialized representation of a translation unit. 690 * 691 * @{ 692 */ 693 694/** 695 * \brief Get the original translation unit source file name. 696 */ 697CINDEX_LINKAGE CXString 698clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 699 700/** 701 * \brief Return the CXTranslationUnit for a given source file and the provided 702 * command line arguments one would pass to the compiler. 703 * 704 * Note: The 'source_filename' argument is optional. If the caller provides a 705 * NULL pointer, the name of the source file is expected to reside in the 706 * specified command line arguments. 707 * 708 * Note: When encountered in 'clang_command_line_args', the following options 709 * are ignored: 710 * 711 * '-c' 712 * '-emit-ast' 713 * '-fsyntax-only' 714 * '-o <output file>' (both '-o' and '<output file>' are ignored) 715 * 716 * \param CIdx The index object with which the translation unit will be 717 * associated. 718 * 719 * \param source_filename - The name of the source file to load, or NULL if the 720 * source file is included in \p clang_command_line_args. 721 * 722 * \param num_clang_command_line_args The number of command-line arguments in 723 * \p clang_command_line_args. 724 * 725 * \param clang_command_line_args The command-line arguments that would be 726 * passed to the \c clang executable if it were being invoked out-of-process. 727 * These command-line options will be parsed and will affect how the translation 728 * unit is parsed. Note that the following options are ignored: '-c', 729 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 730 * 731 * \param num_unsaved_files the number of unsaved file entries in \p 732 * unsaved_files. 733 * 734 * \param unsaved_files the files that have not yet been saved to disk 735 * but may be required for code completion, including the contents of 736 * those files. The contents and name of these files (as specified by 737 * CXUnsavedFile) are copied when necessary, so the client only needs to 738 * guarantee their validity until the call to this function returns. 739 */ 740CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 741 CXIndex CIdx, 742 const char *source_filename, 743 int num_clang_command_line_args, 744 const char * const *clang_command_line_args, 745 unsigned num_unsaved_files, 746 struct CXUnsavedFile *unsaved_files); 747 748/** 749 * \brief Create a translation unit from an AST file (-emit-ast). 750 */ 751CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, 752 const char *ast_filename); 753 754/** 755 * \brief Flags that control the creation of translation units. 756 * 757 * The enumerators in this enumeration type are meant to be bitwise 758 * ORed together to specify which options should be used when 759 * constructing the translation unit. 760 */ 761enum CXTranslationUnit_Flags { 762 /** 763 * \brief Used to indicate that no special translation-unit options are 764 * needed. 765 */ 766 CXTranslationUnit_None = 0x0, 767 768 /** 769 * \brief Used to indicate that the parser should construct a "detailed" 770 * preprocessing record, including all macro definitions and instantiations. 771 * 772 * Constructing a detailed preprocessing record requires more memory 773 * and time to parse, since the information contained in the record 774 * is usually not retained. However, it can be useful for 775 * applications that require more detailed information about the 776 * behavior of the preprocessor. 777 */ 778 CXTranslationUnit_DetailedPreprocessingRecord = 0x01, 779 780 /** 781 * \brief Used to indicate that the translation unit is incomplete. 782 * 783 * When a translation unit is considered "incomplete", semantic 784 * analysis that is typically performed at the end of the 785 * translation unit will be suppressed. For example, this suppresses 786 * the completion of tentative declarations in C and of 787 * instantiation of implicitly-instantiation function templates in 788 * C++. This option is typically used when parsing a header with the 789 * intent of producing a precompiled header. 790 */ 791 CXTranslationUnit_Incomplete = 0x02, 792 793 /** 794 * \brief Used to indicate that the translation unit should be built with an 795 * implicit precompiled header for the preamble. 796 * 797 * An implicit precompiled header is used as an optimization when a 798 * particular translation unit is likely to be reparsed many times 799 * when the sources aren't changing that often. In this case, an 800 * implicit precompiled header will be built containing all of the 801 * initial includes at the top of the main file (what we refer to as 802 * the "preamble" of the file). In subsequent parses, if the 803 * preamble or the files in it have not changed, \c 804 * clang_reparseTranslationUnit() will re-use the implicit 805 * precompiled header to improve parsing performance. 806 */ 807 CXTranslationUnit_PrecompiledPreamble = 0x04, 808 809 /** 810 * \brief Used to indicate that the translation unit should cache some 811 * code-completion results with each reparse of the source file. 812 * 813 * Caching of code-completion results is a performance optimization that 814 * introduces some overhead to reparsing but improves the performance of 815 * code-completion operations. 816 */ 817 CXTranslationUnit_CacheCompletionResults = 0x08, 818 /** 819 * \brief Enable precompiled preambles in C++. 820 * 821 * Note: this is a *temporary* option that is available only while 822 * we are testing C++ precompiled preamble support. 823 */ 824 CXTranslationUnit_CXXPrecompiledPreamble = 0x10, 825 826 /** 827 * \brief Enabled chained precompiled preambles in C++. 828 * 829 * Note: this is a *temporary* option that is available only while 830 * we are testing C++ precompiled preamble support. 831 */ 832 CXTranslationUnit_CXXChainedPCH = 0x20, 833 834 /** 835 * \brief Used to indicate that the "detailed" preprocessing record, 836 * if requested, should also contain nested macro instantiations. 837 * 838 * Nested macro instantiations (i.e., macro instantiations that occur 839 * inside another macro instantiation) can, in some code bases, require 840 * a large amount of storage to due preprocessor metaprogramming. Moreover, 841 * its fairly rare that this information is useful for libclang clients. 842 */ 843 CXTranslationUnit_NestedMacroInstantiations = 0x40 844}; 845 846/** 847 * \brief Returns the set of flags that is suitable for parsing a translation 848 * unit that is being edited. 849 * 850 * The set of flags returned provide options for \c clang_parseTranslationUnit() 851 * to indicate that the translation unit is likely to be reparsed many times, 852 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly 853 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag 854 * set contains an unspecified set of optimizations (e.g., the precompiled 855 * preamble) geared toward improving the performance of these routines. The 856 * set of optimizations enabled may change from one version to the next. 857 */ 858CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void); 859 860/** 861 * \brief Parse the given source file and the translation unit corresponding 862 * to that file. 863 * 864 * This routine is the main entry point for the Clang C API, providing the 865 * ability to parse a source file into a translation unit that can then be 866 * queried by other functions in the API. This routine accepts a set of 867 * command-line arguments so that the compilation can be configured in the same 868 * way that the compiler is configured on the command line. 869 * 870 * \param CIdx The index object with which the translation unit will be 871 * associated. 872 * 873 * \param source_filename The name of the source file to load, or NULL if the 874 * source file is included in \p command_line_args. 875 * 876 * \param command_line_args The command-line arguments that would be 877 * passed to the \c clang executable if it were being invoked out-of-process. 878 * These command-line options will be parsed and will affect how the translation 879 * unit is parsed. Note that the following options are ignored: '-c', 880 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 881 * 882 * \param num_command_line_args The number of command-line arguments in 883 * \p command_line_args. 884 * 885 * \param unsaved_files the files that have not yet been saved to disk 886 * but may be required for parsing, including the contents of 887 * those files. The contents and name of these files (as specified by 888 * CXUnsavedFile) are copied when necessary, so the client only needs to 889 * guarantee their validity until the call to this function returns. 890 * 891 * \param num_unsaved_files the number of unsaved file entries in \p 892 * unsaved_files. 893 * 894 * \param options A bitmask of options that affects how the translation unit 895 * is managed but not its compilation. This should be a bitwise OR of the 896 * CXTranslationUnit_XXX flags. 897 * 898 * \returns A new translation unit describing the parsed code and containing 899 * any diagnostics produced by the compiler. If there is a failure from which 900 * the compiler cannot recover, returns NULL. 901 */ 902CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, 903 const char *source_filename, 904 const char * const *command_line_args, 905 int num_command_line_args, 906 struct CXUnsavedFile *unsaved_files, 907 unsigned num_unsaved_files, 908 unsigned options); 909 910/** 911 * \brief Flags that control how translation units are saved. 912 * 913 * The enumerators in this enumeration type are meant to be bitwise 914 * ORed together to specify which options should be used when 915 * saving the translation unit. 916 */ 917enum CXSaveTranslationUnit_Flags { 918 /** 919 * \brief Used to indicate that no special saving options are needed. 920 */ 921 CXSaveTranslationUnit_None = 0x0 922}; 923 924/** 925 * \brief Returns the set of flags that is suitable for saving a translation 926 * unit. 927 * 928 * The set of flags returned provide options for 929 * \c clang_saveTranslationUnit() by default. The returned flag 930 * set contains an unspecified set of options that save translation units with 931 * the most commonly-requested data. 932 */ 933CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU); 934 935/** 936 * \brief Saves a translation unit into a serialized representation of 937 * that translation unit on disk. 938 * 939 * Any translation unit that was parsed without error can be saved 940 * into a file. The translation unit can then be deserialized into a 941 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or, 942 * if it is an incomplete translation unit that corresponds to a 943 * header, used as a precompiled header when parsing other translation 944 * units. 945 * 946 * \param TU The translation unit to save. 947 * 948 * \param FileName The file to which the translation unit will be saved. 949 * 950 * \param options A bitmask of options that affects how the translation unit 951 * is saved. This should be a bitwise OR of the 952 * CXSaveTranslationUnit_XXX flags. 953 * 954 * \returns Zero if the translation unit was saved successfully, a 955 * non-zero value otherwise. 956 */ 957CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU, 958 const char *FileName, 959 unsigned options); 960 961/** 962 * \brief Destroy the specified CXTranslationUnit object. 963 */ 964CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 965 966/** 967 * \brief Flags that control the reparsing of translation units. 968 * 969 * The enumerators in this enumeration type are meant to be bitwise 970 * ORed together to specify which options should be used when 971 * reparsing the translation unit. 972 */ 973enum CXReparse_Flags { 974 /** 975 * \brief Used to indicate that no special reparsing options are needed. 976 */ 977 CXReparse_None = 0x0 978}; 979 980/** 981 * \brief Returns the set of flags that is suitable for reparsing a translation 982 * unit. 983 * 984 * The set of flags returned provide options for 985 * \c clang_reparseTranslationUnit() by default. The returned flag 986 * set contains an unspecified set of optimizations geared toward common uses 987 * of reparsing. The set of optimizations enabled may change from one version 988 * to the next. 989 */ 990CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU); 991 992/** 993 * \brief Reparse the source files that produced this translation unit. 994 * 995 * This routine can be used to re-parse the source files that originally 996 * created the given translation unit, for example because those source files 997 * have changed (either on disk or as passed via \p unsaved_files). The 998 * source code will be reparsed with the same command-line options as it 999 * was originally parsed. 1000 * 1001 * Reparsing a translation unit invalidates all cursors and source locations 1002 * that refer into that translation unit. This makes reparsing a translation 1003 * unit semantically equivalent to destroying the translation unit and then 1004 * creating a new translation unit with the same command-line arguments. 1005 * However, it may be more efficient to reparse a translation 1006 * unit using this routine. 1007 * 1008 * \param TU The translation unit whose contents will be re-parsed. The 1009 * translation unit must originally have been built with 1010 * \c clang_createTranslationUnitFromSourceFile(). 1011 * 1012 * \param num_unsaved_files The number of unsaved file entries in \p 1013 * unsaved_files. 1014 * 1015 * \param unsaved_files The files that have not yet been saved to disk 1016 * but may be required for parsing, including the contents of 1017 * those files. The contents and name of these files (as specified by 1018 * CXUnsavedFile) are copied when necessary, so the client only needs to 1019 * guarantee their validity until the call to this function returns. 1020 * 1021 * \param options A bitset of options composed of the flags in CXReparse_Flags. 1022 * The function \c clang_defaultReparseOptions() produces a default set of 1023 * options recommended for most uses, based on the translation unit. 1024 * 1025 * \returns 0 if the sources could be reparsed. A non-zero value will be 1026 * returned if reparsing was impossible, such that the translation unit is 1027 * invalid. In such cases, the only valid call for \p TU is 1028 * \c clang_disposeTranslationUnit(TU). 1029 */ 1030CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, 1031 unsigned num_unsaved_files, 1032 struct CXUnsavedFile *unsaved_files, 1033 unsigned options); 1034 1035/** 1036 * \brief Categorizes how memory is being used by a translation unit. 1037 */ 1038enum CXTUResourceUsageKind { 1039 CXTUResourceUsage_AST = 1, 1040 CXTUResourceUsage_Identifiers = 2, 1041 CXTUResourceUsage_Selectors = 3, 1042 CXTUResourceUsage_GlobalCompletionResults = 4, 1043 CXTUResourceUsage_SourceManagerContentCache = 5, 1044 CXTUResourceUsage_AST_SideTables = 6, 1045 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7, 1046 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8, 1047 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9, 1048 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10, 1049 CXTUResourceUsage_Preprocessor = 11, 1050 CXTUResourceUsage_PreprocessingRecord = 12, 1051 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST, 1052 CXTUResourceUsage_MEMORY_IN_BYTES_END = 1053 CXTUResourceUsage_PreprocessingRecord, 1054 1055 CXTUResourceUsage_First = CXTUResourceUsage_AST, 1056 CXTUResourceUsage_Last = CXTUResourceUsage_PreprocessingRecord 1057}; 1058 1059/** 1060 * \brief Returns the human-readable null-terminated C string that represents 1061 * the name of the memory category. This string should never be freed. 1062 */ 1063CINDEX_LINKAGE 1064const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind); 1065 1066typedef struct CXTUResourceUsageEntry { 1067 /* \brief The memory usage category. */ 1068 enum CXTUResourceUsageKind kind; 1069 /* \brief Amount of resources used. 1070 The units will depend on the resource kind. */ 1071 unsigned long amount; 1072} CXTUResourceUsageEntry; 1073 1074/** 1075 * \brief The memory usage of a CXTranslationUnit, broken into categories. 1076 */ 1077typedef struct CXTUResourceUsage { 1078 /* \brief Private data member, used for queries. */ 1079 void *data; 1080 1081 /* \brief The number of entries in the 'entries' array. */ 1082 unsigned numEntries; 1083 1084 /* \brief An array of key-value pairs, representing the breakdown of memory 1085 usage. */ 1086 CXTUResourceUsageEntry *entries; 1087 1088} CXTUResourceUsage; 1089 1090/** 1091 * \brief Return the memory usage of a translation unit. This object 1092 * should be released with clang_disposeCXTUResourceUsage(). 1093 */ 1094CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU); 1095 1096CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage); 1097 1098/** 1099 * @} 1100 */ 1101 1102/** 1103 * \brief Describes the kind of entity that a cursor refers to. 1104 */ 1105enum CXCursorKind { 1106 /* Declarations */ 1107 /** 1108 * \brief A declaration whose specific kind is not exposed via this 1109 * interface. 1110 * 1111 * Unexposed declarations have the same operations as any other kind 1112 * of declaration; one can extract their location information, 1113 * spelling, find their definitions, etc. However, the specific kind 1114 * of the declaration is not reported. 1115 */ 1116 CXCursor_UnexposedDecl = 1, 1117 /** \brief A C or C++ struct. */ 1118 CXCursor_StructDecl = 2, 1119 /** \brief A C or C++ union. */ 1120 CXCursor_UnionDecl = 3, 1121 /** \brief A C++ class. */ 1122 CXCursor_ClassDecl = 4, 1123 /** \brief An enumeration. */ 1124 CXCursor_EnumDecl = 5, 1125 /** 1126 * \brief A field (in C) or non-static data member (in C++) in a 1127 * struct, union, or C++ class. 1128 */ 1129 CXCursor_FieldDecl = 6, 1130 /** \brief An enumerator constant. */ 1131 CXCursor_EnumConstantDecl = 7, 1132 /** \brief A function. */ 1133 CXCursor_FunctionDecl = 8, 1134 /** \brief A variable. */ 1135 CXCursor_VarDecl = 9, 1136 /** \brief A function or method parameter. */ 1137 CXCursor_ParmDecl = 10, 1138 /** \brief An Objective-C @interface. */ 1139 CXCursor_ObjCInterfaceDecl = 11, 1140 /** \brief An Objective-C @interface for a category. */ 1141 CXCursor_ObjCCategoryDecl = 12, 1142 /** \brief An Objective-C @protocol declaration. */ 1143 CXCursor_ObjCProtocolDecl = 13, 1144 /** \brief An Objective-C @property declaration. */ 1145 CXCursor_ObjCPropertyDecl = 14, 1146 /** \brief An Objective-C instance variable. */ 1147 CXCursor_ObjCIvarDecl = 15, 1148 /** \brief An Objective-C instance method. */ 1149 CXCursor_ObjCInstanceMethodDecl = 16, 1150 /** \brief An Objective-C class method. */ 1151 CXCursor_ObjCClassMethodDecl = 17, 1152 /** \brief An Objective-C @implementation. */ 1153 CXCursor_ObjCImplementationDecl = 18, 1154 /** \brief An Objective-C @implementation for a category. */ 1155 CXCursor_ObjCCategoryImplDecl = 19, 1156 /** \brief A typedef */ 1157 CXCursor_TypedefDecl = 20, 1158 /** \brief A C++ class method. */ 1159 CXCursor_CXXMethod = 21, 1160 /** \brief A C++ namespace. */ 1161 CXCursor_Namespace = 22, 1162 /** \brief A linkage specification, e.g. 'extern "C"'. */ 1163 CXCursor_LinkageSpec = 23, 1164 /** \brief A C++ constructor. */ 1165 CXCursor_Constructor = 24, 1166 /** \brief A C++ destructor. */ 1167 CXCursor_Destructor = 25, 1168 /** \brief A C++ conversion function. */ 1169 CXCursor_ConversionFunction = 26, 1170 /** \brief A C++ template type parameter. */ 1171 CXCursor_TemplateTypeParameter = 27, 1172 /** \brief A C++ non-type template parameter. */ 1173 CXCursor_NonTypeTemplateParameter = 28, 1174 /** \brief A C++ template template parameter. */ 1175 CXCursor_TemplateTemplateParameter = 29, 1176 /** \brief A C++ function template. */ 1177 CXCursor_FunctionTemplate = 30, 1178 /** \brief A C++ class template. */ 1179 CXCursor_ClassTemplate = 31, 1180 /** \brief A C++ class template partial specialization. */ 1181 CXCursor_ClassTemplatePartialSpecialization = 32, 1182 /** \brief A C++ namespace alias declaration. */ 1183 CXCursor_NamespaceAlias = 33, 1184 /** \brief A C++ using directive. */ 1185 CXCursor_UsingDirective = 34, 1186 /** \brief A C++ using declaration. */ 1187 CXCursor_UsingDeclaration = 35, 1188 /** \brief A C++ alias declaration */ 1189 CXCursor_TypeAliasDecl = 36, 1190 CXCursor_FirstDecl = CXCursor_UnexposedDecl, 1191 CXCursor_LastDecl = CXCursor_TypeAliasDecl, 1192 1193 /* References */ 1194 CXCursor_FirstRef = 40, /* Decl references */ 1195 CXCursor_ObjCSuperClassRef = 40, 1196 CXCursor_ObjCProtocolRef = 41, 1197 CXCursor_ObjCClassRef = 42, 1198 /** 1199 * \brief A reference to a type declaration. 1200 * 1201 * A type reference occurs anywhere where a type is named but not 1202 * declared. For example, given: 1203 * 1204 * \code 1205 * typedef unsigned size_type; 1206 * size_type size; 1207 * \endcode 1208 * 1209 * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 1210 * while the type of the variable "size" is referenced. The cursor 1211 * referenced by the type of size is the typedef for size_type. 1212 */ 1213 CXCursor_TypeRef = 43, 1214 CXCursor_CXXBaseSpecifier = 44, 1215 /** 1216 * \brief A reference to a class template, function template, template 1217 * template parameter, or class template partial specialization. 1218 */ 1219 CXCursor_TemplateRef = 45, 1220 /** 1221 * \brief A reference to a namespace or namespace alias. 1222 */ 1223 CXCursor_NamespaceRef = 46, 1224 /** 1225 * \brief A reference to a member of a struct, union, or class that occurs in 1226 * some non-expression context, e.g., a designated initializer. 1227 */ 1228 CXCursor_MemberRef = 47, 1229 /** 1230 * \brief A reference to a labeled statement. 1231 * 1232 * This cursor kind is used to describe the jump to "start_over" in the 1233 * goto statement in the following example: 1234 * 1235 * \code 1236 * start_over: 1237 * ++counter; 1238 * 1239 * goto start_over; 1240 * \endcode 1241 * 1242 * A label reference cursor refers to a label statement. 1243 */ 1244 CXCursor_LabelRef = 48, 1245 1246 /** 1247 * \brief A reference to a set of overloaded functions or function templates 1248 * that has not yet been resolved to a specific function or function template. 1249 * 1250 * An overloaded declaration reference cursor occurs in C++ templates where 1251 * a dependent name refers to a function. For example: 1252 * 1253 * \code 1254 * template<typename T> void swap(T&, T&); 1255 * 1256 * struct X { ... }; 1257 * void swap(X&, X&); 1258 * 1259 * template<typename T> 1260 * void reverse(T* first, T* last) { 1261 * while (first < last - 1) { 1262 * swap(*first, *--last); 1263 * ++first; 1264 * } 1265 * } 1266 * 1267 * struct Y { }; 1268 * void swap(Y&, Y&); 1269 * \endcode 1270 * 1271 * Here, the identifier "swap" is associated with an overloaded declaration 1272 * reference. In the template definition, "swap" refers to either of the two 1273 * "swap" functions declared above, so both results will be available. At 1274 * instantiation time, "swap" may also refer to other functions found via 1275 * argument-dependent lookup (e.g., the "swap" function at the end of the 1276 * example). 1277 * 1278 * The functions \c clang_getNumOverloadedDecls() and 1279 * \c clang_getOverloadedDecl() can be used to retrieve the definitions 1280 * referenced by this cursor. 1281 */ 1282 CXCursor_OverloadedDeclRef = 49, 1283 1284 CXCursor_LastRef = CXCursor_OverloadedDeclRef, 1285 1286 /* Error conditions */ 1287 CXCursor_FirstInvalid = 70, 1288 CXCursor_InvalidFile = 70, 1289 CXCursor_NoDeclFound = 71, 1290 CXCursor_NotImplemented = 72, 1291 CXCursor_InvalidCode = 73, 1292 CXCursor_LastInvalid = CXCursor_InvalidCode, 1293 1294 /* Expressions */ 1295 CXCursor_FirstExpr = 100, 1296 1297 /** 1298 * \brief An expression whose specific kind is not exposed via this 1299 * interface. 1300 * 1301 * Unexposed expressions have the same operations as any other kind 1302 * of expression; one can extract their location information, 1303 * spelling, children, etc. However, the specific kind of the 1304 * expression is not reported. 1305 */ 1306 CXCursor_UnexposedExpr = 100, 1307 1308 /** 1309 * \brief An expression that refers to some value declaration, such 1310 * as a function, varible, or enumerator. 1311 */ 1312 CXCursor_DeclRefExpr = 101, 1313 1314 /** 1315 * \brief An expression that refers to a member of a struct, union, 1316 * class, Objective-C class, etc. 1317 */ 1318 CXCursor_MemberRefExpr = 102, 1319 1320 /** \brief An expression that calls a function. */ 1321 CXCursor_CallExpr = 103, 1322 1323 /** \brief An expression that sends a message to an Objective-C 1324 object or class. */ 1325 CXCursor_ObjCMessageExpr = 104, 1326 1327 /** \brief An expression that represents a block literal. */ 1328 CXCursor_BlockExpr = 105, 1329 1330 CXCursor_LastExpr = 105, 1331 1332 /* Statements */ 1333 CXCursor_FirstStmt = 200, 1334 /** 1335 * \brief A statement whose specific kind is not exposed via this 1336 * interface. 1337 * 1338 * Unexposed statements have the same operations as any other kind of 1339 * statement; one can extract their location information, spelling, 1340 * children, etc. However, the specific kind of the statement is not 1341 * reported. 1342 */ 1343 CXCursor_UnexposedStmt = 200, 1344 1345 /** \brief A labelled statement in a function. 1346 * 1347 * This cursor kind is used to describe the "start_over:" label statement in 1348 * the following example: 1349 * 1350 * \code 1351 * start_over: 1352 * ++counter; 1353 * \endcode 1354 * 1355 */ 1356 CXCursor_LabelStmt = 201, 1357 1358 CXCursor_LastStmt = CXCursor_LabelStmt, 1359 1360 /** 1361 * \brief Cursor that represents the translation unit itself. 1362 * 1363 * The translation unit cursor exists primarily to act as the root 1364 * cursor for traversing the contents of a translation unit. 1365 */ 1366 CXCursor_TranslationUnit = 300, 1367 1368 /* Attributes */ 1369 CXCursor_FirstAttr = 400, 1370 /** 1371 * \brief An attribute whose specific kind is not exposed via this 1372 * interface. 1373 */ 1374 CXCursor_UnexposedAttr = 400, 1375 1376 CXCursor_IBActionAttr = 401, 1377 CXCursor_IBOutletAttr = 402, 1378 CXCursor_IBOutletCollectionAttr = 403, 1379 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr, 1380 1381 /* Preprocessing */ 1382 CXCursor_PreprocessingDirective = 500, 1383 CXCursor_MacroDefinition = 501, 1384 CXCursor_MacroInstantiation = 502, 1385 CXCursor_InclusionDirective = 503, 1386 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, 1387 CXCursor_LastPreprocessing = CXCursor_InclusionDirective 1388}; 1389 1390/** 1391 * \brief A cursor representing some element in the abstract syntax tree for 1392 * a translation unit. 1393 * 1394 * The cursor abstraction unifies the different kinds of entities in a 1395 * program--declaration, statements, expressions, references to declarations, 1396 * etc.--under a single "cursor" abstraction with a common set of operations. 1397 * Common operation for a cursor include: getting the physical location in 1398 * a source file where the cursor points, getting the name associated with a 1399 * cursor, and retrieving cursors for any child nodes of a particular cursor. 1400 * 1401 * Cursors can be produced in two specific ways. 1402 * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 1403 * from which one can use clang_visitChildren() to explore the rest of the 1404 * translation unit. clang_getCursor() maps from a physical source location 1405 * to the entity that resides at that location, allowing one to map from the 1406 * source code into the AST. 1407 */ 1408typedef struct { 1409 enum CXCursorKind kind; 1410 void *data[3]; 1411} CXCursor; 1412 1413/** 1414 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 1415 * 1416 * @{ 1417 */ 1418 1419/** 1420 * \brief Retrieve the NULL cursor, which represents no entity. 1421 */ 1422CINDEX_LINKAGE CXCursor clang_getNullCursor(void); 1423 1424/** 1425 * \brief Retrieve the cursor that represents the given translation unit. 1426 * 1427 * The translation unit cursor can be used to start traversing the 1428 * various declarations within the given translation unit. 1429 */ 1430CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 1431 1432/** 1433 * \brief Determine whether two cursors are equivalent. 1434 */ 1435CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 1436 1437/** 1438 * \brief Compute a hash value for the given cursor. 1439 */ 1440CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor); 1441 1442/** 1443 * \brief Retrieve the kind of the given cursor. 1444 */ 1445CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 1446 1447/** 1448 * \brief Determine whether the given cursor kind represents a declaration. 1449 */ 1450CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 1451 1452/** 1453 * \brief Determine whether the given cursor kind represents a simple 1454 * reference. 1455 * 1456 * Note that other kinds of cursors (such as expressions) can also refer to 1457 * other cursors. Use clang_getCursorReferenced() to determine whether a 1458 * particular cursor refers to another entity. 1459 */ 1460CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 1461 1462/** 1463 * \brief Determine whether the given cursor kind represents an expression. 1464 */ 1465CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 1466 1467/** 1468 * \brief Determine whether the given cursor kind represents a statement. 1469 */ 1470CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 1471 1472/** 1473 * \brief Determine whether the given cursor kind represents an invalid 1474 * cursor. 1475 */ 1476CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 1477 1478/** 1479 * \brief Determine whether the given cursor kind represents a translation 1480 * unit. 1481 */ 1482CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 1483 1484/*** 1485 * \brief Determine whether the given cursor represents a preprocessing 1486 * element, such as a preprocessor directive or macro instantiation. 1487 */ 1488CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); 1489 1490/*** 1491 * \brief Determine whether the given cursor represents a currently 1492 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 1493 */ 1494CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); 1495 1496/** 1497 * \brief Describe the linkage of the entity referred to by a cursor. 1498 */ 1499enum CXLinkageKind { 1500 /** \brief This value indicates that no linkage information is available 1501 * for a provided CXCursor. */ 1502 CXLinkage_Invalid, 1503 /** 1504 * \brief This is the linkage for variables, parameters, and so on that 1505 * have automatic storage. This covers normal (non-extern) local variables. 1506 */ 1507 CXLinkage_NoLinkage, 1508 /** \brief This is the linkage for static variables and static functions. */ 1509 CXLinkage_Internal, 1510 /** \brief This is the linkage for entities with external linkage that live 1511 * in C++ anonymous namespaces.*/ 1512 CXLinkage_UniqueExternal, 1513 /** \brief This is the linkage for entities with true, external linkage. */ 1514 CXLinkage_External 1515}; 1516 1517/** 1518 * \brief Determine the linkage of the entity referred to by a given cursor. 1519 */ 1520CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 1521 1522/** 1523 * \brief Determine the availability of the entity that this cursor refers to. 1524 * 1525 * \param cursor The cursor to query. 1526 * 1527 * \returns The availability of the cursor. 1528 */ 1529CINDEX_LINKAGE enum CXAvailabilityKind 1530clang_getCursorAvailability(CXCursor cursor); 1531 1532/** 1533 * \brief Describe the "language" of the entity referred to by a cursor. 1534 */ 1535CINDEX_LINKAGE enum CXLanguageKind { 1536 CXLanguage_Invalid = 0, 1537 CXLanguage_C, 1538 CXLanguage_ObjC, 1539 CXLanguage_CPlusPlus 1540}; 1541 1542/** 1543 * \brief Determine the "language" of the entity referred to by a given cursor. 1544 */ 1545CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 1546 1547 1548/** 1549 * \brief A fast container representing a set of CXCursors. 1550 */ 1551typedef struct CXCursorSetImpl *CXCursorSet; 1552 1553/** 1554 * \brief Creates an empty CXCursorSet. 1555 */ 1556CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(); 1557 1558/** 1559 * \brief Disposes a CXCursorSet and releases its associated memory. 1560 */ 1561CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset); 1562 1563/** 1564 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor. 1565 * 1566 * \returns non-zero if the set contains the specified cursor. 1567*/ 1568CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset, 1569 CXCursor cursor); 1570 1571/** 1572 * \brief Inserts a CXCursor into a CXCursorSet. 1573 * 1574 * \returns zero if the CXCursor was already in the set, and non-zero otherwise. 1575*/ 1576CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset, 1577 CXCursor cursor); 1578 1579/** 1580 * \brief Determine the semantic parent of the given cursor. 1581 * 1582 * The semantic parent of a cursor is the cursor that semantically contains 1583 * the given \p cursor. For many declarations, the lexical and semantic parents 1584 * are equivalent (the lexical parent is returned by 1585 * \c clang_getCursorLexicalParent()). They diverge when declarations or 1586 * definitions are provided out-of-line. For example: 1587 * 1588 * \code 1589 * class C { 1590 * void f(); 1591 * }; 1592 * 1593 * void C::f() { } 1594 * \endcode 1595 * 1596 * In the out-of-line definition of \c C::f, the semantic parent is the 1597 * the class \c C, of which this function is a member. The lexical parent is 1598 * the place where the declaration actually occurs in the source code; in this 1599 * case, the definition occurs in the translation unit. In general, the 1600 * lexical parent for a given entity can change without affecting the semantics 1601 * of the program, and the lexical parent of different declarations of the 1602 * same entity may be different. Changing the semantic parent of a declaration, 1603 * on the other hand, can have a major impact on semantics, and redeclarations 1604 * of a particular entity should all have the same semantic context. 1605 * 1606 * In the example above, both declarations of \c C::f have \c C as their 1607 * semantic context, while the lexical context of the first \c C::f is \c C 1608 * and the lexical context of the second \c C::f is the translation unit. 1609 * 1610 * For global declarations, the semantic parent is the translation unit. 1611 */ 1612CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor); 1613 1614/** 1615 * \brief Determine the lexical parent of the given cursor. 1616 * 1617 * The lexical parent of a cursor is the cursor in which the given \p cursor 1618 * was actually written. For many declarations, the lexical and semantic parents 1619 * are equivalent (the semantic parent is returned by 1620 * \c clang_getCursorSemanticParent()). They diverge when declarations or 1621 * definitions are provided out-of-line. For example: 1622 * 1623 * \code 1624 * class C { 1625 * void f(); 1626 * }; 1627 * 1628 * void C::f() { } 1629 * \endcode 1630 * 1631 * In the out-of-line definition of \c C::f, the semantic parent is the 1632 * the class \c C, of which this function is a member. The lexical parent is 1633 * the place where the declaration actually occurs in the source code; in this 1634 * case, the definition occurs in the translation unit. In general, the 1635 * lexical parent for a given entity can change without affecting the semantics 1636 * of the program, and the lexical parent of different declarations of the 1637 * same entity may be different. Changing the semantic parent of a declaration, 1638 * on the other hand, can have a major impact on semantics, and redeclarations 1639 * of a particular entity should all have the same semantic context. 1640 * 1641 * In the example above, both declarations of \c C::f have \c C as their 1642 * semantic context, while the lexical context of the first \c C::f is \c C 1643 * and the lexical context of the second \c C::f is the translation unit. 1644 * 1645 * For declarations written in the global scope, the lexical parent is 1646 * the translation unit. 1647 */ 1648CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor); 1649 1650/** 1651 * \brief Determine the set of methods that are overridden by the given 1652 * method. 1653 * 1654 * In both Objective-C and C++, a method (aka virtual member function, 1655 * in C++) can override a virtual method in a base class. For 1656 * Objective-C, a method is said to override any method in the class's 1657 * interface (if we're coming from an implementation), its protocols, 1658 * or its categories, that has the same selector and is of the same 1659 * kind (class or instance). If no such method exists, the search 1660 * continues to the class's superclass, its protocols, and its 1661 * categories, and so on. 1662 * 1663 * For C++, a virtual member function overrides any virtual member 1664 * function with the same signature that occurs in its base 1665 * classes. With multiple inheritance, a virtual member function can 1666 * override several virtual member functions coming from different 1667 * base classes. 1668 * 1669 * In all cases, this function determines the immediate overridden 1670 * method, rather than all of the overridden methods. For example, if 1671 * a method is originally declared in a class A, then overridden in B 1672 * (which in inherits from A) and also in C (which inherited from B), 1673 * then the only overridden method returned from this function when 1674 * invoked on C's method will be B's method. The client may then 1675 * invoke this function again, given the previously-found overridden 1676 * methods, to map out the complete method-override set. 1677 * 1678 * \param cursor A cursor representing an Objective-C or C++ 1679 * method. This routine will compute the set of methods that this 1680 * method overrides. 1681 * 1682 * \param overridden A pointer whose pointee will be replaced with a 1683 * pointer to an array of cursors, representing the set of overridden 1684 * methods. If there are no overridden methods, the pointee will be 1685 * set to NULL. The pointee must be freed via a call to 1686 * \c clang_disposeOverriddenCursors(). 1687 * 1688 * \param num_overridden A pointer to the number of overridden 1689 * functions, will be set to the number of overridden functions in the 1690 * array pointed to by \p overridden. 1691 */ 1692CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor, 1693 CXCursor **overridden, 1694 unsigned *num_overridden); 1695 1696/** 1697 * \brief Free the set of overridden cursors returned by \c 1698 * clang_getOverriddenCursors(). 1699 */ 1700CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden); 1701 1702/** 1703 * \brief Retrieve the file that is included by the given inclusion directive 1704 * cursor. 1705 */ 1706CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor); 1707 1708/** 1709 * @} 1710 */ 1711 1712/** 1713 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 1714 * 1715 * Cursors represent a location within the Abstract Syntax Tree (AST). These 1716 * routines help map between cursors and the physical locations where the 1717 * described entities occur in the source code. The mapping is provided in 1718 * both directions, so one can map from source code to the AST and back. 1719 * 1720 * @{ 1721 */ 1722 1723/** 1724 * \brief Map a source location to the cursor that describes the entity at that 1725 * location in the source code. 1726 * 1727 * clang_getCursor() maps an arbitrary source location within a translation 1728 * unit down to the most specific cursor that describes the entity at that 1729 * location. For example, given an expression \c x + y, invoking 1730 * clang_getCursor() with a source location pointing to "x" will return the 1731 * cursor for "x"; similarly for "y". If the cursor points anywhere between 1732 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 1733 * will return a cursor referring to the "+" expression. 1734 * 1735 * \returns a cursor representing the entity at the given source location, or 1736 * a NULL cursor if no such entity can be found. 1737 */ 1738CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 1739 1740/** 1741 * \brief Retrieve the physical location of the source constructor referenced 1742 * by the given cursor. 1743 * 1744 * The location of a declaration is typically the location of the name of that 1745 * declaration, where the name of that declaration would occur if it is 1746 * unnamed, or some keyword that introduces that particular declaration. 1747 * The location of a reference is where that reference occurs within the 1748 * source code. 1749 */ 1750CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 1751 1752/** 1753 * \brief Retrieve the physical extent of the source construct referenced by 1754 * the given cursor. 1755 * 1756 * The extent of a cursor starts with the file/line/column pointing at the 1757 * first character within the source construct that the cursor refers to and 1758 * ends with the last character withinin that source construct. For a 1759 * declaration, the extent covers the declaration itself. For a reference, 1760 * the extent covers the location of the reference (e.g., where the referenced 1761 * entity was actually used). 1762 */ 1763CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 1764 1765/** 1766 * @} 1767 */ 1768 1769/** 1770 * \defgroup CINDEX_TYPES Type information for CXCursors 1771 * 1772 * @{ 1773 */ 1774 1775/** 1776 * \brief Describes the kind of type 1777 */ 1778enum CXTypeKind { 1779 /** 1780 * \brief Reprents an invalid type (e.g., where no type is available). 1781 */ 1782 CXType_Invalid = 0, 1783 1784 /** 1785 * \brief A type whose specific kind is not exposed via this 1786 * interface. 1787 */ 1788 CXType_Unexposed = 1, 1789 1790 /* Builtin types */ 1791 CXType_Void = 2, 1792 CXType_Bool = 3, 1793 CXType_Char_U = 4, 1794 CXType_UChar = 5, 1795 CXType_Char16 = 6, 1796 CXType_Char32 = 7, 1797 CXType_UShort = 8, 1798 CXType_UInt = 9, 1799 CXType_ULong = 10, 1800 CXType_ULongLong = 11, 1801 CXType_UInt128 = 12, 1802 CXType_Char_S = 13, 1803 CXType_SChar = 14, 1804 CXType_WChar = 15, 1805 CXType_Short = 16, 1806 CXType_Int = 17, 1807 CXType_Long = 18, 1808 CXType_LongLong = 19, 1809 CXType_Int128 = 20, 1810 CXType_Float = 21, 1811 CXType_Double = 22, 1812 CXType_LongDouble = 23, 1813 CXType_NullPtr = 24, 1814 CXType_Overload = 25, 1815 CXType_Dependent = 26, 1816 CXType_ObjCId = 27, 1817 CXType_ObjCClass = 28, 1818 CXType_ObjCSel = 29, 1819 CXType_FirstBuiltin = CXType_Void, 1820 CXType_LastBuiltin = CXType_ObjCSel, 1821 1822 CXType_Complex = 100, 1823 CXType_Pointer = 101, 1824 CXType_BlockPointer = 102, 1825 CXType_LValueReference = 103, 1826 CXType_RValueReference = 104, 1827 CXType_Record = 105, 1828 CXType_Enum = 106, 1829 CXType_Typedef = 107, 1830 CXType_ObjCInterface = 108, 1831 CXType_ObjCObjectPointer = 109, 1832 CXType_FunctionNoProto = 110, 1833 CXType_FunctionProto = 111 1834}; 1835 1836/** 1837 * \brief The type of an element in the abstract syntax tree. 1838 * 1839 */ 1840typedef struct { 1841 enum CXTypeKind kind; 1842 void *data[2]; 1843} CXType; 1844 1845/** 1846 * \brief Retrieve the type of a CXCursor (if any). 1847 */ 1848CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); 1849 1850/** 1851 * \determine Determine whether two CXTypes represent the same type. 1852 * 1853 * \returns non-zero if the CXTypes represent the same type and 1854 zero otherwise. 1855 */ 1856CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); 1857 1858/** 1859 * \brief Return the canonical type for a CXType. 1860 * 1861 * Clang's type system explicitly models typedefs and all the ways 1862 * a specific type can be represented. The canonical type is the underlying 1863 * type with all the "sugar" removed. For example, if 'T' is a typedef 1864 * for 'int', the canonical type for 'T' would be 'int'. 1865 */ 1866CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); 1867 1868/** 1869 * \determine Determine whether a CXType has the "const" qualifier set, 1870 * without looking through typedefs that may have added "const" at a different level. 1871 */ 1872CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T); 1873 1874/** 1875 * \determine Determine whether a CXType has the "volatile" qualifier set, 1876 * without looking through typedefs that may have added "volatile" at a different level. 1877 */ 1878CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T); 1879 1880/** 1881 * \determine Determine whether a CXType has the "restrict" qualifier set, 1882 * without looking through typedefs that may have added "restrict" at a different level. 1883 */ 1884CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T); 1885 1886/** 1887 * \brief For pointer types, returns the type of the pointee. 1888 * 1889 */ 1890CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); 1891 1892/** 1893 * \brief Return the cursor for the declaration of the given type. 1894 */ 1895CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); 1896 1897/** 1898 * Returns the Objective-C type encoding for the specified declaration. 1899 */ 1900CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C); 1901 1902/** 1903 * \brief Retrieve the spelling of a given CXTypeKind. 1904 */ 1905CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); 1906 1907/** 1908 * \brief Retrieve the result type associated with a function type. 1909 */ 1910CINDEX_LINKAGE CXType clang_getResultType(CXType T); 1911 1912/** 1913 * \brief Retrieve the result type associated with a given cursor. This only 1914 * returns a valid type of the cursor refers to a function or method. 1915 */ 1916CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); 1917 1918/** 1919 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0 1920 * otherwise. 1921 */ 1922CINDEX_LINKAGE unsigned clang_isPODType(CXType T); 1923 1924/** 1925 * \brief Returns 1 if the base class specified by the cursor with kind 1926 * CX_CXXBaseSpecifier is virtual. 1927 */ 1928CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor); 1929 1930/** 1931 * \brief Represents the C++ access control level to a base class for a 1932 * cursor with kind CX_CXXBaseSpecifier. 1933 */ 1934enum CX_CXXAccessSpecifier { 1935 CX_CXXInvalidAccessSpecifier, 1936 CX_CXXPublic, 1937 CX_CXXProtected, 1938 CX_CXXPrivate 1939}; 1940 1941/** 1942 * \brief Returns the access control level for the C++ base specifier 1943 * represented by a cursor with kind CX_CXXBaseSpecifier. 1944 */ 1945CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor); 1946 1947/** 1948 * \brief Determine the number of overloaded declarations referenced by a 1949 * \c CXCursor_OverloadedDeclRef cursor. 1950 * 1951 * \param cursor The cursor whose overloaded declarations are being queried. 1952 * 1953 * \returns The number of overloaded declarations referenced by \c cursor. If it 1954 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0. 1955 */ 1956CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor); 1957 1958/** 1959 * \brief Retrieve a cursor for one of the overloaded declarations referenced 1960 * by a \c CXCursor_OverloadedDeclRef cursor. 1961 * 1962 * \param cursor The cursor whose overloaded declarations are being queried. 1963 * 1964 * \param index The zero-based index into the set of overloaded declarations in 1965 * the cursor. 1966 * 1967 * \returns A cursor representing the declaration referenced by the given 1968 * \c cursor at the specified \c index. If the cursor does not have an 1969 * associated set of overloaded declarations, or if the index is out of bounds, 1970 * returns \c clang_getNullCursor(); 1971 */ 1972CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor, 1973 unsigned index); 1974 1975/** 1976 * @} 1977 */ 1978 1979/** 1980 * \defgroup CINDEX_ATTRIBUTES Information for attributes 1981 * 1982 * @{ 1983 */ 1984 1985 1986/** 1987 * \brief For cursors representing an iboutletcollection attribute, 1988 * this function returns the collection element type. 1989 * 1990 */ 1991CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor); 1992 1993/** 1994 * @} 1995 */ 1996 1997/** 1998 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 1999 * 2000 * These routines provide the ability to traverse the abstract syntax tree 2001 * using cursors. 2002 * 2003 * @{ 2004 */ 2005 2006/** 2007 * \brief Describes how the traversal of the children of a particular 2008 * cursor should proceed after visiting a particular child cursor. 2009 * 2010 * A value of this enumeration type should be returned by each 2011 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 2012 */ 2013enum CXChildVisitResult { 2014 /** 2015 * \brief Terminates the cursor traversal. 2016 */ 2017 CXChildVisit_Break, 2018 /** 2019 * \brief Continues the cursor traversal with the next sibling of 2020 * the cursor just visited, without visiting its children. 2021 */ 2022 CXChildVisit_Continue, 2023 /** 2024 * \brief Recursively traverse the children of this cursor, using 2025 * the same visitor and client data. 2026 */ 2027 CXChildVisit_Recurse 2028}; 2029 2030/** 2031 * \brief Visitor invoked for each cursor found by a traversal. 2032 * 2033 * This visitor function will be invoked for each cursor found by 2034 * clang_visitCursorChildren(). Its first argument is the cursor being 2035 * visited, its second argument is the parent visitor for that cursor, 2036 * and its third argument is the client data provided to 2037 * clang_visitCursorChildren(). 2038 * 2039 * The visitor should return one of the \c CXChildVisitResult values 2040 * to direct clang_visitCursorChildren(). 2041 */ 2042typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 2043 CXCursor parent, 2044 CXClientData client_data); 2045 2046/** 2047 * \brief Visit the children of a particular cursor. 2048 * 2049 * This function visits all the direct children of the given cursor, 2050 * invoking the given \p visitor function with the cursors of each 2051 * visited child. The traversal may be recursive, if the visitor returns 2052 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 2053 * the visitor returns \c CXChildVisit_Break. 2054 * 2055 * \param parent the cursor whose child may be visited. All kinds of 2056 * cursors can be visited, including invalid cursors (which, by 2057 * definition, have no children). 2058 * 2059 * \param visitor the visitor function that will be invoked for each 2060 * child of \p parent. 2061 * 2062 * \param client_data pointer data supplied by the client, which will 2063 * be passed to the visitor each time it is invoked. 2064 * 2065 * \returns a non-zero value if the traversal was terminated 2066 * prematurely by the visitor returning \c CXChildVisit_Break. 2067 */ 2068CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 2069 CXCursorVisitor visitor, 2070 CXClientData client_data); 2071#ifdef __has_feature 2072# if __has_feature(blocks) 2073/** 2074 * \brief Visitor invoked for each cursor found by a traversal. 2075 * 2076 * This visitor block will be invoked for each cursor found by 2077 * clang_visitChildrenWithBlock(). Its first argument is the cursor being 2078 * visited, its second argument is the parent visitor for that cursor. 2079 * 2080 * The visitor should return one of the \c CXChildVisitResult values 2081 * to direct clang_visitChildrenWithBlock(). 2082 */ 2083typedef enum CXChildVisitResult 2084 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent); 2085 2086/** 2087 * Visits the children of a cursor using the specified block. Behaves 2088 * identically to clang_visitChildren() in all other respects. 2089 */ 2090unsigned clang_visitChildrenWithBlock(CXCursor parent, 2091 CXCursorVisitorBlock block); 2092# endif 2093#endif 2094 2095/** 2096 * @} 2097 */ 2098 2099/** 2100 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 2101 * 2102 * These routines provide the ability to determine references within and 2103 * across translation units, by providing the names of the entities referenced 2104 * by cursors, follow reference cursors to the declarations they reference, 2105 * and associate declarations with their definitions. 2106 * 2107 * @{ 2108 */ 2109 2110/** 2111 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 2112 * by the given cursor. 2113 * 2114 * A Unified Symbol Resolution (USR) is a string that identifies a particular 2115 * entity (function, class, variable, etc.) within a program. USRs can be 2116 * compared across translation units to determine, e.g., when references in 2117 * one translation refer to an entity defined in another translation unit. 2118 */ 2119CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 2120 2121/** 2122 * \brief Construct a USR for a specified Objective-C class. 2123 */ 2124CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); 2125 2126/** 2127 * \brief Construct a USR for a specified Objective-C category. 2128 */ 2129CINDEX_LINKAGE CXString 2130 clang_constructUSR_ObjCCategory(const char *class_name, 2131 const char *category_name); 2132 2133/** 2134 * \brief Construct a USR for a specified Objective-C protocol. 2135 */ 2136CINDEX_LINKAGE CXString 2137 clang_constructUSR_ObjCProtocol(const char *protocol_name); 2138 2139 2140/** 2141 * \brief Construct a USR for a specified Objective-C instance variable and 2142 * the USR for its containing class. 2143 */ 2144CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, 2145 CXString classUSR); 2146 2147/** 2148 * \brief Construct a USR for a specified Objective-C method and 2149 * the USR for its containing class. 2150 */ 2151CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, 2152 unsigned isInstanceMethod, 2153 CXString classUSR); 2154 2155/** 2156 * \brief Construct a USR for a specified Objective-C property and the USR 2157 * for its containing class. 2158 */ 2159CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, 2160 CXString classUSR); 2161 2162/** 2163 * \brief Retrieve a name for the entity referenced by this cursor. 2164 */ 2165CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 2166 2167/** 2168 * \brief Retrieve the display name for the entity referenced by this cursor. 2169 * 2170 * The display name contains extra information that helps identify the cursor, 2171 * such as the parameters of a function or template or the arguments of a 2172 * class template specialization. 2173 */ 2174CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor); 2175 2176/** \brief For a cursor that is a reference, retrieve a cursor representing the 2177 * entity that it references. 2178 * 2179 * Reference cursors refer to other entities in the AST. For example, an 2180 * Objective-C superclass reference cursor refers to an Objective-C class. 2181 * This function produces the cursor for the Objective-C class from the 2182 * cursor for the superclass reference. If the input cursor is a declaration or 2183 * definition, it returns that declaration or definition unchanged. 2184 * Otherwise, returns the NULL cursor. 2185 */ 2186CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 2187 2188/** 2189 * \brief For a cursor that is either a reference to or a declaration 2190 * of some entity, retrieve a cursor that describes the definition of 2191 * that entity. 2192 * 2193 * Some entities can be declared multiple times within a translation 2194 * unit, but only one of those declarations can also be a 2195 * definition. For example, given: 2196 * 2197 * \code 2198 * int f(int, int); 2199 * int g(int x, int y) { return f(x, y); } 2200 * int f(int a, int b) { return a + b; } 2201 * int f(int, int); 2202 * \endcode 2203 * 2204 * there are three declarations of the function "f", but only the 2205 * second one is a definition. The clang_getCursorDefinition() 2206 * function will take any cursor pointing to a declaration of "f" 2207 * (the first or fourth lines of the example) or a cursor referenced 2208 * that uses "f" (the call to "f' inside "g") and will return a 2209 * declaration cursor pointing to the definition (the second "f" 2210 * declaration). 2211 * 2212 * If given a cursor for which there is no corresponding definition, 2213 * e.g., because there is no definition of that entity within this 2214 * translation unit, returns a NULL cursor. 2215 */ 2216CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 2217 2218/** 2219 * \brief Determine whether the declaration pointed to by this cursor 2220 * is also a definition of that entity. 2221 */ 2222CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 2223 2224/** 2225 * \brief Retrieve the canonical cursor corresponding to the given cursor. 2226 * 2227 * In the C family of languages, many kinds of entities can be declared several 2228 * times within a single translation unit. For example, a structure type can 2229 * be forward-declared (possibly multiple times) and later defined: 2230 * 2231 * \code 2232 * struct X; 2233 * struct X; 2234 * struct X { 2235 * int member; 2236 * }; 2237 * \endcode 2238 * 2239 * The declarations and the definition of \c X are represented by three 2240 * different cursors, all of which are declarations of the same underlying 2241 * entity. One of these cursor is considered the "canonical" cursor, which 2242 * is effectively the representative for the underlying entity. One can 2243 * determine if two cursors are declarations of the same underlying entity by 2244 * comparing their canonical cursors. 2245 * 2246 * \returns The canonical cursor for the entity referred to by the given cursor. 2247 */ 2248CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor); 2249 2250/** 2251 * @} 2252 */ 2253 2254/** 2255 * \defgroup CINDEX_CPP C++ AST introspection 2256 * 2257 * The routines in this group provide access information in the ASTs specific 2258 * to C++ language features. 2259 * 2260 * @{ 2261 */ 2262 2263/** 2264 * \brief Determine if a C++ member function or member function template is 2265 * declared 'static'. 2266 */ 2267CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); 2268 2269/** 2270 * \brief Given a cursor that represents a template, determine 2271 * the cursor kind of the specializations would be generated by instantiating 2272 * the template. 2273 * 2274 * This routine can be used to determine what flavor of function template, 2275 * class template, or class template partial specialization is stored in the 2276 * cursor. For example, it can describe whether a class template cursor is 2277 * declared with "struct", "class" or "union". 2278 * 2279 * \param C The cursor to query. This cursor should represent a template 2280 * declaration. 2281 * 2282 * \returns The cursor kind of the specializations that would be generated 2283 * by instantiating the template \p C. If \p C is not a template, returns 2284 * \c CXCursor_NoDeclFound. 2285 */ 2286CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C); 2287 2288/** 2289 * \brief Given a cursor that may represent a specialization or instantiation 2290 * of a template, retrieve the cursor that represents the template that it 2291 * specializes or from which it was instantiated. 2292 * 2293 * This routine determines the template involved both for explicit 2294 * specializations of templates and for implicit instantiations of the template, 2295 * both of which are referred to as "specializations". For a class template 2296 * specialization (e.g., \c std::vector<bool>), this routine will return 2297 * either the primary template (\c std::vector) or, if the specialization was 2298 * instantiated from a class template partial specialization, the class template 2299 * partial specialization. For a class template partial specialization and a 2300 * function template specialization (including instantiations), this 2301 * this routine will return the specialized template. 2302 * 2303 * For members of a class template (e.g., member functions, member classes, or 2304 * static data members), returns the specialized or instantiated member. 2305 * Although not strictly "templates" in the C++ language, members of class 2306 * templates have the same notions of specializations and instantiations that 2307 * templates do, so this routine treats them similarly. 2308 * 2309 * \param C A cursor that may be a specialization of a template or a member 2310 * of a template. 2311 * 2312 * \returns If the given cursor is a specialization or instantiation of a 2313 * template or a member thereof, the template or member that it specializes or 2314 * from which it was instantiated. Otherwise, returns a NULL cursor. 2315 */ 2316CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C); 2317 2318/** 2319 * @} 2320 */ 2321 2322/** 2323 * \defgroup CINDEX_LEX Token extraction and manipulation 2324 * 2325 * The routines in this group provide access to the tokens within a 2326 * translation unit, along with a semantic mapping of those tokens to 2327 * their corresponding cursors. 2328 * 2329 * @{ 2330 */ 2331 2332/** 2333 * \brief Describes a kind of token. 2334 */ 2335typedef enum CXTokenKind { 2336 /** 2337 * \brief A token that contains some kind of punctuation. 2338 */ 2339 CXToken_Punctuation, 2340 2341 /** 2342 * \brief A language keyword. 2343 */ 2344 CXToken_Keyword, 2345 2346 /** 2347 * \brief An identifier (that is not a keyword). 2348 */ 2349 CXToken_Identifier, 2350 2351 /** 2352 * \brief A numeric, string, or character literal. 2353 */ 2354 CXToken_Literal, 2355 2356 /** 2357 * \brief A comment. 2358 */ 2359 CXToken_Comment 2360} CXTokenKind; 2361 2362/** 2363 * \brief Describes a single preprocessing token. 2364 */ 2365typedef struct { 2366 unsigned int_data[4]; 2367 void *ptr_data; 2368} CXToken; 2369 2370/** 2371 * \brief Determine the kind of the given token. 2372 */ 2373CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 2374 2375/** 2376 * \brief Determine the spelling of the given token. 2377 * 2378 * The spelling of a token is the textual representation of that token, e.g., 2379 * the text of an identifier or keyword. 2380 */ 2381CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 2382 2383/** 2384 * \brief Retrieve the source location of the given token. 2385 */ 2386CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 2387 CXToken); 2388 2389/** 2390 * \brief Retrieve a source range that covers the given token. 2391 */ 2392CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 2393 2394/** 2395 * \brief Tokenize the source code described by the given range into raw 2396 * lexical tokens. 2397 * 2398 * \param TU the translation unit whose text is being tokenized. 2399 * 2400 * \param Range the source range in which text should be tokenized. All of the 2401 * tokens produced by tokenization will fall within this source range, 2402 * 2403 * \param Tokens this pointer will be set to point to the array of tokens 2404 * that occur within the given source range. The returned pointer must be 2405 * freed with clang_disposeTokens() before the translation unit is destroyed. 2406 * 2407 * \param NumTokens will be set to the number of tokens in the \c *Tokens 2408 * array. 2409 * 2410 */ 2411CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 2412 CXToken **Tokens, unsigned *NumTokens); 2413 2414/** 2415 * \brief Annotate the given set of tokens by providing cursors for each token 2416 * that can be mapped to a specific entity within the abstract syntax tree. 2417 * 2418 * This token-annotation routine is equivalent to invoking 2419 * clang_getCursor() for the source locations of each of the 2420 * tokens. The cursors provided are filtered, so that only those 2421 * cursors that have a direct correspondence to the token are 2422 * accepted. For example, given a function call \c f(x), 2423 * clang_getCursor() would provide the following cursors: 2424 * 2425 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 2426 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 2427 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 2428 * 2429 * Only the first and last of these cursors will occur within the 2430 * annotate, since the tokens "f" and "x' directly refer to a function 2431 * and a variable, respectively, but the parentheses are just a small 2432 * part of the full syntax of the function call expression, which is 2433 * not provided as an annotation. 2434 * 2435 * \param TU the translation unit that owns the given tokens. 2436 * 2437 * \param Tokens the set of tokens to annotate. 2438 * 2439 * \param NumTokens the number of tokens in \p Tokens. 2440 * 2441 * \param Cursors an array of \p NumTokens cursors, whose contents will be 2442 * replaced with the cursors corresponding to each token. 2443 */ 2444CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 2445 CXToken *Tokens, unsigned NumTokens, 2446 CXCursor *Cursors); 2447 2448/** 2449 * \brief Free the given set of tokens. 2450 */ 2451CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 2452 CXToken *Tokens, unsigned NumTokens); 2453 2454/** 2455 * @} 2456 */ 2457 2458/** 2459 * \defgroup CINDEX_DEBUG Debugging facilities 2460 * 2461 * These routines are used for testing and debugging, only, and should not 2462 * be relied upon. 2463 * 2464 * @{ 2465 */ 2466 2467/* for debug/testing */ 2468CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); 2469CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 2470 const char **startBuf, 2471 const char **endBuf, 2472 unsigned *startLine, 2473 unsigned *startColumn, 2474 unsigned *endLine, 2475 unsigned *endColumn); 2476CINDEX_LINKAGE void clang_enableStackTraces(void); 2477CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data, 2478 unsigned stack_size); 2479 2480/** 2481 * @} 2482 */ 2483 2484/** 2485 * \defgroup CINDEX_CODE_COMPLET Code completion 2486 * 2487 * Code completion involves taking an (incomplete) source file, along with 2488 * knowledge of where the user is actively editing that file, and suggesting 2489 * syntactically- and semantically-valid constructs that the user might want to 2490 * use at that particular point in the source code. These data structures and 2491 * routines provide support for code completion. 2492 * 2493 * @{ 2494 */ 2495 2496/** 2497 * \brief A semantic string that describes a code-completion result. 2498 * 2499 * A semantic string that describes the formatting of a code-completion 2500 * result as a single "template" of text that should be inserted into the 2501 * source buffer when a particular code-completion result is selected. 2502 * Each semantic string is made up of some number of "chunks", each of which 2503 * contains some text along with a description of what that text means, e.g., 2504 * the name of the entity being referenced, whether the text chunk is part of 2505 * the template, or whether it is a "placeholder" that the user should replace 2506 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 2507 * description of the different kinds of chunks. 2508 */ 2509typedef void *CXCompletionString; 2510 2511/** 2512 * \brief A single result of code completion. 2513 */ 2514typedef struct { 2515 /** 2516 * \brief The kind of entity that this completion refers to. 2517 * 2518 * The cursor kind will be a macro, keyword, or a declaration (one of the 2519 * *Decl cursor kinds), describing the entity that the completion is 2520 * referring to. 2521 * 2522 * \todo In the future, we would like to provide a full cursor, to allow 2523 * the client to extract additional information from declaration. 2524 */ 2525 enum CXCursorKind CursorKind; 2526 2527 /** 2528 * \brief The code-completion string that describes how to insert this 2529 * code-completion result into the editing buffer. 2530 */ 2531 CXCompletionString CompletionString; 2532} CXCompletionResult; 2533 2534/** 2535 * \brief Describes a single piece of text within a code-completion string. 2536 * 2537 * Each "chunk" within a code-completion string (\c CXCompletionString) is 2538 * either a piece of text with a specific "kind" that describes how that text 2539 * should be interpreted by the client or is another completion string. 2540 */ 2541enum CXCompletionChunkKind { 2542 /** 2543 * \brief A code-completion string that describes "optional" text that 2544 * could be a part of the template (but is not required). 2545 * 2546 * The Optional chunk is the only kind of chunk that has a code-completion 2547 * string for its representation, which is accessible via 2548 * \c clang_getCompletionChunkCompletionString(). The code-completion string 2549 * describes an additional part of the template that is completely optional. 2550 * For example, optional chunks can be used to describe the placeholders for 2551 * arguments that match up with defaulted function parameters, e.g. given: 2552 * 2553 * \code 2554 * void f(int x, float y = 3.14, double z = 2.71828); 2555 * \endcode 2556 * 2557 * The code-completion string for this function would contain: 2558 * - a TypedText chunk for "f". 2559 * - a LeftParen chunk for "(". 2560 * - a Placeholder chunk for "int x" 2561 * - an Optional chunk containing the remaining defaulted arguments, e.g., 2562 * - a Comma chunk for "," 2563 * - a Placeholder chunk for "float y" 2564 * - an Optional chunk containing the last defaulted argument: 2565 * - a Comma chunk for "," 2566 * - a Placeholder chunk for "double z" 2567 * - a RightParen chunk for ")" 2568 * 2569 * There are many ways to handle Optional chunks. Two simple approaches are: 2570 * - Completely ignore optional chunks, in which case the template for the 2571 * function "f" would only include the first parameter ("int x"). 2572 * - Fully expand all optional chunks, in which case the template for the 2573 * function "f" would have all of the parameters. 2574 */ 2575 CXCompletionChunk_Optional, 2576 /** 2577 * \brief Text that a user would be expected to type to get this 2578 * code-completion result. 2579 * 2580 * There will be exactly one "typed text" chunk in a semantic string, which 2581 * will typically provide the spelling of a keyword or the name of a 2582 * declaration that could be used at the current code point. Clients are 2583 * expected to filter the code-completion results based on the text in this 2584 * chunk. 2585 */ 2586 CXCompletionChunk_TypedText, 2587 /** 2588 * \brief Text that should be inserted as part of a code-completion result. 2589 * 2590 * A "text" chunk represents text that is part of the template to be 2591 * inserted into user code should this particular code-completion result 2592 * be selected. 2593 */ 2594 CXCompletionChunk_Text, 2595 /** 2596 * \brief Placeholder text that should be replaced by the user. 2597 * 2598 * A "placeholder" chunk marks a place where the user should insert text 2599 * into the code-completion template. For example, placeholders might mark 2600 * the function parameters for a function declaration, to indicate that the 2601 * user should provide arguments for each of those parameters. The actual 2602 * text in a placeholder is a suggestion for the text to display before 2603 * the user replaces the placeholder with real code. 2604 */ 2605 CXCompletionChunk_Placeholder, 2606 /** 2607 * \brief Informative text that should be displayed but never inserted as 2608 * part of the template. 2609 * 2610 * An "informative" chunk contains annotations that can be displayed to 2611 * help the user decide whether a particular code-completion result is the 2612 * right option, but which is not part of the actual template to be inserted 2613 * by code completion. 2614 */ 2615 CXCompletionChunk_Informative, 2616 /** 2617 * \brief Text that describes the current parameter when code-completion is 2618 * referring to function call, message send, or template specialization. 2619 * 2620 * A "current parameter" chunk occurs when code-completion is providing 2621 * information about a parameter corresponding to the argument at the 2622 * code-completion point. For example, given a function 2623 * 2624 * \code 2625 * int add(int x, int y); 2626 * \endcode 2627 * 2628 * and the source code \c add(, where the code-completion point is after the 2629 * "(", the code-completion string will contain a "current parameter" chunk 2630 * for "int x", indicating that the current argument will initialize that 2631 * parameter. After typing further, to \c add(17, (where the code-completion 2632 * point is after the ","), the code-completion string will contain a 2633 * "current paremeter" chunk to "int y". 2634 */ 2635 CXCompletionChunk_CurrentParameter, 2636 /** 2637 * \brief A left parenthesis ('('), used to initiate a function call or 2638 * signal the beginning of a function parameter list. 2639 */ 2640 CXCompletionChunk_LeftParen, 2641 /** 2642 * \brief A right parenthesis (')'), used to finish a function call or 2643 * signal the end of a function parameter list. 2644 */ 2645 CXCompletionChunk_RightParen, 2646 /** 2647 * \brief A left bracket ('['). 2648 */ 2649 CXCompletionChunk_LeftBracket, 2650 /** 2651 * \brief A right bracket (']'). 2652 */ 2653 CXCompletionChunk_RightBracket, 2654 /** 2655 * \brief A left brace ('{'). 2656 */ 2657 CXCompletionChunk_LeftBrace, 2658 /** 2659 * \brief A right brace ('}'). 2660 */ 2661 CXCompletionChunk_RightBrace, 2662 /** 2663 * \brief A left angle bracket ('<'). 2664 */ 2665 CXCompletionChunk_LeftAngle, 2666 /** 2667 * \brief A right angle bracket ('>'). 2668 */ 2669 CXCompletionChunk_RightAngle, 2670 /** 2671 * \brief A comma separator (','). 2672 */ 2673 CXCompletionChunk_Comma, 2674 /** 2675 * \brief Text that specifies the result type of a given result. 2676 * 2677 * This special kind of informative chunk is not meant to be inserted into 2678 * the text buffer. Rather, it is meant to illustrate the type that an 2679 * expression using the given completion string would have. 2680 */ 2681 CXCompletionChunk_ResultType, 2682 /** 2683 * \brief A colon (':'). 2684 */ 2685 CXCompletionChunk_Colon, 2686 /** 2687 * \brief A semicolon (';'). 2688 */ 2689 CXCompletionChunk_SemiColon, 2690 /** 2691 * \brief An '=' sign. 2692 */ 2693 CXCompletionChunk_Equal, 2694 /** 2695 * Horizontal space (' '). 2696 */ 2697 CXCompletionChunk_HorizontalSpace, 2698 /** 2699 * Vertical space ('\n'), after which it is generally a good idea to 2700 * perform indentation. 2701 */ 2702 CXCompletionChunk_VerticalSpace 2703}; 2704 2705/** 2706 * \brief Determine the kind of a particular chunk within a completion string. 2707 * 2708 * \param completion_string the completion string to query. 2709 * 2710 * \param chunk_number the 0-based index of the chunk in the completion string. 2711 * 2712 * \returns the kind of the chunk at the index \c chunk_number. 2713 */ 2714CINDEX_LINKAGE enum CXCompletionChunkKind 2715clang_getCompletionChunkKind(CXCompletionString completion_string, 2716 unsigned chunk_number); 2717 2718/** 2719 * \brief Retrieve the text associated with a particular chunk within a 2720 * completion string. 2721 * 2722 * \param completion_string the completion string to query. 2723 * 2724 * \param chunk_number the 0-based index of the chunk in the completion string. 2725 * 2726 * \returns the text associated with the chunk at index \c chunk_number. 2727 */ 2728CINDEX_LINKAGE CXString 2729clang_getCompletionChunkText(CXCompletionString completion_string, 2730 unsigned chunk_number); 2731 2732/** 2733 * \brief Retrieve the completion string associated with a particular chunk 2734 * within a completion string. 2735 * 2736 * \param completion_string the completion string to query. 2737 * 2738 * \param chunk_number the 0-based index of the chunk in the completion string. 2739 * 2740 * \returns the completion string associated with the chunk at index 2741 * \c chunk_number, or NULL if that chunk is not represented by a completion 2742 * string. 2743 */ 2744CINDEX_LINKAGE CXCompletionString 2745clang_getCompletionChunkCompletionString(CXCompletionString completion_string, 2746 unsigned chunk_number); 2747 2748/** 2749 * \brief Retrieve the number of chunks in the given code-completion string. 2750 */ 2751CINDEX_LINKAGE unsigned 2752clang_getNumCompletionChunks(CXCompletionString completion_string); 2753 2754/** 2755 * \brief Determine the priority of this code completion. 2756 * 2757 * The priority of a code completion indicates how likely it is that this 2758 * particular completion is the completion that the user will select. The 2759 * priority is selected by various internal heuristics. 2760 * 2761 * \param completion_string The completion string to query. 2762 * 2763 * \returns The priority of this completion string. Smaller values indicate 2764 * higher-priority (more likely) completions. 2765 */ 2766CINDEX_LINKAGE unsigned 2767clang_getCompletionPriority(CXCompletionString completion_string); 2768 2769/** 2770 * \brief Determine the availability of the entity that this code-completion 2771 * string refers to. 2772 * 2773 * \param completion_string The completion string to query. 2774 * 2775 * \returns The availability of the completion string. 2776 */ 2777CINDEX_LINKAGE enum CXAvailabilityKind 2778clang_getCompletionAvailability(CXCompletionString completion_string); 2779 2780/** 2781 * \brief Contains the results of code-completion. 2782 * 2783 * This data structure contains the results of code completion, as 2784 * produced by \c clang_codeCompleteAt(). Its contents must be freed by 2785 * \c clang_disposeCodeCompleteResults. 2786 */ 2787typedef struct { 2788 /** 2789 * \brief The code-completion results. 2790 */ 2791 CXCompletionResult *Results; 2792 2793 /** 2794 * \brief The number of code-completion results stored in the 2795 * \c Results array. 2796 */ 2797 unsigned NumResults; 2798} CXCodeCompleteResults; 2799 2800/** 2801 * \brief Flags that can be passed to \c clang_codeCompleteAt() to 2802 * modify its behavior. 2803 * 2804 * The enumerators in this enumeration can be bitwise-OR'd together to 2805 * provide multiple options to \c clang_codeCompleteAt(). 2806 */ 2807enum CXCodeComplete_Flags { 2808 /** 2809 * \brief Whether to include macros within the set of code 2810 * completions returned. 2811 */ 2812 CXCodeComplete_IncludeMacros = 0x01, 2813 2814 /** 2815 * \brief Whether to include code patterns for language constructs 2816 * within the set of code completions, e.g., for loops. 2817 */ 2818 CXCodeComplete_IncludeCodePatterns = 0x02 2819}; 2820 2821/** 2822 * \brief Returns a default set of code-completion options that can be 2823 * passed to\c clang_codeCompleteAt(). 2824 */ 2825CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void); 2826 2827/** 2828 * \brief Perform code completion at a given location in a translation unit. 2829 * 2830 * This function performs code completion at a particular file, line, and 2831 * column within source code, providing results that suggest potential 2832 * code snippets based on the context of the completion. The basic model 2833 * for code completion is that Clang will parse a complete source file, 2834 * performing syntax checking up to the location where code-completion has 2835 * been requested. At that point, a special code-completion token is passed 2836 * to the parser, which recognizes this token and determines, based on the 2837 * current location in the C/Objective-C/C++ grammar and the state of 2838 * semantic analysis, what completions to provide. These completions are 2839 * returned via a new \c CXCodeCompleteResults structure. 2840 * 2841 * Code completion itself is meant to be triggered by the client when the 2842 * user types punctuation characters or whitespace, at which point the 2843 * code-completion location will coincide with the cursor. For example, if \c p 2844 * is a pointer, code-completion might be triggered after the "-" and then 2845 * after the ">" in \c p->. When the code-completion location is afer the ">", 2846 * the completion results will provide, e.g., the members of the struct that 2847 * "p" points to. The client is responsible for placing the cursor at the 2848 * beginning of the token currently being typed, then filtering the results 2849 * based on the contents of the token. For example, when code-completing for 2850 * the expression \c p->get, the client should provide the location just after 2851 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 2852 * client can filter the results based on the current token text ("get"), only 2853 * showing those results that start with "get". The intent of this interface 2854 * is to separate the relatively high-latency acquisition of code-completion 2855 * results from the filtering of results on a per-character basis, which must 2856 * have a lower latency. 2857 * 2858 * \param TU The translation unit in which code-completion should 2859 * occur. The source files for this translation unit need not be 2860 * completely up-to-date (and the contents of those source files may 2861 * be overridden via \p unsaved_files). Cursors referring into the 2862 * translation unit may be invalidated by this invocation. 2863 * 2864 * \param complete_filename The name of the source file where code 2865 * completion should be performed. This filename may be any file 2866 * included in the translation unit. 2867 * 2868 * \param complete_line The line at which code-completion should occur. 2869 * 2870 * \param complete_column The column at which code-completion should occur. 2871 * Note that the column should point just after the syntactic construct that 2872 * initiated code completion, and not in the middle of a lexical token. 2873 * 2874 * \param unsaved_files the Tiles that have not yet been saved to disk 2875 * but may be required for parsing or code completion, including the 2876 * contents of those files. The contents and name of these files (as 2877 * specified by CXUnsavedFile) are copied when necessary, so the 2878 * client only needs to guarantee their validity until the call to 2879 * this function returns. 2880 * 2881 * \param num_unsaved_files The number of unsaved file entries in \p 2882 * unsaved_files. 2883 * 2884 * \param options Extra options that control the behavior of code 2885 * completion, expressed as a bitwise OR of the enumerators of the 2886 * CXCodeComplete_Flags enumeration. The 2887 * \c clang_defaultCodeCompleteOptions() function returns a default set 2888 * of code-completion options. 2889 * 2890 * \returns If successful, a new \c CXCodeCompleteResults structure 2891 * containing code-completion results, which should eventually be 2892 * freed with \c clang_disposeCodeCompleteResults(). If code 2893 * completion fails, returns NULL. 2894 */ 2895CINDEX_LINKAGE 2896CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU, 2897 const char *complete_filename, 2898 unsigned complete_line, 2899 unsigned complete_column, 2900 struct CXUnsavedFile *unsaved_files, 2901 unsigned num_unsaved_files, 2902 unsigned options); 2903 2904/** 2905 * \brief Sort the code-completion results in case-insensitive alphabetical 2906 * order. 2907 * 2908 * \param Results The set of results to sort. 2909 * \param NumResults The number of results in \p Results. 2910 */ 2911CINDEX_LINKAGE 2912void clang_sortCodeCompletionResults(CXCompletionResult *Results, 2913 unsigned NumResults); 2914 2915/** 2916 * \brief Free the given set of code-completion results. 2917 */ 2918CINDEX_LINKAGE 2919void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 2920 2921/** 2922 * \brief Determine the number of diagnostics produced prior to the 2923 * location where code completion was performed. 2924 */ 2925CINDEX_LINKAGE 2926unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); 2927 2928/** 2929 * \brief Retrieve a diagnostic associated with the given code completion. 2930 * 2931 * \param Result the code completion results to query. 2932 * \param Index the zero-based diagnostic number to retrieve. 2933 * 2934 * \returns the requested diagnostic. This diagnostic must be freed 2935 * via a call to \c clang_disposeDiagnostic(). 2936 */ 2937CINDEX_LINKAGE 2938CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, 2939 unsigned Index); 2940 2941/** 2942 * @} 2943 */ 2944 2945 2946/** 2947 * \defgroup CINDEX_MISC Miscellaneous utility functions 2948 * 2949 * @{ 2950 */ 2951 2952/** 2953 * \brief Return a version string, suitable for showing to a user, but not 2954 * intended to be parsed (the format is not guaranteed to be stable). 2955 */ 2956CINDEX_LINKAGE CXString clang_getClangVersion(); 2957 2958 2959/** 2960 * \brief Enable/disable crash recovery. 2961 * 2962 * \param Flag to indicate if crash recovery is enabled. A non-zero value 2963 * enables crash recovery, while 0 disables it. 2964 */ 2965CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled); 2966 2967 /** 2968 * \brief Visitor invoked for each file in a translation unit 2969 * (used with clang_getInclusions()). 2970 * 2971 * This visitor function will be invoked by clang_getInclusions() for each 2972 * file included (either at the top-level or by #include directives) within 2973 * a translation unit. The first argument is the file being included, and 2974 * the second and third arguments provide the inclusion stack. The 2975 * array is sorted in order of immediate inclusion. For example, 2976 * the first element refers to the location that included 'included_file'. 2977 */ 2978typedef void (*CXInclusionVisitor)(CXFile included_file, 2979 CXSourceLocation* inclusion_stack, 2980 unsigned include_len, 2981 CXClientData client_data); 2982 2983/** 2984 * \brief Visit the set of preprocessor inclusions in a translation unit. 2985 * The visitor function is called with the provided data for every included 2986 * file. This does not include headers included by the PCH file (unless one 2987 * is inspecting the inclusions in the PCH file itself). 2988 */ 2989CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, 2990 CXInclusionVisitor visitor, 2991 CXClientData client_data); 2992 2993/** 2994 * @} 2995 */ 2996 2997/** 2998 * @} 2999 */ 3000 3001#ifdef __cplusplus 3002} 3003#endif 3004#endif 3005 3006