Index.h revision 44c181aec37789f25f6c15543c164416f72e562a
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 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 void *CXTranslationUnit; /* A translation unit instance. */ 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 * \defgroup CINDEX_STRING String manipulation routines 102 * 103 * @{ 104 */ 105 106/** 107 * \brief A character string. 108 * 109 * The \c CXString type is used to return strings from the interface when 110 * the ownership of that string might different from one call to the next. 111 * Use \c clang_getCString() to retrieve the string data and, once finished 112 * with the string data, call \c clang_disposeString() to free the string. 113 */ 114typedef struct { 115 const char *Spelling; 116 /* A 1 value indicates the clang_ indexing API needed to allocate the string 117 (and it must be freed by clang_disposeString()). */ 118 int MustFreeString; 119} CXString; 120 121/** 122 * \brief Retrieve the character data associated with the given string. 123 */ 124CINDEX_LINKAGE const char *clang_getCString(CXString string); 125 126/** 127 * \brief Free the given string, 128 */ 129CINDEX_LINKAGE void clang_disposeString(CXString string); 130 131/** 132 * @} 133 */ 134 135/** 136 * \brief clang_createIndex() provides a shared context for creating 137 * translation units. It provides two options: 138 * 139 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local" 140 * declarations (when loading any new translation units). A "local" declaration 141 * is one that belongs in the translation unit itself and not in a precompiled 142 * header that was used by the translation unit. If zero, all declarations 143 * will be enumerated. 144 * 145 * Here is an example: 146 * 147 * // excludeDeclsFromPCH = 1, displayDiagnostics=1 148 * Idx = clang_createIndex(1, 1); 149 * 150 * // IndexTest.pch was produced with the following command: 151 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch" 152 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch"); 153 * 154 * // This will load all the symbols from 'IndexTest.pch' 155 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 156 * TranslationUnitVisitor, 0); 157 * clang_disposeTranslationUnit(TU); 158 * 159 * // This will load all the symbols from 'IndexTest.c', excluding symbols 160 * // from 'IndexTest.pch'. 161 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" }; 162 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 163 * 0, 0); 164 * clang_visitChildren(clang_getTranslationUnitCursor(TU), 165 * TranslationUnitVisitor, 0); 166 * clang_disposeTranslationUnit(TU); 167 * 168 * This process of creating the 'pch', loading it separately, and using it (via 169 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks 170 * (which gives the indexer the same performance benefit as the compiler). 171 */ 172CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH, 173 int displayDiagnostics); 174 175/** 176 * \brief Destroy the given index. 177 * 178 * The index must not be destroyed until all of the translation units created 179 * within that index have been destroyed. 180 */ 181CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); 182 183/** 184 * \brief Request that AST's be generated externally for API calls which parse 185 * source code on the fly, e.g. \see createTranslationUnitFromSourceFile. 186 * 187 * Note: This is for debugging purposes only, and may be removed at a later 188 * date. 189 * 190 * \param index - The index to update. 191 * \param value - The new flag value. 192 */ 193CINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index, 194 int value); 195/** 196 * \defgroup CINDEX_FILES File manipulation routines 197 * 198 * @{ 199 */ 200 201/** 202 * \brief A particular source file that is part of a translation unit. 203 */ 204typedef void *CXFile; 205 206 207/** 208 * \brief Retrieve the complete file and path name of the given file. 209 */ 210CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile); 211 212/** 213 * \brief Retrieve the last modification time of the given file. 214 */ 215CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile); 216 217/** 218 * \brief Retrieve a file handle within the given translation unit. 219 * 220 * \param tu the translation unit 221 * 222 * \param file_name the name of the file. 223 * 224 * \returns the file handle for the named file in the translation unit \p tu, 225 * or a NULL file handle if the file was not a part of this translation unit. 226 */ 227CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, 228 const char *file_name); 229 230/** 231 * @} 232 */ 233 234/** 235 * \defgroup CINDEX_LOCATIONS Physical source locations 236 * 237 * Clang represents physical source locations in its abstract syntax tree in 238 * great detail, with file, line, and column information for the majority of 239 * the tokens parsed in the source code. These data types and functions are 240 * used to represent source location information, either for a particular 241 * point in the program or for a range of points in the program, and extract 242 * specific location information from those data types. 243 * 244 * @{ 245 */ 246 247/** 248 * \brief Identifies a specific source location within a translation 249 * unit. 250 * 251 * Use clang_getInstantiationLocation() to map a source location to a 252 * particular file, line, and column. 253 */ 254typedef struct { 255 void *ptr_data[2]; 256 unsigned int_data; 257} CXSourceLocation; 258 259/** 260 * \brief Identifies a half-open character range in the source code. 261 * 262 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the 263 * starting and end locations from a source range, respectively. 264 */ 265typedef struct { 266 void *ptr_data[2]; 267 unsigned begin_int_data; 268 unsigned end_int_data; 269} CXSourceRange; 270 271/** 272 * \brief Retrieve a NULL (invalid) source location. 273 */ 274CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(); 275 276/** 277 * \determine Determine whether two source locations, which must refer into 278 * the same translation unit, refer to exactly the same point in the source 279 * code. 280 * 281 * \returns non-zero if the source locations refer to the same location, zero 282 * if they refer to different locations. 283 */ 284CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1, 285 CXSourceLocation loc2); 286 287/** 288 * \brief Retrieves the source location associated with a given file/line/column 289 * in a particular translation unit. 290 */ 291CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu, 292 CXFile file, 293 unsigned line, 294 unsigned column); 295 296/** 297 * \brief Retrieve a NULL (invalid) source range. 298 */ 299CINDEX_LINKAGE CXSourceRange clang_getNullRange(); 300 301/** 302 * \brief Retrieve a source range given the beginning and ending source 303 * locations. 304 */ 305CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, 306 CXSourceLocation end); 307 308/** 309 * \brief Retrieve the file, line, column, and offset represented by 310 * the given source location. 311 * 312 * \param location the location within a source file that will be decomposed 313 * into its parts. 314 * 315 * \param file [out] if non-NULL, will be set to the file to which the given 316 * source location points. 317 * 318 * \param line [out] if non-NULL, will be set to the line to which the given 319 * source location points. 320 * 321 * \param column [out] if non-NULL, will be set to the column to which the given 322 * source location points. 323 * 324 * \param offset [out] if non-NULL, will be set to the offset into the 325 * buffer to which the given source location points. 326 */ 327CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, 328 CXFile *file, 329 unsigned *line, 330 unsigned *column, 331 unsigned *offset); 332 333/** 334 * \brief Retrieve a source location representing the first character within a 335 * source range. 336 */ 337CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); 338 339/** 340 * \brief Retrieve a source location representing the last character within a 341 * source range. 342 */ 343CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); 344 345/** 346 * @} 347 */ 348 349/** 350 * \defgroup CINDEX_DIAG Diagnostic reporting 351 * 352 * @{ 353 */ 354 355/** 356 * \brief Describes the severity of a particular diagnostic. 357 */ 358enum CXDiagnosticSeverity { 359 /** 360 * \brief A diagnostic that has been suppressed, e.g., by a command-line 361 * option. 362 */ 363 CXDiagnostic_Ignored = 0, 364 365 /** 366 * \brief This diagnostic is a note that should be attached to the 367 * previous (non-note) diagnostic. 368 */ 369 CXDiagnostic_Note = 1, 370 371 /** 372 * \brief This diagnostic indicates suspicious code that may not be 373 * wrong. 374 */ 375 CXDiagnostic_Warning = 2, 376 377 /** 378 * \brief This diagnostic indicates that the code is ill-formed. 379 */ 380 CXDiagnostic_Error = 3, 381 382 /** 383 * \brief This diagnostic indicates that the code is ill-formed such 384 * that future parser recovery is unlikely to produce useful 385 * results. 386 */ 387 CXDiagnostic_Fatal = 4 388}; 389 390/** 391 * \brief A single diagnostic, containing the diagnostic's severity, 392 * location, text, source ranges, and fix-it hints. 393 */ 394typedef void *CXDiagnostic; 395 396/** 397 * \brief Determine the number of diagnostics produced for the given 398 * translation unit. 399 */ 400CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit); 401 402/** 403 * \brief Retrieve a diagnostic associated with the given translation unit. 404 * 405 * \param Unit the translation unit to query. 406 * \param Index the zero-based diagnostic number to retrieve. 407 * 408 * \returns the requested diagnostic. This diagnostic must be freed 409 * via a call to \c clang_disposeDiagnostic(). 410 */ 411CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, 412 unsigned Index); 413 414/** 415 * \brief Destroy a diagnostic. 416 */ 417CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic); 418 419/** 420 * \brief Options to control the display of diagnostics. 421 * 422 * The values in this enum are meant to be combined to customize the 423 * behavior of \c clang_displayDiagnostic(). 424 */ 425enum CXDiagnosticDisplayOptions { 426 /** 427 * \brief Display the source-location information where the 428 * diagnostic was located. 429 * 430 * When set, diagnostics will be prefixed by the file, line, and 431 * (optionally) column to which the diagnostic refers. For example, 432 * 433 * \code 434 * test.c:28: warning: extra tokens at end of #endif directive 435 * \endcode 436 * 437 * This option corresponds to the clang flag \c -fshow-source-location. 438 */ 439 CXDiagnostic_DisplaySourceLocation = 0x01, 440 441 /** 442 * \brief If displaying the source-location information of the 443 * diagnostic, also include the column number. 444 * 445 * This option corresponds to the clang flag \c -fshow-column. 446 */ 447 CXDiagnostic_DisplayColumn = 0x02, 448 449 /** 450 * \brief If displaying the source-location information of the 451 * diagnostic, also include information about source ranges in a 452 * machine-parsable format. 453 * 454 * This option corresponds to the clang flag 455 * \c -fdiagnostics-print-source-range-info. 456 */ 457 CXDiagnostic_DisplaySourceRanges = 0x04 458}; 459 460/** 461 * \brief Format the given diagnostic in a manner that is suitable for display. 462 * 463 * This routine will format the given diagnostic to a string, rendering 464 * the diagnostic according to the various options given. The 465 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of 466 * options that most closely mimics the behavior of the clang compiler. 467 * 468 * \param Diagnostic The diagnostic to print. 469 * 470 * \param Options A set of options that control the diagnostic display, 471 * created by combining \c CXDiagnosticDisplayOptions values. 472 * 473 * \returns A new string containing for formatted diagnostic. 474 */ 475CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, 476 unsigned Options); 477 478/** 479 * \brief Retrieve the set of display options most similar to the 480 * default behavior of the clang compiler. 481 * 482 * \returns A set of display options suitable for use with \c 483 * clang_displayDiagnostic(). 484 */ 485CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void); 486 487/** 488 * \brief Print a diagnostic to the given file. 489 */ 490 491/** 492 * \brief Determine the severity of the given diagnostic. 493 */ 494CINDEX_LINKAGE enum CXDiagnosticSeverity 495clang_getDiagnosticSeverity(CXDiagnostic); 496 497/** 498 * \brief Retrieve the source location of the given diagnostic. 499 * 500 * This location is where Clang would print the caret ('^') when 501 * displaying the diagnostic on the command line. 502 */ 503CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic); 504 505/** 506 * \brief Retrieve the text of the given diagnostic. 507 */ 508CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic); 509 510/** 511 * \brief Determine the number of source ranges associated with the given 512 * diagnostic. 513 */ 514CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic); 515 516/** 517 * \brief Retrieve a source range associated with the diagnostic. 518 * 519 * A diagnostic's source ranges highlight important elements in the source 520 * code. On the command line, Clang displays source ranges by 521 * underlining them with '~' characters. 522 * 523 * \param Diagnostic the diagnostic whose range is being extracted. 524 * 525 * \param Range the zero-based index specifying which range to 526 * 527 * \returns the requested source range. 528 */ 529CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic, 530 unsigned Range); 531 532/** 533 * \brief Determine the number of fix-it hints associated with the 534 * given diagnostic. 535 */ 536CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic); 537 538/** 539 * \brief Retrieve the replacement information for a given fix-it. 540 * 541 * Fix-its are described in terms of a source range whose contents 542 * should be replaced by a string. This approach generalizes over 543 * three kinds of operations: removal of source code (the range covers 544 * the code to be removed and the replacement string is empty), 545 * replacement of source code (the range covers the code to be 546 * replaced and the replacement string provides the new code), and 547 * insertion (both the start and end of the range point at the 548 * insertion location, and the replacement string provides the text to 549 * insert). 550 * 551 * \param Diagnostic The diagnostic whose fix-its are being queried. 552 * 553 * \param FixIt The zero-based index of the fix-it. 554 * 555 * \param ReplacementRange The source range whose contents will be 556 * replaced with the returned replacement string. Note that source 557 * ranges are half-open ranges [a, b), so the source code should be 558 * replaced from a and up to (but not including) b. 559 * 560 * \returns A string containing text that should be replace the source 561 * code indicated by the \c ReplacementRange. 562 */ 563CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, 564 unsigned FixIt, 565 CXSourceRange *ReplacementRange); 566 567/** 568 * @} 569 */ 570 571/** 572 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation 573 * 574 * The routines in this group provide the ability to create and destroy 575 * translation units from files, either by parsing the contents of the files or 576 * by reading in a serialized representation of a translation unit. 577 * 578 * @{ 579 */ 580 581/** 582 * \brief Get the original translation unit source file name. 583 */ 584CINDEX_LINKAGE CXString 585clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit); 586 587/** 588 * \brief Return the CXTranslationUnit for a given source file and the provided 589 * command line arguments one would pass to the compiler. 590 * 591 * Note: The 'source_filename' argument is optional. If the caller provides a 592 * NULL pointer, the name of the source file is expected to reside in the 593 * specified command line arguments. 594 * 595 * Note: When encountered in 'clang_command_line_args', the following options 596 * are ignored: 597 * 598 * '-c' 599 * '-emit-ast' 600 * '-fsyntax-only' 601 * '-o <output file>' (both '-o' and '<output file>' are ignored) 602 * 603 * 604 * \param source_filename - The name of the source file to load, or NULL if the 605 * source file is included in clang_command_line_args. 606 * 607 * \param num_unsaved_files the number of unsaved file entries in \p 608 * unsaved_files. 609 * 610 * \param unsaved_files the files that have not yet been saved to disk 611 * but may be required for code completion, including the contents of 612 * those files. The contents and name of these files (as specified by 613 * CXUnsavedFile) are copied when necessary, so the client only needs to 614 * guarantee their validity until the call to this function returns. 615 * 616 * \param diag_callback callback function that will receive any diagnostics 617 * emitted while processing this source file. If NULL, diagnostics will be 618 * suppressed. 619 * 620 * \param diag_client_data client data that will be passed to the diagnostic 621 * callback function. 622 */ 623CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile( 624 CXIndex CIdx, 625 const char *source_filename, 626 int num_clang_command_line_args, 627 const char **clang_command_line_args, 628 unsigned num_unsaved_files, 629 struct CXUnsavedFile *unsaved_files); 630 631/** 632 * \brief Create a translation unit from an AST file (-emit-ast). 633 */ 634CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex, 635 const char *ast_filename); 636 637/** 638 * \brief Flags that control the creation of translation units. 639 * 640 * The enumerators in this enumeration type are meant to be bitwise 641 * ORed together to specify which options should be used when 642 * constructing the translation unit. 643 */ 644enum CXTranslationUnit_Flags { 645 /** 646 * \brief Used to indicate that no special translation-unit options are 647 * needed. 648 */ 649 CXTranslationUnit_None = 0x0, 650 651 /** 652 * \brief Used to indicate that the parser should construct a "detailed" 653 * preprocessing record, including all macro definitions and instantiations. 654 * 655 * Constructing a detailed preprocessing record requires more memory 656 * and time to parse, since the information contained in the record 657 * is usually not retained. However, it can be useful for 658 * applications that require more detailed information about the 659 * behavior of the preprocessor. 660 */ 661 CXTranslationUnit_DetailedPreprocessingRecord = 0x01, 662 663 /** 664 * \brief A flag that indicates that the intent of parsing the 665 * given translation unit is for live editing of the file. 666 * 667 * This flag is essentially a meta-flag that callers can use to indicate 668 * that the translation unit is being edited and, therefore, is likely to 669 * be reparsed many times. It enables an unspecified set of optimizations 670 * (e.g., the precompiled preamble) geared toward improving the performance 671 * of \c clang_reparseTranslationUnit(). 672 */ 673 CXTranslationUnit_Editing = 0x02, 674 675 /** 676 * \brief Used to indicate that the translation unit should be built with an 677 * implicit precompiled header for the preamble. 678 * 679 * An implicit precompiled header is used as an optimization when a 680 * particular translation unit is likely to be reparsed many times 681 * when the sources aren't changing that often. In this case, an 682 * implicit precompiled header will be built containing all of the 683 * initial includes at the top of the main file (what we refer to as 684 * the "preamble" of the file). In subsequent parses, if the 685 * preamble or the files in it have not changed, \c 686 * clang_reparseTranslationUnit() will re-use the implicit 687 * precompiled header to improve parsing performance. 688 */ 689 CXTranslationUnit_PrecompiledPreamble = 0x04 690}; 691 692/** 693 * \brief Parse the given source file and the translation unit corresponding 694 * to that file. 695 * 696 * This routine is the main entry point for the Clang C API, providing the 697 * ability to parse a source file into a translation unit that can then be 698 * queried by other functions in the API. This routine accepts a set of 699 * command-line arguments so that the compilation can be configured in the same 700 * way that the compiler is configured on the command line. 701 * 702 * \param CIdx The index object with which the translation unit will be 703 * associated. 704 * 705 * \param source_filename The name of the source file to load, or NULL if the 706 * source file is included in \p clang_command_line_args. 707 * 708 * \param command_line_args The command-line arguments that would be 709 * passed to the \c clang executable if it were being invoked out-of-process. 710 * These command-line options will be parsed and will affect how the translation 711 * unit is parsed. Note that the following options are ignored: '-c', 712 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'. 713 * 714 * \param num_command_line_args The number of command-line arguments in 715 * \p command_line_args. 716 * 717 * \param unsaved_files the files that have not yet been saved to disk 718 * but may be required for code completion, including the contents of 719 * those files. The contents and name of these files (as specified by 720 * CXUnsavedFile) are copied when necessary, so the client only needs to 721 * guarantee their validity until the call to this function returns. 722 * 723 * \param num_unsaved_files the number of unsaved file entries in \p 724 * unsaved_files. 725 * 726 * \param options A bitmask of options that affects how the translation unit 727 * is managed but not its compilation. This should be a bitwise OR of the 728 * CXTranslationUnit_XXX flags. 729 * 730 * \returns A new translation unit describing the parsed code and containing 731 * any diagnostics produced by the compiler. If there is a failure from which 732 * the compiler cannot recover, returns NULL. 733 */ 734CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx, 735 const char *source_filename, 736 const char **command_line_args, 737 int num_command_line_args, 738 struct CXUnsavedFile *unsaved_files, 739 unsigned num_unsaved_files, 740 unsigned options); 741 742/** 743 * \brief Destroy the specified CXTranslationUnit object. 744 */ 745CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit); 746 747/** 748 * \brief Reparse the source files that produced this translation unit. 749 * 750 * This routine can be used to re-parse the source files that originally 751 * created the given translation unit, for example because those source files 752 * have changed (either on disk or as passed via \p unsaved_files). The 753 * source code will be reparsed with the same command-line options as it 754 * was originally parsed. 755 * 756 * Reparsing a translation unit invalidates all cursors and source locations 757 * that refer into that translation unit. This makes reparsing a translation 758 * unit semantically equivalent to destroying the translation unit and then 759 * creating a new translation unit with the same command-line arguments. 760 * However, it may be more efficient to reparse a translation 761 * unit using this routine. 762 * 763 * \param TU The translation unit whose contents will be re-parsed. The 764 * translation unit must originally have been built with 765 * \c clang_createTranslationUnitFromSourceFile(). 766 * 767 * \param num_unsaved_files The number of unsaved file entries in \p 768 * unsaved_files. 769 * 770 * \param unsaved_files The files that have not yet been saved to disk 771 * but may be required for parsing, including the contents of 772 * those files. The contents and name of these files (as specified by 773 * CXUnsavedFile) are copied when necessary, so the client only needs to 774 * guarantee their validity until the call to this function returns. 775 * 776 * \returns 0 if the sources could be reparsed. A non-zero value will be 777 * returned if reparsing was impossible, such that the translation unit is 778 * invalid. In such cases, the only valid call for \p TU is 779 * \c clang_disposeTranslationUnit(TU). 780 */ 781CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU, 782 unsigned num_unsaved_files, 783 struct CXUnsavedFile *unsaved_files); 784 785/** 786 * @} 787 */ 788 789/** 790 * \brief Describes the kind of entity that a cursor refers to. 791 */ 792enum CXCursorKind { 793 /* Declarations */ 794 /** 795 * \brief A declaration whose specific kind is not exposed via this 796 * interface. 797 * 798 * Unexposed declarations have the same operations as any other kind 799 * of declaration; one can extract their location information, 800 * spelling, find their definitions, etc. However, the specific kind 801 * of the declaration is not reported. 802 */ 803 CXCursor_UnexposedDecl = 1, 804 /** \brief A C or C++ struct. */ 805 CXCursor_StructDecl = 2, 806 /** \brief A C or C++ union. */ 807 CXCursor_UnionDecl = 3, 808 /** \brief A C++ class. */ 809 CXCursor_ClassDecl = 4, 810 /** \brief An enumeration. */ 811 CXCursor_EnumDecl = 5, 812 /** 813 * \brief A field (in C) or non-static data member (in C++) in a 814 * struct, union, or C++ class. 815 */ 816 CXCursor_FieldDecl = 6, 817 /** \brief An enumerator constant. */ 818 CXCursor_EnumConstantDecl = 7, 819 /** \brief A function. */ 820 CXCursor_FunctionDecl = 8, 821 /** \brief A variable. */ 822 CXCursor_VarDecl = 9, 823 /** \brief A function or method parameter. */ 824 CXCursor_ParmDecl = 10, 825 /** \brief An Objective-C @interface. */ 826 CXCursor_ObjCInterfaceDecl = 11, 827 /** \brief An Objective-C @interface for a category. */ 828 CXCursor_ObjCCategoryDecl = 12, 829 /** \brief An Objective-C @protocol declaration. */ 830 CXCursor_ObjCProtocolDecl = 13, 831 /** \brief An Objective-C @property declaration. */ 832 CXCursor_ObjCPropertyDecl = 14, 833 /** \brief An Objective-C instance variable. */ 834 CXCursor_ObjCIvarDecl = 15, 835 /** \brief An Objective-C instance method. */ 836 CXCursor_ObjCInstanceMethodDecl = 16, 837 /** \brief An Objective-C class method. */ 838 CXCursor_ObjCClassMethodDecl = 17, 839 /** \brief An Objective-C @implementation. */ 840 CXCursor_ObjCImplementationDecl = 18, 841 /** \brief An Objective-C @implementation for a category. */ 842 CXCursor_ObjCCategoryImplDecl = 19, 843 /** \brief A typedef */ 844 CXCursor_TypedefDecl = 20, 845 /** \brief A C++ class method. */ 846 CXCursor_CXXMethod = 21, 847 /** \brief A C++ namespace. */ 848 CXCursor_Namespace = 22, 849 /** \brief A linkage specification, e.g. 'extern "C"'. */ 850 CXCursor_LinkageSpec = 23, 851 852 CXCursor_FirstDecl = CXCursor_UnexposedDecl, 853 CXCursor_LastDecl = CXCursor_LinkageSpec, 854 855 /* References */ 856 CXCursor_FirstRef = 40, /* Decl references */ 857 CXCursor_ObjCSuperClassRef = 40, 858 CXCursor_ObjCProtocolRef = 41, 859 CXCursor_ObjCClassRef = 42, 860 /** 861 * \brief A reference to a type declaration. 862 * 863 * A type reference occurs anywhere where a type is named but not 864 * declared. For example, given: 865 * 866 * \code 867 * typedef unsigned size_type; 868 * size_type size; 869 * \endcode 870 * 871 * The typedef is a declaration of size_type (CXCursor_TypedefDecl), 872 * while the type of the variable "size" is referenced. The cursor 873 * referenced by the type of size is the typedef for size_type. 874 */ 875 CXCursor_TypeRef = 43, 876 CXCursor_LastRef = 43, 877 878 /* Error conditions */ 879 CXCursor_FirstInvalid = 70, 880 CXCursor_InvalidFile = 70, 881 CXCursor_NoDeclFound = 71, 882 CXCursor_NotImplemented = 72, 883 CXCursor_InvalidCode = 73, 884 CXCursor_LastInvalid = CXCursor_InvalidCode, 885 886 /* Expressions */ 887 CXCursor_FirstExpr = 100, 888 889 /** 890 * \brief An expression whose specific kind is not exposed via this 891 * interface. 892 * 893 * Unexposed expressions have the same operations as any other kind 894 * of expression; one can extract their location information, 895 * spelling, children, etc. However, the specific kind of the 896 * expression is not reported. 897 */ 898 CXCursor_UnexposedExpr = 100, 899 900 /** 901 * \brief An expression that refers to some value declaration, such 902 * as a function, varible, or enumerator. 903 */ 904 CXCursor_DeclRefExpr = 101, 905 906 /** 907 * \brief An expression that refers to a member of a struct, union, 908 * class, Objective-C class, etc. 909 */ 910 CXCursor_MemberRefExpr = 102, 911 912 /** \brief An expression that calls a function. */ 913 CXCursor_CallExpr = 103, 914 915 /** \brief An expression that sends a message to an Objective-C 916 object or class. */ 917 CXCursor_ObjCMessageExpr = 104, 918 919 /** \brief An expression that represents a block literal. */ 920 CXCursor_BlockExpr = 105, 921 922 CXCursor_LastExpr = 105, 923 924 /* Statements */ 925 CXCursor_FirstStmt = 200, 926 /** 927 * \brief A statement whose specific kind is not exposed via this 928 * interface. 929 * 930 * Unexposed statements have the same operations as any other kind of 931 * statement; one can extract their location information, spelling, 932 * children, etc. However, the specific kind of the statement is not 933 * reported. 934 */ 935 CXCursor_UnexposedStmt = 200, 936 CXCursor_LastStmt = 200, 937 938 /** 939 * \brief Cursor that represents the translation unit itself. 940 * 941 * The translation unit cursor exists primarily to act as the root 942 * cursor for traversing the contents of a translation unit. 943 */ 944 CXCursor_TranslationUnit = 300, 945 946 /* Attributes */ 947 CXCursor_FirstAttr = 400, 948 /** 949 * \brief An attribute whose specific kind is not exposed via this 950 * interface. 951 */ 952 CXCursor_UnexposedAttr = 400, 953 954 CXCursor_IBActionAttr = 401, 955 CXCursor_IBOutletAttr = 402, 956 CXCursor_IBOutletCollectionAttr = 403, 957 CXCursor_LastAttr = CXCursor_IBOutletCollectionAttr, 958 959 /* Preprocessing */ 960 CXCursor_PreprocessingDirective = 500, 961 CXCursor_MacroDefinition = 501, 962 CXCursor_MacroInstantiation = 502, 963 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective, 964 CXCursor_LastPreprocessing = CXCursor_MacroInstantiation 965}; 966 967/** 968 * \brief A cursor representing some element in the abstract syntax tree for 969 * a translation unit. 970 * 971 * The cursor abstraction unifies the different kinds of entities in a 972 * program--declaration, statements, expressions, references to declarations, 973 * etc.--under a single "cursor" abstraction with a common set of operations. 974 * Common operation for a cursor include: getting the physical location in 975 * a source file where the cursor points, getting the name associated with a 976 * cursor, and retrieving cursors for any child nodes of a particular cursor. 977 * 978 * Cursors can be produced in two specific ways. 979 * clang_getTranslationUnitCursor() produces a cursor for a translation unit, 980 * from which one can use clang_visitChildren() to explore the rest of the 981 * translation unit. clang_getCursor() maps from a physical source location 982 * to the entity that resides at that location, allowing one to map from the 983 * source code into the AST. 984 */ 985typedef struct { 986 enum CXCursorKind kind; 987 void *data[3]; 988} CXCursor; 989 990/** 991 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations 992 * 993 * @{ 994 */ 995 996/** 997 * \brief Retrieve the NULL cursor, which represents no entity. 998 */ 999CINDEX_LINKAGE CXCursor clang_getNullCursor(void); 1000 1001/** 1002 * \brief Retrieve the cursor that represents the given translation unit. 1003 * 1004 * The translation unit cursor can be used to start traversing the 1005 * various declarations within the given translation unit. 1006 */ 1007CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit); 1008 1009/** 1010 * \brief Determine whether two cursors are equivalent. 1011 */ 1012CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor); 1013 1014/** 1015 * \brief Retrieve the kind of the given cursor. 1016 */ 1017CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor); 1018 1019/** 1020 * \brief Determine whether the given cursor kind represents a declaration. 1021 */ 1022CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind); 1023 1024/** 1025 * \brief Determine whether the given cursor kind represents a simple 1026 * reference. 1027 * 1028 * Note that other kinds of cursors (such as expressions) can also refer to 1029 * other cursors. Use clang_getCursorReferenced() to determine whether a 1030 * particular cursor refers to another entity. 1031 */ 1032CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind); 1033 1034/** 1035 * \brief Determine whether the given cursor kind represents an expression. 1036 */ 1037CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind); 1038 1039/** 1040 * \brief Determine whether the given cursor kind represents a statement. 1041 */ 1042CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind); 1043 1044/** 1045 * \brief Determine whether the given cursor kind represents an invalid 1046 * cursor. 1047 */ 1048CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind); 1049 1050/** 1051 * \brief Determine whether the given cursor kind represents a translation 1052 * unit. 1053 */ 1054CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind); 1055 1056/*** 1057 * \brief Determine whether the given cursor represents a preprocessing 1058 * element, such as a preprocessor directive or macro instantiation. 1059 */ 1060CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind); 1061 1062/*** 1063 * \brief Determine whether the given cursor represents a currently 1064 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt). 1065 */ 1066CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind); 1067 1068/** 1069 * \brief Describe the linkage of the entity referred to by a cursor. 1070 */ 1071enum CXLinkageKind { 1072 /** \brief This value indicates that no linkage information is available 1073 * for a provided CXCursor. */ 1074 CXLinkage_Invalid, 1075 /** 1076 * \brief This is the linkage for variables, parameters, and so on that 1077 * have automatic storage. This covers normal (non-extern) local variables. 1078 */ 1079 CXLinkage_NoLinkage, 1080 /** \brief This is the linkage for static variables and static functions. */ 1081 CXLinkage_Internal, 1082 /** \brief This is the linkage for entities with external linkage that live 1083 * in C++ anonymous namespaces.*/ 1084 CXLinkage_UniqueExternal, 1085 /** \brief This is the linkage for entities with true, external linkage. */ 1086 CXLinkage_External 1087}; 1088 1089/** 1090 * \brief Determine the linkage of the entity referred to by a given cursor. 1091 */ 1092CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor); 1093 1094/** 1095 * \brief Describe the "language" of the entity referred to by a cursor. 1096 */ 1097CINDEX_LINKAGE enum CXLanguageKind { 1098 CXLanguage_Invalid = 0, 1099 CXLanguage_C, 1100 CXLanguage_ObjC, 1101 CXLanguage_CPlusPlus 1102}; 1103 1104/** 1105 * \brief Determine the "language" of the entity referred to by a given cursor. 1106 */ 1107CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor); 1108 1109/** 1110 * @} 1111 */ 1112 1113/** 1114 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code 1115 * 1116 * Cursors represent a location within the Abstract Syntax Tree (AST). These 1117 * routines help map between cursors and the physical locations where the 1118 * described entities occur in the source code. The mapping is provided in 1119 * both directions, so one can map from source code to the AST and back. 1120 * 1121 * @{ 1122 */ 1123 1124/** 1125 * \brief Map a source location to the cursor that describes the entity at that 1126 * location in the source code. 1127 * 1128 * clang_getCursor() maps an arbitrary source location within a translation 1129 * unit down to the most specific cursor that describes the entity at that 1130 * location. For example, given an expression \c x + y, invoking 1131 * clang_getCursor() with a source location pointing to "x" will return the 1132 * cursor for "x"; similarly for "y". If the cursor points anywhere between 1133 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor() 1134 * will return a cursor referring to the "+" expression. 1135 * 1136 * \returns a cursor representing the entity at the given source location, or 1137 * a NULL cursor if no such entity can be found. 1138 */ 1139CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation); 1140 1141/** 1142 * \brief Retrieve the physical location of the source constructor referenced 1143 * by the given cursor. 1144 * 1145 * The location of a declaration is typically the location of the name of that 1146 * declaration, where the name of that declaration would occur if it is 1147 * unnamed, or some keyword that introduces that particular declaration. 1148 * The location of a reference is where that reference occurs within the 1149 * source code. 1150 */ 1151CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor); 1152 1153/** 1154 * \brief Retrieve the physical extent of the source construct referenced by 1155 * the given cursor. 1156 * 1157 * The extent of a cursor starts with the file/line/column pointing at the 1158 * first character within the source construct that the cursor refers to and 1159 * ends with the last character withinin that source construct. For a 1160 * declaration, the extent covers the declaration itself. For a reference, 1161 * the extent covers the location of the reference (e.g., where the referenced 1162 * entity was actually used). 1163 */ 1164CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor); 1165 1166/** 1167 * @} 1168 */ 1169 1170/** 1171 * \defgroup CINDEX_TYPES Type information for CXCursors 1172 * 1173 * @{ 1174 */ 1175 1176/** 1177 * \brief Describes the kind of type 1178 */ 1179enum CXTypeKind { 1180 /** 1181 * \brief Reprents an invalid type (e.g., where no type is available). 1182 */ 1183 CXType_Invalid = 0, 1184 1185 /** 1186 * \brief A type whose specific kind is not exposed via this 1187 * interface. 1188 */ 1189 CXType_Unexposed = 1, 1190 1191 /* Builtin types */ 1192 CXType_Void = 2, 1193 CXType_Bool = 3, 1194 CXType_Char_U = 4, 1195 CXType_UChar = 5, 1196 CXType_Char16 = 6, 1197 CXType_Char32 = 7, 1198 CXType_UShort = 8, 1199 CXType_UInt = 9, 1200 CXType_ULong = 10, 1201 CXType_ULongLong = 11, 1202 CXType_UInt128 = 12, 1203 CXType_Char_S = 13, 1204 CXType_SChar = 14, 1205 CXType_WChar = 15, 1206 CXType_Short = 16, 1207 CXType_Int = 17, 1208 CXType_Long = 18, 1209 CXType_LongLong = 19, 1210 CXType_Int128 = 20, 1211 CXType_Float = 21, 1212 CXType_Double = 22, 1213 CXType_LongDouble = 23, 1214 CXType_NullPtr = 24, 1215 CXType_Overload = 25, 1216 CXType_Dependent = 26, 1217 CXType_ObjCId = 27, 1218 CXType_ObjCClass = 28, 1219 CXType_ObjCSel = 29, 1220 CXType_FirstBuiltin = CXType_Void, 1221 CXType_LastBuiltin = CXType_ObjCSel, 1222 1223 CXType_Complex = 100, 1224 CXType_Pointer = 101, 1225 CXType_BlockPointer = 102, 1226 CXType_LValueReference = 103, 1227 CXType_RValueReference = 104, 1228 CXType_Record = 105, 1229 CXType_Enum = 106, 1230 CXType_Typedef = 107, 1231 CXType_ObjCInterface = 108, 1232 CXType_ObjCObjectPointer = 109, 1233 CXType_FunctionNoProto = 110, 1234 CXType_FunctionProto = 111 1235}; 1236 1237/** 1238 * \brief The type of an element in the abstract syntax tree. 1239 * 1240 */ 1241typedef struct { 1242 enum CXTypeKind kind; 1243 void *data[2]; 1244} CXType; 1245 1246/** 1247 * \brief Retrieve the type of a CXCursor (if any). 1248 */ 1249CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C); 1250 1251/** 1252 * \determine Determine whether two CXTypes represent the same type. 1253 * 1254 * \returns non-zero if the CXTypes represent the same type and 1255 zero otherwise. 1256 */ 1257CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B); 1258 1259/** 1260 * \brief Return the canonical type for a CXType. 1261 * 1262 * Clang's type system explicitly models typedefs and all the ways 1263 * a specific type can be represented. The canonical type is the underlying 1264 * type with all the "sugar" removed. For example, if 'T' is a typedef 1265 * for 'int', the canonical type for 'T' would be 'int'. 1266 */ 1267CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T); 1268 1269/** 1270 * \brief For pointer types, returns the type of the pointee. 1271 * 1272 */ 1273CINDEX_LINKAGE CXType clang_getPointeeType(CXType T); 1274 1275/** 1276 * \brief Return the cursor for the declaration of the given type. 1277 */ 1278CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T); 1279 1280 1281/** 1282 * \brief Retrieve the spelling of a given CXTypeKind. 1283 */ 1284CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K); 1285 1286/** 1287 * \brief Retrieve the result type associated with a function type. 1288 */ 1289CINDEX_LINKAGE CXType clang_getResultType(CXType T); 1290 1291/** 1292 * \brief Retrieve the result type associated with a given cursor. This only 1293 * returns a valid type of the cursor refers to a function or method. 1294 */ 1295CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C); 1296 1297/** 1298 * @} 1299 */ 1300 1301/** 1302 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors 1303 * 1304 * These routines provide the ability to traverse the abstract syntax tree 1305 * using cursors. 1306 * 1307 * @{ 1308 */ 1309 1310/** 1311 * \brief Describes how the traversal of the children of a particular 1312 * cursor should proceed after visiting a particular child cursor. 1313 * 1314 * A value of this enumeration type should be returned by each 1315 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed. 1316 */ 1317enum CXChildVisitResult { 1318 /** 1319 * \brief Terminates the cursor traversal. 1320 */ 1321 CXChildVisit_Break, 1322 /** 1323 * \brief Continues the cursor traversal with the next sibling of 1324 * the cursor just visited, without visiting its children. 1325 */ 1326 CXChildVisit_Continue, 1327 /** 1328 * \brief Recursively traverse the children of this cursor, using 1329 * the same visitor and client data. 1330 */ 1331 CXChildVisit_Recurse 1332}; 1333 1334/** 1335 * \brief Visitor invoked for each cursor found by a traversal. 1336 * 1337 * This visitor function will be invoked for each cursor found by 1338 * clang_visitCursorChildren(). Its first argument is the cursor being 1339 * visited, its second argument is the parent visitor for that cursor, 1340 * and its third argument is the client data provided to 1341 * clang_visitCursorChildren(). 1342 * 1343 * The visitor should return one of the \c CXChildVisitResult values 1344 * to direct clang_visitCursorChildren(). 1345 */ 1346typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor, 1347 CXCursor parent, 1348 CXClientData client_data); 1349 1350/** 1351 * \brief Visit the children of a particular cursor. 1352 * 1353 * This function visits all the direct children of the given cursor, 1354 * invoking the given \p visitor function with the cursors of each 1355 * visited child. The traversal may be recursive, if the visitor returns 1356 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if 1357 * the visitor returns \c CXChildVisit_Break. 1358 * 1359 * \param parent the cursor whose child may be visited. All kinds of 1360 * cursors can be visited, including invalid cursors (which, by 1361 * definition, have no children). 1362 * 1363 * \param visitor the visitor function that will be invoked for each 1364 * child of \p parent. 1365 * 1366 * \param client_data pointer data supplied by the client, which will 1367 * be passed to the visitor each time it is invoked. 1368 * 1369 * \returns a non-zero value if the traversal was terminated 1370 * prematurely by the visitor returning \c CXChildVisit_Break. 1371 */ 1372CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent, 1373 CXCursorVisitor visitor, 1374 CXClientData client_data); 1375 1376/** 1377 * @} 1378 */ 1379 1380/** 1381 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST 1382 * 1383 * These routines provide the ability to determine references within and 1384 * across translation units, by providing the names of the entities referenced 1385 * by cursors, follow reference cursors to the declarations they reference, 1386 * and associate declarations with their definitions. 1387 * 1388 * @{ 1389 */ 1390 1391/** 1392 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced 1393 * by the given cursor. 1394 * 1395 * A Unified Symbol Resolution (USR) is a string that identifies a particular 1396 * entity (function, class, variable, etc.) within a program. USRs can be 1397 * compared across translation units to determine, e.g., when references in 1398 * one translation refer to an entity defined in another translation unit. 1399 */ 1400CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor); 1401 1402/** 1403 * \brief Construct a USR for a specified Objective-C class. 1404 */ 1405CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name); 1406 1407/** 1408 * \brief Construct a USR for a specified Objective-C category. 1409 */ 1410CINDEX_LINKAGE CXString 1411 clang_constructUSR_ObjCCategory(const char *class_name, 1412 const char *category_name); 1413 1414/** 1415 * \brief Construct a USR for a specified Objective-C protocol. 1416 */ 1417CINDEX_LINKAGE CXString 1418 clang_constructUSR_ObjCProtocol(const char *protocol_name); 1419 1420 1421/** 1422 * \brief Construct a USR for a specified Objective-C instance variable and 1423 * the USR for its containing class. 1424 */ 1425CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name, 1426 CXString classUSR); 1427 1428/** 1429 * \brief Construct a USR for a specified Objective-C method and 1430 * the USR for its containing class. 1431 */ 1432CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name, 1433 unsigned isInstanceMethod, 1434 CXString classUSR); 1435 1436/** 1437 * \brief Construct a USR for a specified Objective-C property and the USR 1438 * for its containing class. 1439 */ 1440CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property, 1441 CXString classUSR); 1442 1443/** 1444 * \brief Retrieve a name for the entity referenced by this cursor. 1445 */ 1446CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor); 1447 1448/** \brief For a cursor that is a reference, retrieve a cursor representing the 1449 * entity that it references. 1450 * 1451 * Reference cursors refer to other entities in the AST. For example, an 1452 * Objective-C superclass reference cursor refers to an Objective-C class. 1453 * This function produces the cursor for the Objective-C class from the 1454 * cursor for the superclass reference. If the input cursor is a declaration or 1455 * definition, it returns that declaration or definition unchanged. 1456 * Otherwise, returns the NULL cursor. 1457 */ 1458CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor); 1459 1460/** 1461 * \brief For a cursor that is either a reference to or a declaration 1462 * of some entity, retrieve a cursor that describes the definition of 1463 * that entity. 1464 * 1465 * Some entities can be declared multiple times within a translation 1466 * unit, but only one of those declarations can also be a 1467 * definition. For example, given: 1468 * 1469 * \code 1470 * int f(int, int); 1471 * int g(int x, int y) { return f(x, y); } 1472 * int f(int a, int b) { return a + b; } 1473 * int f(int, int); 1474 * \endcode 1475 * 1476 * there are three declarations of the function "f", but only the 1477 * second one is a definition. The clang_getCursorDefinition() 1478 * function will take any cursor pointing to a declaration of "f" 1479 * (the first or fourth lines of the example) or a cursor referenced 1480 * that uses "f" (the call to "f' inside "g") and will return a 1481 * declaration cursor pointing to the definition (the second "f" 1482 * declaration). 1483 * 1484 * If given a cursor for which there is no corresponding definition, 1485 * e.g., because there is no definition of that entity within this 1486 * translation unit, returns a NULL cursor. 1487 */ 1488CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor); 1489 1490/** 1491 * \brief Determine whether the declaration pointed to by this cursor 1492 * is also a definition of that entity. 1493 */ 1494CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor); 1495 1496/** 1497 * @} 1498 */ 1499 1500/** 1501 * \defgroup CINDEX_CPP C++ AST introspection 1502 * 1503 * The routines in this group provide access information in the ASTs specific 1504 * to C++ language features. 1505 * 1506 * @{ 1507 */ 1508 1509/** 1510 * \brief Determine if a C++ member function is declared 'static'. 1511 */ 1512CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C); 1513 1514/** 1515 * @} 1516 */ 1517 1518/** 1519 * \defgroup CINDEX_LEX Token extraction and manipulation 1520 * 1521 * The routines in this group provide access to the tokens within a 1522 * translation unit, along with a semantic mapping of those tokens to 1523 * their corresponding cursors. 1524 * 1525 * @{ 1526 */ 1527 1528/** 1529 * \brief Describes a kind of token. 1530 */ 1531typedef enum CXTokenKind { 1532 /** 1533 * \brief A token that contains some kind of punctuation. 1534 */ 1535 CXToken_Punctuation, 1536 1537 /** 1538 * \brief A language keyword. 1539 */ 1540 CXToken_Keyword, 1541 1542 /** 1543 * \brief An identifier (that is not a keyword). 1544 */ 1545 CXToken_Identifier, 1546 1547 /** 1548 * \brief A numeric, string, or character literal. 1549 */ 1550 CXToken_Literal, 1551 1552 /** 1553 * \brief A comment. 1554 */ 1555 CXToken_Comment 1556} CXTokenKind; 1557 1558/** 1559 * \brief Describes a single preprocessing token. 1560 */ 1561typedef struct { 1562 unsigned int_data[4]; 1563 void *ptr_data; 1564} CXToken; 1565 1566/** 1567 * \brief Determine the kind of the given token. 1568 */ 1569CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken); 1570 1571/** 1572 * \brief Determine the spelling of the given token. 1573 * 1574 * The spelling of a token is the textual representation of that token, e.g., 1575 * the text of an identifier or keyword. 1576 */ 1577CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken); 1578 1579/** 1580 * \brief Retrieve the source location of the given token. 1581 */ 1582CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit, 1583 CXToken); 1584 1585/** 1586 * \brief Retrieve a source range that covers the given token. 1587 */ 1588CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken); 1589 1590/** 1591 * \brief Tokenize the source code described by the given range into raw 1592 * lexical tokens. 1593 * 1594 * \param TU the translation unit whose text is being tokenized. 1595 * 1596 * \param Range the source range in which text should be tokenized. All of the 1597 * tokens produced by tokenization will fall within this source range, 1598 * 1599 * \param Tokens this pointer will be set to point to the array of tokens 1600 * that occur within the given source range. The returned pointer must be 1601 * freed with clang_disposeTokens() before the translation unit is destroyed. 1602 * 1603 * \param NumTokens will be set to the number of tokens in the \c *Tokens 1604 * array. 1605 * 1606 */ 1607CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range, 1608 CXToken **Tokens, unsigned *NumTokens); 1609 1610/** 1611 * \brief Annotate the given set of tokens by providing cursors for each token 1612 * that can be mapped to a specific entity within the abstract syntax tree. 1613 * 1614 * This token-annotation routine is equivalent to invoking 1615 * clang_getCursor() for the source locations of each of the 1616 * tokens. The cursors provided are filtered, so that only those 1617 * cursors that have a direct correspondence to the token are 1618 * accepted. For example, given a function call \c f(x), 1619 * clang_getCursor() would provide the following cursors: 1620 * 1621 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'. 1622 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'. 1623 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'. 1624 * 1625 * Only the first and last of these cursors will occur within the 1626 * annotate, since the tokens "f" and "x' directly refer to a function 1627 * and a variable, respectively, but the parentheses are just a small 1628 * part of the full syntax of the function call expression, which is 1629 * not provided as an annotation. 1630 * 1631 * \param TU the translation unit that owns the given tokens. 1632 * 1633 * \param Tokens the set of tokens to annotate. 1634 * 1635 * \param NumTokens the number of tokens in \p Tokens. 1636 * 1637 * \param Cursors an array of \p NumTokens cursors, whose contents will be 1638 * replaced with the cursors corresponding to each token. 1639 */ 1640CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU, 1641 CXToken *Tokens, unsigned NumTokens, 1642 CXCursor *Cursors); 1643 1644/** 1645 * \brief Free the given set of tokens. 1646 */ 1647CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU, 1648 CXToken *Tokens, unsigned NumTokens); 1649 1650/** 1651 * @} 1652 */ 1653 1654/** 1655 * \defgroup CINDEX_DEBUG Debugging facilities 1656 * 1657 * These routines are used for testing and debugging, only, and should not 1658 * be relied upon. 1659 * 1660 * @{ 1661 */ 1662 1663/* for debug/testing */ 1664CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind); 1665CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor, 1666 const char **startBuf, 1667 const char **endBuf, 1668 unsigned *startLine, 1669 unsigned *startColumn, 1670 unsigned *endLine, 1671 unsigned *endColumn); 1672CINDEX_LINKAGE void clang_enableStackTraces(void); 1673/** 1674 * @} 1675 */ 1676 1677/** 1678 * \defgroup CINDEX_CODE_COMPLET Code completion 1679 * 1680 * Code completion involves taking an (incomplete) source file, along with 1681 * knowledge of where the user is actively editing that file, and suggesting 1682 * syntactically- and semantically-valid constructs that the user might want to 1683 * use at that particular point in the source code. These data structures and 1684 * routines provide support for code completion. 1685 * 1686 * @{ 1687 */ 1688 1689/** 1690 * \brief A semantic string that describes a code-completion result. 1691 * 1692 * A semantic string that describes the formatting of a code-completion 1693 * result as a single "template" of text that should be inserted into the 1694 * source buffer when a particular code-completion result is selected. 1695 * Each semantic string is made up of some number of "chunks", each of which 1696 * contains some text along with a description of what that text means, e.g., 1697 * the name of the entity being referenced, whether the text chunk is part of 1698 * the template, or whether it is a "placeholder" that the user should replace 1699 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a 1700 * description of the different kinds of chunks. 1701 */ 1702typedef void *CXCompletionString; 1703 1704/** 1705 * \brief A single result of code completion. 1706 */ 1707typedef struct { 1708 /** 1709 * \brief The kind of entity that this completion refers to. 1710 * 1711 * The cursor kind will be a macro, keyword, or a declaration (one of the 1712 * *Decl cursor kinds), describing the entity that the completion is 1713 * referring to. 1714 * 1715 * \todo In the future, we would like to provide a full cursor, to allow 1716 * the client to extract additional information from declaration. 1717 */ 1718 enum CXCursorKind CursorKind; 1719 1720 /** 1721 * \brief The code-completion string that describes how to insert this 1722 * code-completion result into the editing buffer. 1723 */ 1724 CXCompletionString CompletionString; 1725} CXCompletionResult; 1726 1727/** 1728 * \brief Describes a single piece of text within a code-completion string. 1729 * 1730 * Each "chunk" within a code-completion string (\c CXCompletionString) is 1731 * either a piece of text with a specific "kind" that describes how that text 1732 * should be interpreted by the client or is another completion string. 1733 */ 1734enum CXCompletionChunkKind { 1735 /** 1736 * \brief A code-completion string that describes "optional" text that 1737 * could be a part of the template (but is not required). 1738 * 1739 * The Optional chunk is the only kind of chunk that has a code-completion 1740 * string for its representation, which is accessible via 1741 * \c clang_getCompletionChunkCompletionString(). The code-completion string 1742 * describes an additional part of the template that is completely optional. 1743 * For example, optional chunks can be used to describe the placeholders for 1744 * arguments that match up with defaulted function parameters, e.g. given: 1745 * 1746 * \code 1747 * void f(int x, float y = 3.14, double z = 2.71828); 1748 * \endcode 1749 * 1750 * The code-completion string for this function would contain: 1751 * - a TypedText chunk for "f". 1752 * - a LeftParen chunk for "(". 1753 * - a Placeholder chunk for "int x" 1754 * - an Optional chunk containing the remaining defaulted arguments, e.g., 1755 * - a Comma chunk for "," 1756 * - a Placeholder chunk for "float y" 1757 * - an Optional chunk containing the last defaulted argument: 1758 * - a Comma chunk for "," 1759 * - a Placeholder chunk for "double z" 1760 * - a RightParen chunk for ")" 1761 * 1762 * There are many ways to handle Optional chunks. Two simple approaches are: 1763 * - Completely ignore optional chunks, in which case the template for the 1764 * function "f" would only include the first parameter ("int x"). 1765 * - Fully expand all optional chunks, in which case the template for the 1766 * function "f" would have all of the parameters. 1767 */ 1768 CXCompletionChunk_Optional, 1769 /** 1770 * \brief Text that a user would be expected to type to get this 1771 * code-completion result. 1772 * 1773 * There will be exactly one "typed text" chunk in a semantic string, which 1774 * will typically provide the spelling of a keyword or the name of a 1775 * declaration that could be used at the current code point. Clients are 1776 * expected to filter the code-completion results based on the text in this 1777 * chunk. 1778 */ 1779 CXCompletionChunk_TypedText, 1780 /** 1781 * \brief Text that should be inserted as part of a code-completion result. 1782 * 1783 * A "text" chunk represents text that is part of the template to be 1784 * inserted into user code should this particular code-completion result 1785 * be selected. 1786 */ 1787 CXCompletionChunk_Text, 1788 /** 1789 * \brief Placeholder text that should be replaced by the user. 1790 * 1791 * A "placeholder" chunk marks a place where the user should insert text 1792 * into the code-completion template. For example, placeholders might mark 1793 * the function parameters for a function declaration, to indicate that the 1794 * user should provide arguments for each of those parameters. The actual 1795 * text in a placeholder is a suggestion for the text to display before 1796 * the user replaces the placeholder with real code. 1797 */ 1798 CXCompletionChunk_Placeholder, 1799 /** 1800 * \brief Informative text that should be displayed but never inserted as 1801 * part of the template. 1802 * 1803 * An "informative" chunk contains annotations that can be displayed to 1804 * help the user decide whether a particular code-completion result is the 1805 * right option, but which is not part of the actual template to be inserted 1806 * by code completion. 1807 */ 1808 CXCompletionChunk_Informative, 1809 /** 1810 * \brief Text that describes the current parameter when code-completion is 1811 * referring to function call, message send, or template specialization. 1812 * 1813 * A "current parameter" chunk occurs when code-completion is providing 1814 * information about a parameter corresponding to the argument at the 1815 * code-completion point. For example, given a function 1816 * 1817 * \code 1818 * int add(int x, int y); 1819 * \endcode 1820 * 1821 * and the source code \c add(, where the code-completion point is after the 1822 * "(", the code-completion string will contain a "current parameter" chunk 1823 * for "int x", indicating that the current argument will initialize that 1824 * parameter. After typing further, to \c add(17, (where the code-completion 1825 * point is after the ","), the code-completion string will contain a 1826 * "current paremeter" chunk to "int y". 1827 */ 1828 CXCompletionChunk_CurrentParameter, 1829 /** 1830 * \brief A left parenthesis ('('), used to initiate a function call or 1831 * signal the beginning of a function parameter list. 1832 */ 1833 CXCompletionChunk_LeftParen, 1834 /** 1835 * \brief A right parenthesis (')'), used to finish a function call or 1836 * signal the end of a function parameter list. 1837 */ 1838 CXCompletionChunk_RightParen, 1839 /** 1840 * \brief A left bracket ('['). 1841 */ 1842 CXCompletionChunk_LeftBracket, 1843 /** 1844 * \brief A right bracket (']'). 1845 */ 1846 CXCompletionChunk_RightBracket, 1847 /** 1848 * \brief A left brace ('{'). 1849 */ 1850 CXCompletionChunk_LeftBrace, 1851 /** 1852 * \brief A right brace ('}'). 1853 */ 1854 CXCompletionChunk_RightBrace, 1855 /** 1856 * \brief A left angle bracket ('<'). 1857 */ 1858 CXCompletionChunk_LeftAngle, 1859 /** 1860 * \brief A right angle bracket ('>'). 1861 */ 1862 CXCompletionChunk_RightAngle, 1863 /** 1864 * \brief A comma separator (','). 1865 */ 1866 CXCompletionChunk_Comma, 1867 /** 1868 * \brief Text that specifies the result type of a given result. 1869 * 1870 * This special kind of informative chunk is not meant to be inserted into 1871 * the text buffer. Rather, it is meant to illustrate the type that an 1872 * expression using the given completion string would have. 1873 */ 1874 CXCompletionChunk_ResultType, 1875 /** 1876 * \brief A colon (':'). 1877 */ 1878 CXCompletionChunk_Colon, 1879 /** 1880 * \brief A semicolon (';'). 1881 */ 1882 CXCompletionChunk_SemiColon, 1883 /** 1884 * \brief An '=' sign. 1885 */ 1886 CXCompletionChunk_Equal, 1887 /** 1888 * Horizontal space (' '). 1889 */ 1890 CXCompletionChunk_HorizontalSpace, 1891 /** 1892 * Vertical space ('\n'), after which it is generally a good idea to 1893 * perform indentation. 1894 */ 1895 CXCompletionChunk_VerticalSpace 1896}; 1897 1898/** 1899 * \brief Determine the kind of a particular chunk within a completion string. 1900 * 1901 * \param completion_string the completion string to query. 1902 * 1903 * \param chunk_number the 0-based index of the chunk in the completion string. 1904 * 1905 * \returns the kind of the chunk at the index \c chunk_number. 1906 */ 1907CINDEX_LINKAGE enum CXCompletionChunkKind 1908clang_getCompletionChunkKind(CXCompletionString completion_string, 1909 unsigned chunk_number); 1910 1911/** 1912 * \brief Retrieve the text associated with a particular chunk within a 1913 * completion string. 1914 * 1915 * \param completion_string the completion string to query. 1916 * 1917 * \param chunk_number the 0-based index of the chunk in the completion string. 1918 * 1919 * \returns the text associated with the chunk at index \c chunk_number. 1920 */ 1921CINDEX_LINKAGE CXString 1922clang_getCompletionChunkText(CXCompletionString completion_string, 1923 unsigned chunk_number); 1924 1925/** 1926 * \brief Retrieve the completion string associated with a particular chunk 1927 * within a completion string. 1928 * 1929 * \param completion_string the completion string to query. 1930 * 1931 * \param chunk_number the 0-based index of the chunk in the completion string. 1932 * 1933 * \returns the completion string associated with the chunk at index 1934 * \c chunk_number, or NULL if that chunk is not represented by a completion 1935 * string. 1936 */ 1937CINDEX_LINKAGE CXCompletionString 1938clang_getCompletionChunkCompletionString(CXCompletionString completion_string, 1939 unsigned chunk_number); 1940 1941/** 1942 * \brief Retrieve the number of chunks in the given code-completion string. 1943 */ 1944CINDEX_LINKAGE unsigned 1945clang_getNumCompletionChunks(CXCompletionString completion_string); 1946 1947/** 1948 * \brief Determine the priority of this code completion. 1949 * 1950 * The priority of a code completion indicates how likely it is that this 1951 * particular completion is the completion that the user will select. The 1952 * priority is selected by various internal heuristics. 1953 * 1954 * \param completion_string The completion string to query. 1955 * 1956 * \returns The priority of this completion string. Smaller values indicate 1957 * higher-priority (more likely) completions. 1958 */ 1959CINDEX_LINKAGE unsigned 1960clang_getCompletionPriority(CXCompletionString completion_string); 1961 1962/** 1963 * \brief Contains the results of code-completion. 1964 * 1965 * This data structure contains the results of code completion, as 1966 * produced by \c clang_codeComplete. Its contents must be freed by 1967 * \c clang_disposeCodeCompleteResults. 1968 */ 1969typedef struct { 1970 /** 1971 * \brief The code-completion results. 1972 */ 1973 CXCompletionResult *Results; 1974 1975 /** 1976 * \brief The number of code-completion results stored in the 1977 * \c Results array. 1978 */ 1979 unsigned NumResults; 1980} CXCodeCompleteResults; 1981 1982/** 1983 * \brief Perform code completion at a given location in a source file. 1984 * 1985 * This function performs code completion at a particular file, line, and 1986 * column within source code, providing results that suggest potential 1987 * code snippets based on the context of the completion. The basic model 1988 * for code completion is that Clang will parse a complete source file, 1989 * performing syntax checking up to the location where code-completion has 1990 * been requested. At that point, a special code-completion token is passed 1991 * to the parser, which recognizes this token and determines, based on the 1992 * current location in the C/Objective-C/C++ grammar and the state of 1993 * semantic analysis, what completions to provide. These completions are 1994 * returned via a new \c CXCodeCompleteResults structure. 1995 * 1996 * Code completion itself is meant to be triggered by the client when the 1997 * user types punctuation characters or whitespace, at which point the 1998 * code-completion location will coincide with the cursor. For example, if \c p 1999 * is a pointer, code-completion might be triggered after the "-" and then 2000 * after the ">" in \c p->. When the code-completion location is afer the ">", 2001 * the completion results will provide, e.g., the members of the struct that 2002 * "p" points to. The client is responsible for placing the cursor at the 2003 * beginning of the token currently being typed, then filtering the results 2004 * based on the contents of the token. For example, when code-completing for 2005 * the expression \c p->get, the client should provide the location just after 2006 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the 2007 * client can filter the results based on the current token text ("get"), only 2008 * showing those results that start with "get". The intent of this interface 2009 * is to separate the relatively high-latency acquisition of code-completion 2010 * results from the filtering of results on a per-character basis, which must 2011 * have a lower latency. 2012 * 2013 * \param CIdx the \c CXIndex instance that will be used to perform code 2014 * completion. 2015 * 2016 * \param source_filename the name of the source file that should be parsed to 2017 * perform code-completion. This source file must be the same as or include the 2018 * filename described by \p complete_filename, or no code-completion results 2019 * will be produced. NOTE: One can also specify NULL for this argument if the 2020 * source file is included in command_line_args. 2021 * 2022 * \param num_command_line_args the number of command-line arguments stored in 2023 * \p command_line_args. 2024 * 2025 * \param command_line_args the command-line arguments to pass to the Clang 2026 * compiler to build the given source file. This should include all of the 2027 * necessary include paths, language-dialect switches, precompiled header 2028 * includes, etc., but should not include any information specific to 2029 * code completion. 2030 * 2031 * \param num_unsaved_files the number of unsaved file entries in \p 2032 * unsaved_files. 2033 * 2034 * \param unsaved_files the files that have not yet been saved to disk 2035 * but may be required for code completion, including the contents of 2036 * those files. The contents and name of these files (as specified by 2037 * CXUnsavedFile) are copied when necessary, so the client only needs to 2038 * guarantee their validity until the call to this function returns. 2039 * 2040 * \param complete_filename the name of the source file where code completion 2041 * should be performed. In many cases, this name will be the same as the 2042 * source filename. However, the completion filename may also be a file 2043 * included by the source file, which is required when producing 2044 * code-completion results for a header. 2045 * 2046 * \param complete_line the line at which code-completion should occur. 2047 * 2048 * \param complete_column the column at which code-completion should occur. 2049 * Note that the column should point just after the syntactic construct that 2050 * initiated code completion, and not in the middle of a lexical token. 2051 * 2052 * \param diag_callback callback function that will receive any diagnostics 2053 * emitted while processing this source file. If NULL, diagnostics will be 2054 * suppressed. 2055 * 2056 * \param diag_client_data client data that will be passed to the diagnostic 2057 * callback function. 2058 * 2059 * \returns if successful, a new CXCodeCompleteResults structure 2060 * containing code-completion results, which should eventually be 2061 * freed with \c clang_disposeCodeCompleteResults(). If code 2062 * completion fails, returns NULL. 2063 */ 2064CINDEX_LINKAGE 2065CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx, 2066 const char *source_filename, 2067 int num_command_line_args, 2068 const char **command_line_args, 2069 unsigned num_unsaved_files, 2070 struct CXUnsavedFile *unsaved_files, 2071 const char *complete_filename, 2072 unsigned complete_line, 2073 unsigned complete_column); 2074 2075/** 2076 * \brief Free the given set of code-completion results. 2077 */ 2078CINDEX_LINKAGE 2079void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results); 2080 2081/** 2082 * \brief Determine the number of diagnostics produced prior to the 2083 * location where code completion was performed. 2084 */ 2085CINDEX_LINKAGE 2086unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results); 2087 2088/** 2089 * \brief Retrieve a diagnostic associated with the given code completion. 2090 * 2091 * \param Result the code completion results to query. 2092 * \param Index the zero-based diagnostic number to retrieve. 2093 * 2094 * \returns the requested diagnostic. This diagnostic must be freed 2095 * via a call to \c clang_disposeDiagnostic(). 2096 */ 2097CINDEX_LINKAGE 2098CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results, 2099 unsigned Index); 2100 2101/** 2102 * @} 2103 */ 2104 2105 2106/** 2107 * \defgroup CINDEX_MISC Miscellaneous utility functions 2108 * 2109 * @{ 2110 */ 2111 2112/** 2113 * \brief Return a version string, suitable for showing to a user, but not 2114 * intended to be parsed (the format is not guaranteed to be stable). 2115 */ 2116CINDEX_LINKAGE CXString clang_getClangVersion(); 2117 2118/** 2119 * \brief Return a version string, suitable for showing to a user, but not 2120 * intended to be parsed (the format is not guaranteed to be stable). 2121 */ 2122 2123 2124 /** 2125 * \brief Visitor invoked for each file in a translation unit 2126 * (used with clang_getInclusions()). 2127 * 2128 * This visitor function will be invoked by clang_getInclusions() for each 2129 * file included (either at the top-level or by #include directives) within 2130 * a translation unit. The first argument is the file being included, and 2131 * the second and third arguments provide the inclusion stack. The 2132 * array is sorted in order of immediate inclusion. For example, 2133 * the first element refers to the location that included 'included_file'. 2134 */ 2135typedef void (*CXInclusionVisitor)(CXFile included_file, 2136 CXSourceLocation* inclusion_stack, 2137 unsigned include_len, 2138 CXClientData client_data); 2139 2140/** 2141 * \brief Visit the set of preprocessor inclusions in a translation unit. 2142 * The visitor function is called with the provided data for every included 2143 * file. This does not include headers included by the PCH file (unless one 2144 * is inspecting the inclusions in the PCH file itself). 2145 */ 2146CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu, 2147 CXInclusionVisitor visitor, 2148 CXClientData client_data); 2149 2150/** 2151 * @} 2152 */ 2153 2154/** 2155 * @} 2156 */ 2157 2158#ifdef __cplusplus 2159} 2160#endif 2161#endif 2162 2163