1 /*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
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 *|
14 \*===----------------------------------------------------------------------===*/
16 #ifndef CLANG_C_INDEX_H
17 #define CLANG_C_INDEX_H
23 #include "clang-c/Platform.h"
24 #include "clang-c/CXString.h"
27 * \brief The version constants for the libclang API.
28 * CINDEX_VERSION_MINOR should increase when there are API additions.
29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
31 * The policy about the libclang API was always to keep it source and ABI
32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
34 #define CINDEX_VERSION_MAJOR 0
35 #define CINDEX_VERSION_MINOR 6
37 #define CINDEX_VERSION_ENCODE(major, minor) ( \
41 #define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
42 CINDEX_VERSION_MAJOR, \
43 CINDEX_VERSION_MINOR )
45 #define CINDEX_VERSION_STRINGIZE_(major, minor) \
47 #define CINDEX_VERSION_STRINGIZE(major, minor) \
48 CINDEX_VERSION_STRINGIZE_(major, minor)
50 #define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
51 CINDEX_VERSION_MAJOR, \
58 /** \defgroup CINDEX libclang: C Interface to Clang
60 * The C Interface to Clang provides a relatively small API that exposes
61 * facilities for parsing source code into an abstract syntax tree (AST),
62 * loading already-parsed ASTs, traversing the AST, associating
63 * physical source locations with elements within the AST, and other
64 * facilities that support Clang-based development tools.
66 * This C interface to Clang will never provide all of the information
67 * representation stored in Clang's C++ AST, nor should it: the intent is to
68 * maintain an API that is relatively stable from one release to the next,
69 * providing only the basic functionality needed to support development tools.
71 * To avoid namespace pollution, data types are prefixed with "CX" and
72 * functions are prefixed with "clang_".
78 * \brief An "index" that consists of a set of translation units that would
79 * typically be linked together into an executable or library.
81 typedef void *CXIndex;
84 * \brief A single translation unit, which resides in an index.
86 typedef struct CXTranslationUnitImpl *CXTranslationUnit;
89 * \brief Opaque pointer representing client data that will be passed through
90 * to various callbacks and visitors.
92 typedef void *CXClientData;
95 * \brief Provides the contents of a file that has not yet been saved to disk.
97 * Each CXUnsavedFile instance provides the name of a file on the
98 * system along with the current contents of that file that have not
99 * yet been saved to disk.
101 struct CXUnsavedFile {
103 * \brief The file whose contents have not yet been saved.
105 * This file must already exist in the file system.
107 const char *Filename;
110 * \brief A buffer containing the unsaved contents of this file.
112 const char *Contents;
115 * \brief The length of the unsaved contents of this buffer.
117 unsigned long Length;
121 * \brief Describes the availability of a particular entity, which indicates
122 * whether the use of this entity will result in a warning or error due to
123 * it being deprecated or unavailable.
125 enum CXAvailabilityKind {
127 * \brief The entity is available.
129 CXAvailability_Available,
131 * \brief The entity is available, but has been deprecated (and its use is
134 CXAvailability_Deprecated,
136 * \brief The entity is not available; any use of it will be an error.
138 CXAvailability_NotAvailable,
140 * \brief The entity is available, but not accessible; any use of it will be
143 CXAvailability_NotAccessible
147 * \brief Describes a version number of the form major.minor.subminor.
149 typedef struct CXVersion {
151 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
152 * value indicates that there is no version number at all.
156 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
157 * will be negative if no minor version number was provided, e.g., for
162 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
163 * will be negative if no minor or subminor version number was provided,
164 * e.g., in version '10' or '10.7'.
170 * \brief Provides a shared context for creating translation units.
172 * It provides two options:
174 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
175 * declarations (when loading any new translation units). A "local" declaration
176 * is one that belongs in the translation unit itself and not in a precompiled
177 * header that was used by the translation unit. If zero, all declarations
178 * will be enumerated.
180 * Here is an example:
183 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
184 * Idx = clang_createIndex(1, 1);
186 * // IndexTest.pch was produced with the following command:
187 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
188 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
190 * // This will load all the symbols from 'IndexTest.pch'
191 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
192 * TranslationUnitVisitor, 0);
193 * clang_disposeTranslationUnit(TU);
195 * // This will load all the symbols from 'IndexTest.c', excluding symbols
196 * // from 'IndexTest.pch'.
197 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
198 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
200 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
201 * TranslationUnitVisitor, 0);
202 * clang_disposeTranslationUnit(TU);
205 * This process of creating the 'pch', loading it separately, and using it (via
206 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
207 * (which gives the indexer the same performance benefit as the compiler).
209 CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
210 int displayDiagnostics);
213 * \brief Destroy the given index.
215 * The index must not be destroyed until all of the translation units created
216 * within that index have been destroyed.
218 CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
222 * \brief Used to indicate that no special CXIndex options are needed.
224 CXGlobalOpt_None = 0x0,
227 * \brief Used to indicate that threads that libclang creates for indexing
228 * purposes should use background priority.
230 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
231 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
233 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
236 * \brief Used to indicate that threads that libclang creates for editing
237 * purposes should use background priority.
239 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
240 * #clang_annotateTokens
242 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
245 * \brief Used to indicate that all threads that libclang creates should use
246 * background priority.
248 CXGlobalOpt_ThreadBackgroundPriorityForAll =
249 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
250 CXGlobalOpt_ThreadBackgroundPriorityForEditing
255 * \brief Sets general options associated with a CXIndex.
260 * clang_CXIndex_setGlobalOptions(idx,
261 * clang_CXIndex_getGlobalOptions(idx) |
262 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
265 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
267 CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
270 * \brief Gets the general options associated with a CXIndex.
272 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
273 * are associated with the given CXIndex object.
275 CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
278 * \defgroup CINDEX_FILES File manipulation routines
284 * \brief A particular source file that is part of a translation unit.
286 typedef void *CXFile;
290 * \brief Retrieve the complete file and path name of the given file.
292 CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
295 * \brief Retrieve the last modification time of the given file.
297 CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
300 * \brief Determine whether the given header is guarded against
301 * multiple inclusions, either with the conventional
302 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
304 CINDEX_LINKAGE unsigned
305 clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
308 * \brief Retrieve a file handle within the given translation unit.
310 * \param tu the translation unit
312 * \param file_name the name of the file.
314 * \returns the file handle for the named file in the translation unit \p tu,
315 * or a NULL file handle if the file was not a part of this translation unit.
317 CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
318 const char *file_name);
325 * \defgroup CINDEX_LOCATIONS Physical source locations
327 * Clang represents physical source locations in its abstract syntax tree in
328 * great detail, with file, line, and column information for the majority of
329 * the tokens parsed in the source code. These data types and functions are
330 * used to represent source location information, either for a particular
331 * point in the program or for a range of points in the program, and extract
332 * specific location information from those data types.
338 * \brief Identifies a specific source location within a translation
341 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
342 * to map a source location to a particular file, line, and column.
350 * \brief Identifies a half-open character range in the source code.
352 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
353 * starting and end locations from a source range, respectively.
357 unsigned begin_int_data;
358 unsigned end_int_data;
362 * \brief Retrieve a NULL (invalid) source location.
364 CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
367 * \brief Determine whether two source locations, which must refer into
368 * the same translation unit, refer to exactly the same point in the source
371 * \returns non-zero if the source locations refer to the same location, zero
372 * if they refer to different locations.
374 CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
375 CXSourceLocation loc2);
378 * \brief Retrieves the source location associated with a given file/line/column
379 * in a particular translation unit.
381 CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
386 * \brief Retrieves the source location associated with a given character offset
387 * in a particular translation unit.
389 CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
394 * \brief Retrieve a NULL (invalid) source range.
396 CINDEX_LINKAGE CXSourceRange clang_getNullRange();
399 * \brief Retrieve a source range given the beginning and ending source
402 CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
403 CXSourceLocation end);
406 * \brief Determine whether two ranges are equivalent.
408 * \returns non-zero if the ranges are the same, zero if they differ.
410 CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
411 CXSourceRange range2);
414 * \brief Returns non-zero if \p range is null.
416 CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
419 * \brief Retrieve the file, line, column, and offset represented by
420 * the given source location.
422 * If the location refers into a macro expansion, retrieves the
423 * location of the macro expansion.
425 * \param location the location within a source file that will be decomposed
428 * \param file [out] if non-NULL, will be set to the file to which the given
429 * source location points.
431 * \param line [out] if non-NULL, will be set to the line to which the given
432 * source location points.
434 * \param column [out] if non-NULL, will be set to the column to which the given
435 * source location points.
437 * \param offset [out] if non-NULL, will be set to the offset into the
438 * buffer to which the given source location points.
440 CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
447 * \brief Retrieve the file, line, column, and offset represented by
448 * the given source location, as specified in a # line directive.
450 * Example: given the following source code in a file somefile.c
455 * static int func(void)
461 * the location information returned by this function would be
463 * File: dummy.c Line: 124 Column: 12
465 * whereas clang_getExpansionLocation would have returned
467 * File: somefile.c Line: 3 Column: 12
469 * \param location the location within a source file that will be decomposed
472 * \param filename [out] if non-NULL, will be set to the filename of the
473 * source location. Note that filenames returned will be for "virtual" files,
474 * which don't necessarily exist on the machine running clang - e.g. when
475 * parsing preprocessed output obtained from a different environment. If
476 * a non-NULL value is passed in, remember to dispose of the returned value
477 * using \c clang_disposeString() once you've finished with it. For an invalid
478 * source location, an empty string is returned.
480 * \param line [out] if non-NULL, will be set to the line number of the
481 * source location. For an invalid source location, zero is returned.
483 * \param column [out] if non-NULL, will be set to the column number of the
484 * source location. For an invalid source location, zero is returned.
486 CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
492 * \brief Legacy API to retrieve the file, line, column, and offset represented
493 * by the given source location.
495 * This interface has been replaced by the newer interface
496 * #clang_getExpansionLocation(). See that interface's documentation for
499 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
506 * \brief Retrieve the file, line, column, and offset represented by
507 * the given source location.
509 * If the location refers into a macro instantiation, return where the
510 * location was originally spelled in the source file.
512 * \param location the location within a source file that will be decomposed
515 * \param file [out] if non-NULL, will be set to the file to which the given
516 * source location points.
518 * \param line [out] if non-NULL, will be set to the line to which the given
519 * source location points.
521 * \param column [out] if non-NULL, will be set to the column to which the given
522 * source location points.
524 * \param offset [out] if non-NULL, will be set to the offset into the
525 * buffer to which the given source location points.
527 CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
534 * \brief Retrieve a source location representing the first character within a
537 CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
540 * \brief Retrieve a source location representing the last character within a
543 CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
550 * \defgroup CINDEX_DIAG Diagnostic reporting
556 * \brief Describes the severity of a particular diagnostic.
558 enum CXDiagnosticSeverity {
560 * \brief A diagnostic that has been suppressed, e.g., by a command-line
563 CXDiagnostic_Ignored = 0,
566 * \brief This diagnostic is a note that should be attached to the
567 * previous (non-note) diagnostic.
569 CXDiagnostic_Note = 1,
572 * \brief This diagnostic indicates suspicious code that may not be
575 CXDiagnostic_Warning = 2,
578 * \brief This diagnostic indicates that the code is ill-formed.
580 CXDiagnostic_Error = 3,
583 * \brief This diagnostic indicates that the code is ill-formed such
584 * that future parser recovery is unlikely to produce useful
587 CXDiagnostic_Fatal = 4
591 * \brief A single diagnostic, containing the diagnostic's severity,
592 * location, text, source ranges, and fix-it hints.
594 typedef void *CXDiagnostic;
597 * \brief A group of CXDiagnostics.
599 typedef void *CXDiagnosticSet;
602 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
604 CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
607 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
609 * \param Diags the CXDiagnosticSet to query.
610 * \param Index the zero-based diagnostic number to retrieve.
612 * \returns the requested diagnostic. This diagnostic must be freed
613 * via a call to \c clang_disposeDiagnostic().
615 CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
620 * \brief Describes the kind of error that occurred (if any) in a call to
621 * \c clang_loadDiagnostics.
623 enum CXLoadDiag_Error {
625 * \brief Indicates that no error occurred.
630 * \brief Indicates that an unknown error occurred while attempting to
631 * deserialize diagnostics.
633 CXLoadDiag_Unknown = 1,
636 * \brief Indicates that the file containing the serialized diagnostics
637 * could not be opened.
639 CXLoadDiag_CannotLoad = 2,
642 * \brief Indicates that the serialized diagnostics file is invalid or
645 CXLoadDiag_InvalidFile = 3
649 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
652 * \param file The name of the file to deserialize.
653 * \param error A pointer to a enum value recording if there was a problem
654 * deserializing the diagnostics.
655 * \param errorString A pointer to a CXString for recording the error string
656 * if the file was not successfully loaded.
658 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
659 * diagnostics should be released using clang_disposeDiagnosticSet().
661 CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
662 enum CXLoadDiag_Error *error,
663 CXString *errorString);
666 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
668 CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
671 * \brief Retrieve the child diagnostics of a CXDiagnostic.
673 * This CXDiagnosticSet does not need to be released by
674 * clang_diposeDiagnosticSet.
676 CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
679 * \brief Determine the number of diagnostics produced for the given
682 CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
685 * \brief Retrieve a diagnostic associated with the given translation unit.
687 * \param Unit the translation unit to query.
688 * \param Index the zero-based diagnostic number to retrieve.
690 * \returns the requested diagnostic. This diagnostic must be freed
691 * via a call to \c clang_disposeDiagnostic().
693 CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
697 * \brief Retrieve the complete set of diagnostics associated with a
700 * \param Unit the translation unit to query.
702 CINDEX_LINKAGE CXDiagnosticSet
703 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
706 * \brief Destroy a diagnostic.
708 CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
711 * \brief Options to control the display of diagnostics.
713 * The values in this enum are meant to be combined to customize the
714 * behavior of \c clang_displayDiagnostic().
716 enum CXDiagnosticDisplayOptions {
718 * \brief Display the source-location information where the
719 * diagnostic was located.
721 * When set, diagnostics will be prefixed by the file, line, and
722 * (optionally) column to which the diagnostic refers. For example,
725 * test.c:28: warning: extra tokens at end of #endif directive
728 * This option corresponds to the clang flag \c -fshow-source-location.
730 CXDiagnostic_DisplaySourceLocation = 0x01,
733 * \brief If displaying the source-location information of the
734 * diagnostic, also include the column number.
736 * This option corresponds to the clang flag \c -fshow-column.
738 CXDiagnostic_DisplayColumn = 0x02,
741 * \brief If displaying the source-location information of the
742 * diagnostic, also include information about source ranges in a
743 * machine-parsable format.
745 * This option corresponds to the clang flag
746 * \c -fdiagnostics-print-source-range-info.
748 CXDiagnostic_DisplaySourceRanges = 0x04,
751 * \brief Display the option name associated with this diagnostic, if any.
753 * The option name displayed (e.g., -Wconversion) will be placed in brackets
754 * after the diagnostic text. This option corresponds to the clang flag
755 * \c -fdiagnostics-show-option.
757 CXDiagnostic_DisplayOption = 0x08,
760 * \brief Display the category number associated with this diagnostic, if any.
762 * The category number is displayed within brackets after the diagnostic text.
763 * This option corresponds to the clang flag
764 * \c -fdiagnostics-show-category=id.
766 CXDiagnostic_DisplayCategoryId = 0x10,
769 * \brief Display the category name associated with this diagnostic, if any.
771 * The category name is displayed within brackets after the diagnostic text.
772 * This option corresponds to the clang flag
773 * \c -fdiagnostics-show-category=name.
775 CXDiagnostic_DisplayCategoryName = 0x20
779 * \brief Format the given diagnostic in a manner that is suitable for display.
781 * This routine will format the given diagnostic to a string, rendering
782 * the diagnostic according to the various options given. The
783 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
784 * options that most closely mimics the behavior of the clang compiler.
786 * \param Diagnostic The diagnostic to print.
788 * \param Options A set of options that control the diagnostic display,
789 * created by combining \c CXDiagnosticDisplayOptions values.
791 * \returns A new string containing for formatted diagnostic.
793 CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
797 * \brief Retrieve the set of display options most similar to the
798 * default behavior of the clang compiler.
800 * \returns A set of display options suitable for use with \c
801 * clang_displayDiagnostic().
803 CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
806 * \brief Determine the severity of the given diagnostic.
808 CINDEX_LINKAGE enum CXDiagnosticSeverity
809 clang_getDiagnosticSeverity(CXDiagnostic);
812 * \brief Retrieve the source location of the given diagnostic.
814 * This location is where Clang would print the caret ('^') when
815 * displaying the diagnostic on the command line.
817 CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
820 * \brief Retrieve the text of the given diagnostic.
822 CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
825 * \brief Retrieve the name of the command-line option that enabled this
828 * \param Diag The diagnostic to be queried.
830 * \param Disable If non-NULL, will be set to the option that disables this
831 * diagnostic (if any).
833 * \returns A string that contains the command-line option used to enable this
834 * warning, such as "-Wconversion" or "-pedantic".
836 CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
840 * \brief Retrieve the category number for this diagnostic.
842 * Diagnostics can be categorized into groups along with other, related
843 * diagnostics (e.g., diagnostics under the same warning flag). This routine
844 * retrieves the category number for the given diagnostic.
846 * \returns The number of the category that contains this diagnostic, or zero
847 * if this diagnostic is uncategorized.
849 CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
852 * \brief Retrieve the name of a particular diagnostic category. This
853 * is now deprecated. Use clang_getDiagnosticCategoryText()
856 * \param Category A diagnostic category number, as returned by
857 * \c clang_getDiagnosticCategory().
859 * \returns The name of the given diagnostic category.
861 CINDEX_DEPRECATED CINDEX_LINKAGE
862 CXString clang_getDiagnosticCategoryName(unsigned Category);
865 * \brief Retrieve the diagnostic category text for a given diagnostic.
867 * \returns The text of the given diagnostic category.
869 CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
872 * \brief Determine the number of source ranges associated with the given
875 CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
878 * \brief Retrieve a source range associated with the diagnostic.
880 * A diagnostic's source ranges highlight important elements in the source
881 * code. On the command line, Clang displays source ranges by
882 * underlining them with '~' characters.
884 * \param Diagnostic the diagnostic whose range is being extracted.
886 * \param Range the zero-based index specifying which range to
888 * \returns the requested source range.
890 CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
894 * \brief Determine the number of fix-it hints associated with the
897 CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
900 * \brief Retrieve the replacement information for a given fix-it.
902 * Fix-its are described in terms of a source range whose contents
903 * should be replaced by a string. This approach generalizes over
904 * three kinds of operations: removal of source code (the range covers
905 * the code to be removed and the replacement string is empty),
906 * replacement of source code (the range covers the code to be
907 * replaced and the replacement string provides the new code), and
908 * insertion (both the start and end of the range point at the
909 * insertion location, and the replacement string provides the text to
912 * \param Diagnostic The diagnostic whose fix-its are being queried.
914 * \param FixIt The zero-based index of the fix-it.
916 * \param ReplacementRange The source range whose contents will be
917 * replaced with the returned replacement string. Note that source
918 * ranges are half-open ranges [a, b), so the source code should be
919 * replaced from a and up to (but not including) b.
921 * \returns A string containing text that should be replace the source
922 * code indicated by the \c ReplacementRange.
924 CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
926 CXSourceRange *ReplacementRange);
933 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
935 * The routines in this group provide the ability to create and destroy
936 * translation units from files, either by parsing the contents of the files or
937 * by reading in a serialized representation of a translation unit.
943 * \brief Get the original translation unit source file name.
945 CINDEX_LINKAGE CXString
946 clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
949 * \brief Return the CXTranslationUnit for a given source file and the provided
950 * command line arguments one would pass to the compiler.
952 * Note: The 'source_filename' argument is optional. If the caller provides a
953 * NULL pointer, the name of the source file is expected to reside in the
954 * specified command line arguments.
956 * Note: When encountered in 'clang_command_line_args', the following options
962 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
964 * \param CIdx The index object with which the translation unit will be
967 * \param source_filename The name of the source file to load, or NULL if the
968 * source file is included in \p clang_command_line_args.
970 * \param num_clang_command_line_args The number of command-line arguments in
971 * \p clang_command_line_args.
973 * \param clang_command_line_args The command-line arguments that would be
974 * passed to the \c clang executable if it were being invoked out-of-process.
975 * These command-line options will be parsed and will affect how the translation
976 * unit is parsed. Note that the following options are ignored: '-c',
977 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
979 * \param num_unsaved_files the number of unsaved file entries in \p
982 * \param unsaved_files the files that have not yet been saved to disk
983 * but may be required for code completion, including the contents of
984 * those files. The contents and name of these files (as specified by
985 * CXUnsavedFile) are copied when necessary, so the client only needs to
986 * guarantee their validity until the call to this function returns.
988 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
990 const char *source_filename,
991 int num_clang_command_line_args,
992 const char * const *clang_command_line_args,
993 unsigned num_unsaved_files,
994 struct CXUnsavedFile *unsaved_files);
997 * \brief Create a translation unit from an AST file (-emit-ast).
999 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
1000 const char *ast_filename);
1003 * \brief Flags that control the creation of translation units.
1005 * The enumerators in this enumeration type are meant to be bitwise
1006 * ORed together to specify which options should be used when
1007 * constructing the translation unit.
1009 enum CXTranslationUnit_Flags {
1011 * \brief Used to indicate that no special translation-unit options are
1014 CXTranslationUnit_None = 0x0,
1017 * \brief Used to indicate that the parser should construct a "detailed"
1018 * preprocessing record, including all macro definitions and instantiations.
1020 * Constructing a detailed preprocessing record requires more memory
1021 * and time to parse, since the information contained in the record
1022 * is usually not retained. However, it can be useful for
1023 * applications that require more detailed information about the
1024 * behavior of the preprocessor.
1026 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1029 * \brief Used to indicate that the translation unit is incomplete.
1031 * When a translation unit is considered "incomplete", semantic
1032 * analysis that is typically performed at the end of the
1033 * translation unit will be suppressed. For example, this suppresses
1034 * the completion of tentative declarations in C and of
1035 * instantiation of implicitly-instantiation function templates in
1036 * C++. This option is typically used when parsing a header with the
1037 * intent of producing a precompiled header.
1039 CXTranslationUnit_Incomplete = 0x02,
1042 * \brief Used to indicate that the translation unit should be built with an
1043 * implicit precompiled header for the preamble.
1045 * An implicit precompiled header is used as an optimization when a
1046 * particular translation unit is likely to be reparsed many times
1047 * when the sources aren't changing that often. In this case, an
1048 * implicit precompiled header will be built containing all of the
1049 * initial includes at the top of the main file (what we refer to as
1050 * the "preamble" of the file). In subsequent parses, if the
1051 * preamble or the files in it have not changed, \c
1052 * clang_reparseTranslationUnit() will re-use the implicit
1053 * precompiled header to improve parsing performance.
1055 CXTranslationUnit_PrecompiledPreamble = 0x04,
1058 * \brief Used to indicate that the translation unit should cache some
1059 * code-completion results with each reparse of the source file.
1061 * Caching of code-completion results is a performance optimization that
1062 * introduces some overhead to reparsing but improves the performance of
1063 * code-completion operations.
1065 CXTranslationUnit_CacheCompletionResults = 0x08,
1068 * \brief Used to indicate that the translation unit will be serialized with
1069 * \c clang_saveTranslationUnit.
1071 * This option is typically used when parsing a header with the intent of
1072 * producing a precompiled header.
1074 CXTranslationUnit_ForSerialization = 0x10,
1077 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
1079 * Note: this is a *temporary* option that is available only while
1080 * we are testing C++ precompiled preamble support. It is deprecated.
1082 CXTranslationUnit_CXXChainedPCH = 0x20,
1085 * \brief Used to indicate that function/method bodies should be skipped while
1088 * This option can be used to search for declarations/definitions while
1089 * ignoring the usages.
1091 CXTranslationUnit_SkipFunctionBodies = 0x40,
1094 * \brief Used to indicate that brief documentation comments should be
1095 * included into the set of code completions returned from this translation
1098 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80
1102 * \brief Returns the set of flags that is suitable for parsing a translation
1103 * unit that is being edited.
1105 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1106 * to indicate that the translation unit is likely to be reparsed many times,
1107 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1108 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1109 * set contains an unspecified set of optimizations (e.g., the precompiled
1110 * preamble) geared toward improving the performance of these routines. The
1111 * set of optimizations enabled may change from one version to the next.
1113 CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
1116 * \brief Parse the given source file and the translation unit corresponding
1119 * This routine is the main entry point for the Clang C API, providing the
1120 * ability to parse a source file into a translation unit that can then be
1121 * queried by other functions in the API. This routine accepts a set of
1122 * command-line arguments so that the compilation can be configured in the same
1123 * way that the compiler is configured on the command line.
1125 * \param CIdx The index object with which the translation unit will be
1128 * \param source_filename The name of the source file to load, or NULL if the
1129 * source file is included in \p command_line_args.
1131 * \param command_line_args The command-line arguments that would be
1132 * passed to the \c clang executable if it were being invoked out-of-process.
1133 * These command-line options will be parsed and will affect how the translation
1134 * unit is parsed. Note that the following options are ignored: '-c',
1135 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
1137 * \param num_command_line_args The number of command-line arguments in
1138 * \p command_line_args.
1140 * \param unsaved_files the files that have not yet been saved to disk
1141 * but may be required for parsing, including the contents of
1142 * those files. The contents and name of these files (as specified by
1143 * CXUnsavedFile) are copied when necessary, so the client only needs to
1144 * guarantee their validity until the call to this function returns.
1146 * \param num_unsaved_files the number of unsaved file entries in \p
1149 * \param options A bitmask of options that affects how the translation unit
1150 * is managed but not its compilation. This should be a bitwise OR of the
1151 * CXTranslationUnit_XXX flags.
1153 * \returns A new translation unit describing the parsed code and containing
1154 * any diagnostics produced by the compiler. If there is a failure from which
1155 * the compiler cannot recover, returns NULL.
1157 CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1158 const char *source_filename,
1159 const char * const *command_line_args,
1160 int num_command_line_args,
1161 struct CXUnsavedFile *unsaved_files,
1162 unsigned num_unsaved_files,
1166 * \brief Flags that control how translation units are saved.
1168 * The enumerators in this enumeration type are meant to be bitwise
1169 * ORed together to specify which options should be used when
1170 * saving the translation unit.
1172 enum CXSaveTranslationUnit_Flags {
1174 * \brief Used to indicate that no special saving options are needed.
1176 CXSaveTranslationUnit_None = 0x0
1180 * \brief Returns the set of flags that is suitable for saving a translation
1183 * The set of flags returned provide options for
1184 * \c clang_saveTranslationUnit() by default. The returned flag
1185 * set contains an unspecified set of options that save translation units with
1186 * the most commonly-requested data.
1188 CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1191 * \brief Describes the kind of error that occurred (if any) in a call to
1192 * \c clang_saveTranslationUnit().
1196 * \brief Indicates that no error occurred while saving a translation unit.
1198 CXSaveError_None = 0,
1201 * \brief Indicates that an unknown error occurred while attempting to save
1204 * This error typically indicates that file I/O failed when attempting to
1207 CXSaveError_Unknown = 1,
1210 * \brief Indicates that errors during translation prevented this attempt
1211 * to save the translation unit.
1213 * Errors that prevent the translation unit from being saved can be
1214 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1216 CXSaveError_TranslationErrors = 2,
1219 * \brief Indicates that the translation unit to be saved was somehow
1220 * invalid (e.g., NULL).
1222 CXSaveError_InvalidTU = 3
1226 * \brief Saves a translation unit into a serialized representation of
1227 * that translation unit on disk.
1229 * Any translation unit that was parsed without error can be saved
1230 * into a file. The translation unit can then be deserialized into a
1231 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1232 * if it is an incomplete translation unit that corresponds to a
1233 * header, used as a precompiled header when parsing other translation
1236 * \param TU The translation unit to save.
1238 * \param FileName The file to which the translation unit will be saved.
1240 * \param options A bitmask of options that affects how the translation unit
1241 * is saved. This should be a bitwise OR of the
1242 * CXSaveTranslationUnit_XXX flags.
1244 * \returns A value that will match one of the enumerators of the CXSaveError
1245 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1246 * saved successfully, while a non-zero value indicates that a problem occurred.
1248 CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
1249 const char *FileName,
1253 * \brief Destroy the specified CXTranslationUnit object.
1255 CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
1258 * \brief Flags that control the reparsing of translation units.
1260 * The enumerators in this enumeration type are meant to be bitwise
1261 * ORed together to specify which options should be used when
1262 * reparsing the translation unit.
1264 enum CXReparse_Flags {
1266 * \brief Used to indicate that no special reparsing options are needed.
1268 CXReparse_None = 0x0
1272 * \brief Returns the set of flags that is suitable for reparsing a translation
1275 * The set of flags returned provide options for
1276 * \c clang_reparseTranslationUnit() by default. The returned flag
1277 * set contains an unspecified set of optimizations geared toward common uses
1278 * of reparsing. The set of optimizations enabled may change from one version
1281 CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1284 * \brief Reparse the source files that produced this translation unit.
1286 * This routine can be used to re-parse the source files that originally
1287 * created the given translation unit, for example because those source files
1288 * have changed (either on disk or as passed via \p unsaved_files). The
1289 * source code will be reparsed with the same command-line options as it
1290 * was originally parsed.
1292 * Reparsing a translation unit invalidates all cursors and source locations
1293 * that refer into that translation unit. This makes reparsing a translation
1294 * unit semantically equivalent to destroying the translation unit and then
1295 * creating a new translation unit with the same command-line arguments.
1296 * However, it may be more efficient to reparse a translation
1297 * unit using this routine.
1299 * \param TU The translation unit whose contents will be re-parsed. The
1300 * translation unit must originally have been built with
1301 * \c clang_createTranslationUnitFromSourceFile().
1303 * \param num_unsaved_files The number of unsaved file entries in \p
1306 * \param unsaved_files The files that have not yet been saved to disk
1307 * but may be required for parsing, including the contents of
1308 * those files. The contents and name of these files (as specified by
1309 * CXUnsavedFile) are copied when necessary, so the client only needs to
1310 * guarantee their validity until the call to this function returns.
1312 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1313 * The function \c clang_defaultReparseOptions() produces a default set of
1314 * options recommended for most uses, based on the translation unit.
1316 * \returns 0 if the sources could be reparsed. A non-zero value will be
1317 * returned if reparsing was impossible, such that the translation unit is
1318 * invalid. In such cases, the only valid call for \p TU is
1319 * \c clang_disposeTranslationUnit(TU).
1321 CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1322 unsigned num_unsaved_files,
1323 struct CXUnsavedFile *unsaved_files,
1327 * \brief Categorizes how memory is being used by a translation unit.
1329 enum CXTUResourceUsageKind {
1330 CXTUResourceUsage_AST = 1,
1331 CXTUResourceUsage_Identifiers = 2,
1332 CXTUResourceUsage_Selectors = 3,
1333 CXTUResourceUsage_GlobalCompletionResults = 4,
1334 CXTUResourceUsage_SourceManagerContentCache = 5,
1335 CXTUResourceUsage_AST_SideTables = 6,
1336 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
1337 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1338 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1339 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
1340 CXTUResourceUsage_Preprocessor = 11,
1341 CXTUResourceUsage_PreprocessingRecord = 12,
1342 CXTUResourceUsage_SourceManager_DataStructures = 13,
1343 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
1344 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1345 CXTUResourceUsage_MEMORY_IN_BYTES_END =
1346 CXTUResourceUsage_Preprocessor_HeaderSearch,
1348 CXTUResourceUsage_First = CXTUResourceUsage_AST,
1349 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
1353 * \brief Returns the human-readable null-terminated C string that represents
1354 * the name of the memory category. This string should never be freed.
1357 const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
1359 typedef struct CXTUResourceUsageEntry {
1360 /* \brief The memory usage category. */
1361 enum CXTUResourceUsageKind kind;
1362 /* \brief Amount of resources used.
1363 The units will depend on the resource kind. */
1364 unsigned long amount;
1365 } CXTUResourceUsageEntry;
1368 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1370 typedef struct CXTUResourceUsage {
1371 /* \brief Private data member, used for queries. */
1374 /* \brief The number of entries in the 'entries' array. */
1375 unsigned numEntries;
1377 /* \brief An array of key-value pairs, representing the breakdown of memory
1379 CXTUResourceUsageEntry *entries;
1381 } CXTUResourceUsage;
1384 * \brief Return the memory usage of a translation unit. This object
1385 * should be released with clang_disposeCXTUResourceUsage().
1387 CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
1389 CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
1396 * \brief Describes the kind of entity that a cursor refers to.
1401 * \brief A declaration whose specific kind is not exposed via this
1404 * Unexposed declarations have the same operations as any other kind
1405 * of declaration; one can extract their location information,
1406 * spelling, find their definitions, etc. However, the specific kind
1407 * of the declaration is not reported.
1409 CXCursor_UnexposedDecl = 1,
1410 /** \brief A C or C++ struct. */
1411 CXCursor_StructDecl = 2,
1412 /** \brief A C or C++ union. */
1413 CXCursor_UnionDecl = 3,
1414 /** \brief A C++ class. */
1415 CXCursor_ClassDecl = 4,
1416 /** \brief An enumeration. */
1417 CXCursor_EnumDecl = 5,
1419 * \brief A field (in C) or non-static data member (in C++) in a
1420 * struct, union, or C++ class.
1422 CXCursor_FieldDecl = 6,
1423 /** \brief An enumerator constant. */
1424 CXCursor_EnumConstantDecl = 7,
1425 /** \brief A function. */
1426 CXCursor_FunctionDecl = 8,
1427 /** \brief A variable. */
1428 CXCursor_VarDecl = 9,
1429 /** \brief A function or method parameter. */
1430 CXCursor_ParmDecl = 10,
1431 /** \brief An Objective-C \@interface. */
1432 CXCursor_ObjCInterfaceDecl = 11,
1433 /** \brief An Objective-C \@interface for a category. */
1434 CXCursor_ObjCCategoryDecl = 12,
1435 /** \brief An Objective-C \@protocol declaration. */
1436 CXCursor_ObjCProtocolDecl = 13,
1437 /** \brief An Objective-C \@property declaration. */
1438 CXCursor_ObjCPropertyDecl = 14,
1439 /** \brief An Objective-C instance variable. */
1440 CXCursor_ObjCIvarDecl = 15,
1441 /** \brief An Objective-C instance method. */
1442 CXCursor_ObjCInstanceMethodDecl = 16,
1443 /** \brief An Objective-C class method. */
1444 CXCursor_ObjCClassMethodDecl = 17,
1445 /** \brief An Objective-C \@implementation. */
1446 CXCursor_ObjCImplementationDecl = 18,
1447 /** \brief An Objective-C \@implementation for a category. */
1448 CXCursor_ObjCCategoryImplDecl = 19,
1449 /** \brief A typedef */
1450 CXCursor_TypedefDecl = 20,
1451 /** \brief A C++ class method. */
1452 CXCursor_CXXMethod = 21,
1453 /** \brief A C++ namespace. */
1454 CXCursor_Namespace = 22,
1455 /** \brief A linkage specification, e.g. 'extern "C"'. */
1456 CXCursor_LinkageSpec = 23,
1457 /** \brief A C++ constructor. */
1458 CXCursor_Constructor = 24,
1459 /** \brief A C++ destructor. */
1460 CXCursor_Destructor = 25,
1461 /** \brief A C++ conversion function. */
1462 CXCursor_ConversionFunction = 26,
1463 /** \brief A C++ template type parameter. */
1464 CXCursor_TemplateTypeParameter = 27,
1465 /** \brief A C++ non-type template parameter. */
1466 CXCursor_NonTypeTemplateParameter = 28,
1467 /** \brief A C++ template template parameter. */
1468 CXCursor_TemplateTemplateParameter = 29,
1469 /** \brief A C++ function template. */
1470 CXCursor_FunctionTemplate = 30,
1471 /** \brief A C++ class template. */
1472 CXCursor_ClassTemplate = 31,
1473 /** \brief A C++ class template partial specialization. */
1474 CXCursor_ClassTemplatePartialSpecialization = 32,
1475 /** \brief A C++ namespace alias declaration. */
1476 CXCursor_NamespaceAlias = 33,
1477 /** \brief A C++ using directive. */
1478 CXCursor_UsingDirective = 34,
1479 /** \brief A C++ using declaration. */
1480 CXCursor_UsingDeclaration = 35,
1481 /** \brief A C++ alias declaration */
1482 CXCursor_TypeAliasDecl = 36,
1483 /** \brief An Objective-C \@synthesize definition. */
1484 CXCursor_ObjCSynthesizeDecl = 37,
1485 /** \brief An Objective-C \@dynamic definition. */
1486 CXCursor_ObjCDynamicDecl = 38,
1487 /** \brief An access specifier. */
1488 CXCursor_CXXAccessSpecifier = 39,
1490 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
1491 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
1494 CXCursor_FirstRef = 40, /* Decl references */
1495 CXCursor_ObjCSuperClassRef = 40,
1496 CXCursor_ObjCProtocolRef = 41,
1497 CXCursor_ObjCClassRef = 42,
1499 * \brief A reference to a type declaration.
1501 * A type reference occurs anywhere where a type is named but not
1502 * declared. For example, given:
1505 * typedef unsigned size_type;
1509 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1510 * while the type of the variable "size" is referenced. The cursor
1511 * referenced by the type of size is the typedef for size_type.
1513 CXCursor_TypeRef = 43,
1514 CXCursor_CXXBaseSpecifier = 44,
1516 * \brief A reference to a class template, function template, template
1517 * template parameter, or class template partial specialization.
1519 CXCursor_TemplateRef = 45,
1521 * \brief A reference to a namespace or namespace alias.
1523 CXCursor_NamespaceRef = 46,
1525 * \brief A reference to a member of a struct, union, or class that occurs in
1526 * some non-expression context, e.g., a designated initializer.
1528 CXCursor_MemberRef = 47,
1530 * \brief A reference to a labeled statement.
1532 * This cursor kind is used to describe the jump to "start_over" in the
1533 * goto statement in the following example:
1542 * A label reference cursor refers to a label statement.
1544 CXCursor_LabelRef = 48,
1547 * \brief A reference to a set of overloaded functions or function templates
1548 * that has not yet been resolved to a specific function or function template.
1550 * An overloaded declaration reference cursor occurs in C++ templates where
1551 * a dependent name refers to a function. For example:
1554 * template<typename T> void swap(T&, T&);
1557 * void swap(X&, X&);
1559 * template<typename T>
1560 * void reverse(T* first, T* last) {
1561 * while (first < last - 1) {
1562 * swap(*first, *--last);
1568 * void swap(Y&, Y&);
1571 * Here, the identifier "swap" is associated with an overloaded declaration
1572 * reference. In the template definition, "swap" refers to either of the two
1573 * "swap" functions declared above, so both results will be available. At
1574 * instantiation time, "swap" may also refer to other functions found via
1575 * argument-dependent lookup (e.g., the "swap" function at the end of the
1578 * The functions \c clang_getNumOverloadedDecls() and
1579 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1580 * referenced by this cursor.
1582 CXCursor_OverloadedDeclRef = 49,
1585 * \brief A reference to a variable that occurs in some non-expression
1586 * context, e.g., a C++ lambda capture list.
1588 CXCursor_VariableRef = 50,
1590 CXCursor_LastRef = CXCursor_VariableRef,
1592 /* Error conditions */
1593 CXCursor_FirstInvalid = 70,
1594 CXCursor_InvalidFile = 70,
1595 CXCursor_NoDeclFound = 71,
1596 CXCursor_NotImplemented = 72,
1597 CXCursor_InvalidCode = 73,
1598 CXCursor_LastInvalid = CXCursor_InvalidCode,
1601 CXCursor_FirstExpr = 100,
1604 * \brief An expression whose specific kind is not exposed via this
1607 * Unexposed expressions have the same operations as any other kind
1608 * of expression; one can extract their location information,
1609 * spelling, children, etc. However, the specific kind of the
1610 * expression is not reported.
1612 CXCursor_UnexposedExpr = 100,
1615 * \brief An expression that refers to some value declaration, such
1616 * as a function, varible, or enumerator.
1618 CXCursor_DeclRefExpr = 101,
1621 * \brief An expression that refers to a member of a struct, union,
1622 * class, Objective-C class, etc.
1624 CXCursor_MemberRefExpr = 102,
1626 /** \brief An expression that calls a function. */
1627 CXCursor_CallExpr = 103,
1629 /** \brief An expression that sends a message to an Objective-C
1631 CXCursor_ObjCMessageExpr = 104,
1633 /** \brief An expression that represents a block literal. */
1634 CXCursor_BlockExpr = 105,
1636 /** \brief An integer literal.
1638 CXCursor_IntegerLiteral = 106,
1640 /** \brief A floating point number literal.
1642 CXCursor_FloatingLiteral = 107,
1644 /** \brief An imaginary number literal.
1646 CXCursor_ImaginaryLiteral = 108,
1648 /** \brief A string literal.
1650 CXCursor_StringLiteral = 109,
1652 /** \brief A character literal.
1654 CXCursor_CharacterLiteral = 110,
1656 /** \brief A parenthesized expression, e.g. "(1)".
1658 * This AST node is only formed if full location information is requested.
1660 CXCursor_ParenExpr = 111,
1662 /** \brief This represents the unary-expression's (except sizeof and
1665 CXCursor_UnaryOperator = 112,
1667 /** \brief [C99 6.5.2.1] Array Subscripting.
1669 CXCursor_ArraySubscriptExpr = 113,
1671 /** \brief A builtin binary operation expression such as "x + y" or
1674 CXCursor_BinaryOperator = 114,
1676 /** \brief Compound assignment such as "+=".
1678 CXCursor_CompoundAssignOperator = 115,
1680 /** \brief The ?: ternary operator.
1682 CXCursor_ConditionalOperator = 116,
1684 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1685 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1687 * For example: (int)f.
1689 CXCursor_CStyleCastExpr = 117,
1691 /** \brief [C99 6.5.2.5]
1693 CXCursor_CompoundLiteralExpr = 118,
1695 /** \brief Describes an C or C++ initializer list.
1697 CXCursor_InitListExpr = 119,
1699 /** \brief The GNU address of label extension, representing &&label.
1701 CXCursor_AddrLabelExpr = 120,
1703 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1705 CXCursor_StmtExpr = 121,
1707 /** \brief Represents a C11 generic selection.
1709 CXCursor_GenericSelectionExpr = 122,
1711 /** \brief Implements the GNU __null extension, which is a name for a null
1712 * pointer constant that has integral type (e.g., int or long) and is the same
1713 * size and alignment as a pointer.
1715 * The __null extension is typically only used by system headers, which define
1716 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1717 * match the size of a pointer).
1719 CXCursor_GNUNullExpr = 123,
1721 /** \brief C++'s static_cast<> expression.
1723 CXCursor_CXXStaticCastExpr = 124,
1725 /** \brief C++'s dynamic_cast<> expression.
1727 CXCursor_CXXDynamicCastExpr = 125,
1729 /** \brief C++'s reinterpret_cast<> expression.
1731 CXCursor_CXXReinterpretCastExpr = 126,
1733 /** \brief C++'s const_cast<> expression.
1735 CXCursor_CXXConstCastExpr = 127,
1737 /** \brief Represents an explicit C++ type conversion that uses "functional"
1738 * notion (C++ [expr.type.conv]).
1745 CXCursor_CXXFunctionalCastExpr = 128,
1747 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1749 CXCursor_CXXTypeidExpr = 129,
1751 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1753 CXCursor_CXXBoolLiteralExpr = 130,
1755 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1757 CXCursor_CXXNullPtrLiteralExpr = 131,
1759 /** \brief Represents the "this" expression in C++
1761 CXCursor_CXXThisExpr = 132,
1763 /** \brief [C++ 15] C++ Throw Expression.
1765 * This handles 'throw' and 'throw' assignment-expression. When
1766 * assignment-expression isn't present, Op will be null.
1768 CXCursor_CXXThrowExpr = 133,
1770 /** \brief A new expression for memory allocation and constructor calls, e.g:
1771 * "new CXXNewExpr(foo)".
1773 CXCursor_CXXNewExpr = 134,
1775 /** \brief A delete expression for memory deallocation and destructor calls,
1776 * e.g. "delete[] pArray".
1778 CXCursor_CXXDeleteExpr = 135,
1780 /** \brief A unary expression.
1782 CXCursor_UnaryExpr = 136,
1784 /** \brief An Objective-C string literal i.e. @"foo".
1786 CXCursor_ObjCStringLiteral = 137,
1788 /** \brief An Objective-C \@encode expression.
1790 CXCursor_ObjCEncodeExpr = 138,
1792 /** \brief An Objective-C \@selector expression.
1794 CXCursor_ObjCSelectorExpr = 139,
1796 /** \brief An Objective-C \@protocol expression.
1798 CXCursor_ObjCProtocolExpr = 140,
1800 /** \brief An Objective-C "bridged" cast expression, which casts between
1801 * Objective-C pointers and C pointers, transferring ownership in the process.
1804 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1807 CXCursor_ObjCBridgedCastExpr = 141,
1809 /** \brief Represents a C++0x pack expansion that produces a sequence of
1812 * A pack expansion expression contains a pattern (which itself is an
1813 * expression) followed by an ellipsis. For example:
1816 * template<typename F, typename ...Types>
1817 * void forward(F f, Types &&...args) {
1818 * f(static_cast<Types&&>(args)...);
1822 CXCursor_PackExpansionExpr = 142,
1824 /** \brief Represents an expression that computes the length of a parameter
1828 * template<typename ...Types>
1830 * static const unsigned value = sizeof...(Types);
1834 CXCursor_SizeOfPackExpr = 143,
1836 /* \brief Represents a C++ lambda expression that produces a local function
1840 * void abssort(float *x, unsigned N) {
1841 * std::sort(x, x + N,
1842 * [](float a, float b) {
1843 * return std::abs(a) < std::abs(b);
1848 CXCursor_LambdaExpr = 144,
1850 /** \brief Objective-c Boolean Literal.
1852 CXCursor_ObjCBoolLiteralExpr = 145,
1854 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
1857 CXCursor_FirstStmt = 200,
1859 * \brief A statement whose specific kind is not exposed via this
1862 * Unexposed statements have the same operations as any other kind of
1863 * statement; one can extract their location information, spelling,
1864 * children, etc. However, the specific kind of the statement is not
1867 CXCursor_UnexposedStmt = 200,
1869 /** \brief A labelled statement in a function.
1871 * This cursor kind is used to describe the "start_over:" label statement in
1872 * the following example:
1880 CXCursor_LabelStmt = 201,
1882 /** \brief A group of statements like { stmt stmt }.
1884 * This cursor kind is used to describe compound statements, e.g. function
1887 CXCursor_CompoundStmt = 202,
1889 /** \brief A case statment.
1891 CXCursor_CaseStmt = 203,
1893 /** \brief A default statement.
1895 CXCursor_DefaultStmt = 204,
1897 /** \brief An if statement
1899 CXCursor_IfStmt = 205,
1901 /** \brief A switch statement.
1903 CXCursor_SwitchStmt = 206,
1905 /** \brief A while statement.
1907 CXCursor_WhileStmt = 207,
1909 /** \brief A do statement.
1911 CXCursor_DoStmt = 208,
1913 /** \brief A for statement.
1915 CXCursor_ForStmt = 209,
1917 /** \brief A goto statement.
1919 CXCursor_GotoStmt = 210,
1921 /** \brief An indirect goto statement.
1923 CXCursor_IndirectGotoStmt = 211,
1925 /** \brief A continue statement.
1927 CXCursor_ContinueStmt = 212,
1929 /** \brief A break statement.
1931 CXCursor_BreakStmt = 213,
1933 /** \brief A return statement.
1935 CXCursor_ReturnStmt = 214,
1937 /** \brief A GCC inline assembly statement extension.
1939 CXCursor_GCCAsmStmt = 215,
1940 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
1942 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
1944 CXCursor_ObjCAtTryStmt = 216,
1946 /** \brief Objective-C's \@catch statement.
1948 CXCursor_ObjCAtCatchStmt = 217,
1950 /** \brief Objective-C's \@finally statement.
1952 CXCursor_ObjCAtFinallyStmt = 218,
1954 /** \brief Objective-C's \@throw statement.
1956 CXCursor_ObjCAtThrowStmt = 219,
1958 /** \brief Objective-C's \@synchronized statement.
1960 CXCursor_ObjCAtSynchronizedStmt = 220,
1962 /** \brief Objective-C's autorelease pool statement.
1964 CXCursor_ObjCAutoreleasePoolStmt = 221,
1966 /** \brief Objective-C's collection statement.
1968 CXCursor_ObjCForCollectionStmt = 222,
1970 /** \brief C++'s catch statement.
1972 CXCursor_CXXCatchStmt = 223,
1974 /** \brief C++'s try statement.
1976 CXCursor_CXXTryStmt = 224,
1978 /** \brief C++'s for (* : *) statement.
1980 CXCursor_CXXForRangeStmt = 225,
1982 /** \brief Windows Structured Exception Handling's try statement.
1984 CXCursor_SEHTryStmt = 226,
1986 /** \brief Windows Structured Exception Handling's except statement.
1988 CXCursor_SEHExceptStmt = 227,
1990 /** \brief Windows Structured Exception Handling's finally statement.
1992 CXCursor_SEHFinallyStmt = 228,
1994 /** \brief A MS inline assembly statement extension.
1996 CXCursor_MSAsmStmt = 229,
1998 /** \brief The null satement ";": C99 6.8.3p3.
2000 * This cursor kind is used to describe the null statement.
2002 CXCursor_NullStmt = 230,
2004 /** \brief Adaptor class for mixing declarations with statements and
2007 CXCursor_DeclStmt = 231,
2009 CXCursor_LastStmt = CXCursor_DeclStmt,
2012 * \brief Cursor that represents the translation unit itself.
2014 * The translation unit cursor exists primarily to act as the root
2015 * cursor for traversing the contents of a translation unit.
2017 CXCursor_TranslationUnit = 300,
2020 CXCursor_FirstAttr = 400,
2022 * \brief An attribute whose specific kind is not exposed via this
2025 CXCursor_UnexposedAttr = 400,
2027 CXCursor_IBActionAttr = 401,
2028 CXCursor_IBOutletAttr = 402,
2029 CXCursor_IBOutletCollectionAttr = 403,
2030 CXCursor_CXXFinalAttr = 404,
2031 CXCursor_CXXOverrideAttr = 405,
2032 CXCursor_AnnotateAttr = 406,
2033 CXCursor_AsmLabelAttr = 407,
2034 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
2037 CXCursor_PreprocessingDirective = 500,
2038 CXCursor_MacroDefinition = 501,
2039 CXCursor_MacroExpansion = 502,
2040 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
2041 CXCursor_InclusionDirective = 503,
2042 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
2043 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2045 /* Extra Declarations */
2047 * \brief A module import declaration.
2049 CXCursor_ModuleImportDecl = 600,
2050 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2051 CXCursor_LastExtraDecl = CXCursor_ModuleImportDecl
2055 * \brief A cursor representing some element in the abstract syntax tree for
2056 * a translation unit.
2058 * The cursor abstraction unifies the different kinds of entities in a
2059 * program--declaration, statements, expressions, references to declarations,
2060 * etc.--under a single "cursor" abstraction with a common set of operations.
2061 * Common operation for a cursor include: getting the physical location in
2062 * a source file where the cursor points, getting the name associated with a
2063 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2065 * Cursors can be produced in two specific ways.
2066 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2067 * from which one can use clang_visitChildren() to explore the rest of the
2068 * translation unit. clang_getCursor() maps from a physical source location
2069 * to the entity that resides at that location, allowing one to map from the
2070 * source code into the AST.
2073 enum CXCursorKind kind;
2079 * \brief A comment AST node.
2082 const void *ASTNode;
2083 CXTranslationUnit TranslationUnit;
2087 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2093 * \brief Retrieve the NULL cursor, which represents no entity.
2095 CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
2098 * \brief Retrieve the cursor that represents the given translation unit.
2100 * The translation unit cursor can be used to start traversing the
2101 * various declarations within the given translation unit.
2103 CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2106 * \brief Determine whether two cursors are equivalent.
2108 CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
2111 * \brief Returns non-zero if \p cursor is null.
2113 CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
2116 * \brief Compute a hash value for the given cursor.
2118 CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2121 * \brief Retrieve the kind of the given cursor.
2123 CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2126 * \brief Determine whether the given cursor kind represents a declaration.
2128 CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2131 * \brief Determine whether the given cursor kind represents a simple
2134 * Note that other kinds of cursors (such as expressions) can also refer to
2135 * other cursors. Use clang_getCursorReferenced() to determine whether a
2136 * particular cursor refers to another entity.
2138 CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2141 * \brief Determine whether the given cursor kind represents an expression.
2143 CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2146 * \brief Determine whether the given cursor kind represents a statement.
2148 CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2151 * \brief Determine whether the given cursor kind represents an attribute.
2153 CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2156 * \brief Determine whether the given cursor kind represents an invalid
2159 CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2162 * \brief Determine whether the given cursor kind represents a translation
2165 CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
2168 * \brief Determine whether the given cursor represents a preprocessing
2169 * element, such as a preprocessor directive or macro instantiation.
2171 CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2174 * \brief Determine whether the given cursor represents a currently
2175 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2177 CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2180 * \brief Describe the linkage of the entity referred to by a cursor.
2182 enum CXLinkageKind {
2183 /** \brief This value indicates that no linkage information is available
2184 * for a provided CXCursor. */
2187 * \brief This is the linkage for variables, parameters, and so on that
2188 * have automatic storage. This covers normal (non-extern) local variables.
2190 CXLinkage_NoLinkage,
2191 /** \brief This is the linkage for static variables and static functions. */
2193 /** \brief This is the linkage for entities with external linkage that live
2194 * in C++ anonymous namespaces.*/
2195 CXLinkage_UniqueExternal,
2196 /** \brief This is the linkage for entities with true, external linkage. */
2201 * \brief Determine the linkage of the entity referred to by a given cursor.
2203 CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2206 * \brief Determine the availability of the entity that this cursor refers to,
2207 * taking the current target platform into account.
2209 * \param cursor The cursor to query.
2211 * \returns The availability of the cursor.
2213 CINDEX_LINKAGE enum CXAvailabilityKind
2214 clang_getCursorAvailability(CXCursor cursor);
2217 * Describes the availability of a given entity on a particular platform, e.g.,
2218 * a particular class might only be available on Mac OS 10.7 or newer.
2220 typedef struct CXPlatformAvailability {
2222 * \brief A string that describes the platform for which this structure
2223 * provides availability information.
2225 * Possible values are "ios" or "macosx".
2229 * \brief The version number in which this entity was introduced.
2231 CXVersion Introduced;
2233 * \brief The version number in which this entity was deprecated (but is
2236 CXVersion Deprecated;
2238 * \brief The version number in which this entity was obsoleted, and therefore
2239 * is no longer available.
2241 CXVersion Obsoleted;
2243 * \brief Whether the entity is unconditionally unavailable on this platform.
2247 * \brief An optional message to provide to a user of this API, e.g., to
2248 * suggest replacement APIs.
2251 } CXPlatformAvailability;
2254 * \brief Determine the availability of the entity that this cursor refers to
2255 * on any platforms for which availability information is known.
2257 * \param cursor The cursor to query.
2259 * \param always_deprecated If non-NULL, will be set to indicate whether the
2260 * entity is deprecated on all platforms.
2262 * \param deprecated_message If non-NULL, will be set to the message text
2263 * provided along with the unconditional deprecation of this entity. The client
2264 * is responsible for deallocating this string.
2266 * \param always_unavailable If non-NULL, will be set to indicate whether the
2267 * entity is unavailable on all platforms.
2269 * \param unavailable_message If non-NULL, will be set to the message text
2270 * provided along with the unconditional unavailability of this entity. The
2271 * client is responsible for deallocating this string.
2273 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2274 * that will be populated with platform availability information, up to either
2275 * the number of platforms for which availability information is available (as
2276 * returned by this function) or \c availability_size, whichever is smaller.
2278 * \param availability_size The number of elements available in the
2279 * \c availability array.
2281 * \returns The number of platforms (N) for which availability information is
2282 * available (which is unrelated to \c availability_size).
2284 * Note that the client is responsible for calling
2285 * \c clang_disposeCXPlatformAvailability to free each of the
2286 * platform-availability structures returned. There are
2287 * \c min(N, availability_size) such structures.
2290 clang_getCursorPlatformAvailability(CXCursor cursor,
2291 int *always_deprecated,
2292 CXString *deprecated_message,
2293 int *always_unavailable,
2294 CXString *unavailable_message,
2295 CXPlatformAvailability *availability,
2296 int availability_size);
2299 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2302 clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2305 * \brief Describe the "language" of the entity referred to by a cursor.
2307 CINDEX_LINKAGE enum CXLanguageKind {
2308 CXLanguage_Invalid = 0,
2311 CXLanguage_CPlusPlus
2315 * \brief Determine the "language" of the entity referred to by a given cursor.
2317 CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2320 * \brief Returns the translation unit that a cursor originated from.
2322 CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2326 * \brief A fast container representing a set of CXCursors.
2328 typedef struct CXCursorSetImpl *CXCursorSet;
2331 * \brief Creates an empty CXCursorSet.
2333 CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2336 * \brief Disposes a CXCursorSet and releases its associated memory.
2338 CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2341 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2343 * \returns non-zero if the set contains the specified cursor.
2345 CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2349 * \brief Inserts a CXCursor into a CXCursorSet.
2351 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2353 CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2357 * \brief Determine the semantic parent of the given cursor.
2359 * The semantic parent of a cursor is the cursor that semantically contains
2360 * the given \p cursor. For many declarations, the lexical and semantic parents
2361 * are equivalent (the lexical parent is returned by
2362 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2363 * definitions are provided out-of-line. For example:
2373 * In the out-of-line definition of \c C::f, the semantic parent is the
2374 * the class \c C, of which this function is a member. The lexical parent is
2375 * the place where the declaration actually occurs in the source code; in this
2376 * case, the definition occurs in the translation unit. In general, the
2377 * lexical parent for a given entity can change without affecting the semantics
2378 * of the program, and the lexical parent of different declarations of the
2379 * same entity may be different. Changing the semantic parent of a declaration,
2380 * on the other hand, can have a major impact on semantics, and redeclarations
2381 * of a particular entity should all have the same semantic context.
2383 * In the example above, both declarations of \c C::f have \c C as their
2384 * semantic context, while the lexical context of the first \c C::f is \c C
2385 * and the lexical context of the second \c C::f is the translation unit.
2387 * For global declarations, the semantic parent is the translation unit.
2389 CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2392 * \brief Determine the lexical parent of the given cursor.
2394 * The lexical parent of a cursor is the cursor in which the given \p cursor
2395 * was actually written. For many declarations, the lexical and semantic parents
2396 * are equivalent (the semantic parent is returned by
2397 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2398 * definitions are provided out-of-line. For example:
2408 * In the out-of-line definition of \c C::f, the semantic parent is the
2409 * the class \c C, of which this function is a member. The lexical parent is
2410 * the place where the declaration actually occurs in the source code; in this
2411 * case, the definition occurs in the translation unit. In general, the
2412 * lexical parent for a given entity can change without affecting the semantics
2413 * of the program, and the lexical parent of different declarations of the
2414 * same entity may be different. Changing the semantic parent of a declaration,
2415 * on the other hand, can have a major impact on semantics, and redeclarations
2416 * of a particular entity should all have the same semantic context.
2418 * In the example above, both declarations of \c C::f have \c C as their
2419 * semantic context, while the lexical context of the first \c C::f is \c C
2420 * and the lexical context of the second \c C::f is the translation unit.
2422 * For declarations written in the global scope, the lexical parent is
2423 * the translation unit.
2425 CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
2428 * \brief Determine the set of methods that are overridden by the given
2431 * In both Objective-C and C++, a method (aka virtual member function,
2432 * in C++) can override a virtual method in a base class. For
2433 * Objective-C, a method is said to override any method in the class's
2434 * base class, its protocols, or its categories' protocols, that has the same
2435 * selector and is of the same kind (class or instance).
2436 * If no such method exists, the search continues to the class's superclass,
2437 * its protocols, and its categories, and so on. A method from an Objective-C
2438 * implementation is considered to override the same methods as its
2439 * corresponding method in the interface.
2441 * For C++, a virtual member function overrides any virtual member
2442 * function with the same signature that occurs in its base
2443 * classes. With multiple inheritance, a virtual member function can
2444 * override several virtual member functions coming from different
2447 * In all cases, this function determines the immediate overridden
2448 * method, rather than all of the overridden methods. For example, if
2449 * a method is originally declared in a class A, then overridden in B
2450 * (which in inherits from A) and also in C (which inherited from B),
2451 * then the only overridden method returned from this function when
2452 * invoked on C's method will be B's method. The client may then
2453 * invoke this function again, given the previously-found overridden
2454 * methods, to map out the complete method-override set.
2456 * \param cursor A cursor representing an Objective-C or C++
2457 * method. This routine will compute the set of methods that this
2460 * \param overridden A pointer whose pointee will be replaced with a
2461 * pointer to an array of cursors, representing the set of overridden
2462 * methods. If there are no overridden methods, the pointee will be
2463 * set to NULL. The pointee must be freed via a call to
2464 * \c clang_disposeOverriddenCursors().
2466 * \param num_overridden A pointer to the number of overridden
2467 * functions, will be set to the number of overridden functions in the
2468 * array pointed to by \p overridden.
2470 CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2471 CXCursor **overridden,
2472 unsigned *num_overridden);
2475 * \brief Free the set of overridden cursors returned by \c
2476 * clang_getOverriddenCursors().
2478 CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2481 * \brief Retrieve the file that is included by the given inclusion directive
2484 CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2491 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2493 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2494 * routines help map between cursors and the physical locations where the
2495 * described entities occur in the source code. The mapping is provided in
2496 * both directions, so one can map from source code to the AST and back.
2502 * \brief Map a source location to the cursor that describes the entity at that
2503 * location in the source code.
2505 * clang_getCursor() maps an arbitrary source location within a translation
2506 * unit down to the most specific cursor that describes the entity at that
2507 * location. For example, given an expression \c x + y, invoking
2508 * clang_getCursor() with a source location pointing to "x" will return the
2509 * cursor for "x"; similarly for "y". If the cursor points anywhere between
2510 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2511 * will return a cursor referring to the "+" expression.
2513 * \returns a cursor representing the entity at the given source location, or
2514 * a NULL cursor if no such entity can be found.
2516 CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
2519 * \brief Retrieve the physical location of the source constructor referenced
2520 * by the given cursor.
2522 * The location of a declaration is typically the location of the name of that
2523 * declaration, where the name of that declaration would occur if it is
2524 * unnamed, or some keyword that introduces that particular declaration.
2525 * The location of a reference is where that reference occurs within the
2528 CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
2531 * \brief Retrieve the physical extent of the source construct referenced by
2534 * The extent of a cursor starts with the file/line/column pointing at the
2535 * first character within the source construct that the cursor refers to and
2536 * ends with the last character withinin that source construct. For a
2537 * declaration, the extent covers the declaration itself. For a reference,
2538 * the extent covers the location of the reference (e.g., where the referenced
2539 * entity was actually used).
2541 CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
2548 * \defgroup CINDEX_TYPES Type information for CXCursors
2554 * \brief Describes the kind of type
2558 * \brief Reprents an invalid type (e.g., where no type is available).
2563 * \brief A type whose specific kind is not exposed via this
2566 CXType_Unexposed = 1,
2578 CXType_ULongLong = 11,
2579 CXType_UInt128 = 12,
2586 CXType_LongLong = 19,
2590 CXType_LongDouble = 23,
2591 CXType_NullPtr = 24,
2592 CXType_Overload = 25,
2593 CXType_Dependent = 26,
2595 CXType_ObjCClass = 28,
2596 CXType_ObjCSel = 29,
2597 CXType_FirstBuiltin = CXType_Void,
2598 CXType_LastBuiltin = CXType_ObjCSel,
2600 CXType_Complex = 100,
2601 CXType_Pointer = 101,
2602 CXType_BlockPointer = 102,
2603 CXType_LValueReference = 103,
2604 CXType_RValueReference = 104,
2605 CXType_Record = 105,
2607 CXType_Typedef = 107,
2608 CXType_ObjCInterface = 108,
2609 CXType_ObjCObjectPointer = 109,
2610 CXType_FunctionNoProto = 110,
2611 CXType_FunctionProto = 111,
2612 CXType_ConstantArray = 112,
2617 * \brief Describes the calling convention of a function type
2619 enum CXCallingConv {
2620 CXCallingConv_Default = 0,
2621 CXCallingConv_C = 1,
2622 CXCallingConv_X86StdCall = 2,
2623 CXCallingConv_X86FastCall = 3,
2624 CXCallingConv_X86ThisCall = 4,
2625 CXCallingConv_X86Pascal = 5,
2626 CXCallingConv_AAPCS = 6,
2627 CXCallingConv_AAPCS_VFP = 7,
2628 CXCallingConv_PnaclCall = 8,
2630 CXCallingConv_Invalid = 100,
2631 CXCallingConv_Unexposed = 200
2636 * \brief The type of an element in the abstract syntax tree.
2640 enum CXTypeKind kind;
2645 * \brief Retrieve the type of a CXCursor (if any).
2647 CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2650 * \brief Retrieve the underlying type of a typedef declaration.
2652 * If the cursor does not reference a typedef declaration, an invalid type is
2655 CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2658 * \brief Retrieve the integer type of an enum declaration.
2660 * If the cursor does not reference an enum declaration, an invalid type is
2663 CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2666 * \brief Retrieve the integer value of an enum constant declaration as a signed
2669 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2670 * Since this is also potentially a valid constant value, the kind of the cursor
2671 * must be verified before calling this function.
2673 CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2676 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2679 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2680 * Since this is also potentially a valid constant value, the kind of the cursor
2681 * must be verified before calling this function.
2683 CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2686 * \brief Retrieve the number of non-variadic arguments associated with a given
2689 * If a cursor that is not a function or method is passed in, -1 is returned.
2691 CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2694 * \brief Retrieve the argument cursor of a function or method.
2696 * If a cursor that is not a function or method is passed in or the index
2697 * exceeds the number of arguments, an invalid cursor is returned.
2699 CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2702 * \brief Determine whether two CXTypes represent the same type.
2704 * \returns non-zero if the CXTypes represent the same type and
2707 CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2710 * \brief Return the canonical type for a CXType.
2712 * Clang's type system explicitly models typedefs and all the ways
2713 * a specific type can be represented. The canonical type is the underlying
2714 * type with all the "sugar" removed. For example, if 'T' is a typedef
2715 * for 'int', the canonical type for 'T' would be 'int'.
2717 CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2720 * \brief Determine whether a CXType has the "const" qualifier set,
2721 * without looking through typedefs that may have added "const" at a
2724 CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2727 * \brief Determine whether a CXType has the "volatile" qualifier set,
2728 * without looking through typedefs that may have added "volatile" at
2729 * a different level.
2731 CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2734 * \brief Determine whether a CXType has the "restrict" qualifier set,
2735 * without looking through typedefs that may have added "restrict" at a
2738 CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2741 * \brief For pointer types, returns the type of the pointee.
2743 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2746 * \brief Return the cursor for the declaration of the given type.
2748 CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2751 * Returns the Objective-C type encoding for the specified declaration.
2753 CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
2756 * \brief Retrieve the spelling of a given CXTypeKind.
2758 CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2761 * \brief Retrieve the calling convention associated with a function type.
2763 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2765 CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2768 * \brief Retrieve the result type associated with a function type.
2770 * If a non-function type is passed in, an invalid type is returned.
2772 CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2775 * \brief Retrieve the number of non-variadic arguments associated with a
2778 * If a non-function type is passed in, -1 is returned.
2780 CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
2783 * \brief Retrieve the type of an argument of a function type.
2785 * If a non-function type is passed in or the function does not have enough
2786 * parameters, an invalid type is returned.
2788 CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2791 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2793 CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2796 * \brief Retrieve the result type associated with a given cursor.
2798 * This only returns a valid type if the cursor refers to a function or method.
2800 CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2803 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2806 CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2809 * \brief Return the element type of an array, complex, or vector type.
2811 * If a type is passed in that is not an array, complex, or vector type,
2812 * an invalid type is returned.
2814 CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2817 * \brief Return the number of elements of an array or vector type.
2819 * If a type is passed in that is not an array or vector type,
2822 CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2825 * \brief Return the element type of an array type.
2827 * If a non-array type is passed in, an invalid type is returned.
2829 CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2832 * \brief Return the array size of a constant array.
2834 * If a non-array type is passed in, -1 is returned.
2836 CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2839 * \brief Returns 1 if the base class specified by the cursor with kind
2840 * CX_CXXBaseSpecifier is virtual.
2842 CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2845 * \brief Represents the C++ access control level to a base class for a
2846 * cursor with kind CX_CXXBaseSpecifier.
2848 enum CX_CXXAccessSpecifier {
2849 CX_CXXInvalidAccessSpecifier,
2856 * \brief Returns the access control level for the C++ base specifier
2857 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2858 * CXCursor_AccessSpecifier.
2860 CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2863 * \brief Determine the number of overloaded declarations referenced by a
2864 * \c CXCursor_OverloadedDeclRef cursor.
2866 * \param cursor The cursor whose overloaded declarations are being queried.
2868 * \returns The number of overloaded declarations referenced by \c cursor. If it
2869 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2871 CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2874 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2875 * by a \c CXCursor_OverloadedDeclRef cursor.
2877 * \param cursor The cursor whose overloaded declarations are being queried.
2879 * \param index The zero-based index into the set of overloaded declarations in
2882 * \returns A cursor representing the declaration referenced by the given
2883 * \c cursor at the specified \c index. If the cursor does not have an
2884 * associated set of overloaded declarations, or if the index is out of bounds,
2885 * returns \c clang_getNullCursor();
2887 CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2895 * \defgroup CINDEX_ATTRIBUTES Information for attributes
2902 * \brief For cursors representing an iboutletcollection attribute,
2903 * this function returns the collection element type.
2906 CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2913 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2915 * These routines provide the ability to traverse the abstract syntax tree
2922 * \brief Describes how the traversal of the children of a particular
2923 * cursor should proceed after visiting a particular child cursor.
2925 * A value of this enumeration type should be returned by each
2926 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2928 enum CXChildVisitResult {
2930 * \brief Terminates the cursor traversal.
2934 * \brief Continues the cursor traversal with the next sibling of
2935 * the cursor just visited, without visiting its children.
2937 CXChildVisit_Continue,
2939 * \brief Recursively traverse the children of this cursor, using
2940 * the same visitor and client data.
2942 CXChildVisit_Recurse
2946 * \brief Visitor invoked for each cursor found by a traversal.
2948 * This visitor function will be invoked for each cursor found by
2949 * clang_visitCursorChildren(). Its first argument is the cursor being
2950 * visited, its second argument is the parent visitor for that cursor,
2951 * and its third argument is the client data provided to
2952 * clang_visitCursorChildren().
2954 * The visitor should return one of the \c CXChildVisitResult values
2955 * to direct clang_visitCursorChildren().
2957 typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2959 CXClientData client_data);
2962 * \brief Visit the children of a particular cursor.
2964 * This function visits all the direct children of the given cursor,
2965 * invoking the given \p visitor function with the cursors of each
2966 * visited child. The traversal may be recursive, if the visitor returns
2967 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2968 * the visitor returns \c CXChildVisit_Break.
2970 * \param parent the cursor whose child may be visited. All kinds of
2971 * cursors can be visited, including invalid cursors (which, by
2972 * definition, have no children).
2974 * \param visitor the visitor function that will be invoked for each
2975 * child of \p parent.
2977 * \param client_data pointer data supplied by the client, which will
2978 * be passed to the visitor each time it is invoked.
2980 * \returns a non-zero value if the traversal was terminated
2981 * prematurely by the visitor returning \c CXChildVisit_Break.
2983 CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
2984 CXCursorVisitor visitor,
2985 CXClientData client_data);
2986 #ifdef __has_feature
2987 # if __has_feature(blocks)
2989 * \brief Visitor invoked for each cursor found by a traversal.
2991 * This visitor block will be invoked for each cursor found by
2992 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2993 * visited, its second argument is the parent visitor for that cursor.
2995 * The visitor should return one of the \c CXChildVisitResult values
2996 * to direct clang_visitChildrenWithBlock().
2998 typedef enum CXChildVisitResult
2999 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3002 * Visits the children of a cursor using the specified block. Behaves
3003 * identically to clang_visitChildren() in all other respects.
3005 unsigned clang_visitChildrenWithBlock(CXCursor parent,
3006 CXCursorVisitorBlock block);
3015 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
3017 * These routines provide the ability to determine references within and
3018 * across translation units, by providing the names of the entities referenced
3019 * by cursors, follow reference cursors to the declarations they reference,
3020 * and associate declarations with their definitions.
3026 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
3027 * by the given cursor.
3029 * A Unified Symbol Resolution (USR) is a string that identifies a particular
3030 * entity (function, class, variable, etc.) within a program. USRs can be
3031 * compared across translation units to determine, e.g., when references in
3032 * one translation refer to an entity defined in another translation unit.
3034 CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
3037 * \brief Construct a USR for a specified Objective-C class.
3039 CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
3042 * \brief Construct a USR for a specified Objective-C category.
3044 CINDEX_LINKAGE CXString
3045 clang_constructUSR_ObjCCategory(const char *class_name,
3046 const char *category_name);
3049 * \brief Construct a USR for a specified Objective-C protocol.
3051 CINDEX_LINKAGE CXString
3052 clang_constructUSR_ObjCProtocol(const char *protocol_name);
3056 * \brief Construct a USR for a specified Objective-C instance variable and
3057 * the USR for its containing class.
3059 CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
3063 * \brief Construct a USR for a specified Objective-C method and
3064 * the USR for its containing class.
3066 CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
3067 unsigned isInstanceMethod,
3071 * \brief Construct a USR for a specified Objective-C property and the USR
3072 * for its containing class.
3074 CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
3078 * \brief Retrieve a name for the entity referenced by this cursor.
3080 CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
3083 * \brief Retrieve a range for a piece that forms the cursors spelling name.
3084 * Most of the times there is only one range for the complete spelling but for
3085 * objc methods and objc message expressions, there are multiple pieces for each
3086 * selector identifier.
3088 * \param pieceIndex the index of the spelling name piece. If this is greater
3089 * than the actual number of pieces, it will return a NULL (invalid) range.
3091 * \param options Reserved.
3093 CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
3094 unsigned pieceIndex,
3098 * \brief Retrieve the display name for the entity referenced by this cursor.
3100 * The display name contains extra information that helps identify the cursor,
3101 * such as the parameters of a function or template or the arguments of a
3102 * class template specialization.
3104 CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
3106 /** \brief For a cursor that is a reference, retrieve a cursor representing the
3107 * entity that it references.
3109 * Reference cursors refer to other entities in the AST. For example, an
3110 * Objective-C superclass reference cursor refers to an Objective-C class.
3111 * This function produces the cursor for the Objective-C class from the
3112 * cursor for the superclass reference. If the input cursor is a declaration or
3113 * definition, it returns that declaration or definition unchanged.
3114 * Otherwise, returns the NULL cursor.
3116 CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
3119 * \brief For a cursor that is either a reference to or a declaration
3120 * of some entity, retrieve a cursor that describes the definition of
3123 * Some entities can be declared multiple times within a translation
3124 * unit, but only one of those declarations can also be a
3125 * definition. For example, given:
3129 * int g(int x, int y) { return f(x, y); }
3130 * int f(int a, int b) { return a + b; }
3134 * there are three declarations of the function "f", but only the
3135 * second one is a definition. The clang_getCursorDefinition()
3136 * function will take any cursor pointing to a declaration of "f"
3137 * (the first or fourth lines of the example) or a cursor referenced
3138 * that uses "f" (the call to "f' inside "g") and will return a
3139 * declaration cursor pointing to the definition (the second "f"
3142 * If given a cursor for which there is no corresponding definition,
3143 * e.g., because there is no definition of that entity within this
3144 * translation unit, returns a NULL cursor.
3146 CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3149 * \brief Determine whether the declaration pointed to by this cursor
3150 * is also a definition of that entity.
3152 CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3155 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3157 * In the C family of languages, many kinds of entities can be declared several
3158 * times within a single translation unit. For example, a structure type can
3159 * be forward-declared (possibly multiple times) and later defined:
3169 * The declarations and the definition of \c X are represented by three
3170 * different cursors, all of which are declarations of the same underlying
3171 * entity. One of these cursor is considered the "canonical" cursor, which
3172 * is effectively the representative for the underlying entity. One can
3173 * determine if two cursors are declarations of the same underlying entity by
3174 * comparing their canonical cursors.
3176 * \returns The canonical cursor for the entity referred to by the given cursor.
3178 CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3182 * \brief If the cursor points to a selector identifier in a objc method or
3183 * message expression, this returns the selector index.
3185 * After getting a cursor with #clang_getCursor, this can be called to
3186 * determine if the location points to a selector identifier.
3188 * \returns The selector index if the cursor is an objc method or message
3189 * expression and the cursor is pointing to a selector identifier, or -1
3192 CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3195 * \brief Given a cursor pointing to a C++ method call or an ObjC message,
3196 * returns non-zero if the method/message is "dynamic", meaning:
3198 * For a C++ method: the call is virtual.
3199 * For an ObjC message: the receiver is an object instance, not 'super' or a
3202 * If the method/message is "static" or the cursor does not point to a
3203 * method/message, it will return zero.
3205 CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
3208 * \brief Given a cursor pointing to an ObjC message, returns the CXType of the
3211 CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
3214 * \brief Given a cursor that represents a declaration, return the associated
3215 * comment's source range. The range may include multiple consecutive comments
3216 * with whitespace in between.
3218 CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
3221 * \brief Given a cursor that represents a declaration, return the associated
3222 * comment text, including comment markers.
3224 CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
3227 * \brief Given a cursor that represents a documentable entity (e.g.,
3228 * declaration), return the associated \\brief paragraph; otherwise return the
3231 CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
3234 * \brief Given a cursor that represents a documentable entity (e.g.,
3235 * declaration), return the associated parsed comment as a
3236 * \c CXComment_FullComment AST node.
3238 CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
3245 * \defgroup CINDEX_MODULE Module introspection
3247 * The functions in this group provide access to information about modules.
3252 typedef void *CXModule;
3255 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
3257 CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
3260 * \param Module a module object.
3262 * \returns the parent of a sub-module or NULL if the given module is top-level,
3263 * e.g. for 'std.vector' it will return the 'std' module.
3265 CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
3268 * \param Module a module object.
3270 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
3271 * will return "vector".
3273 CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
3276 * \param Module a module object.
3278 * \returns the full name of the module, e.g. "std.vector".
3280 CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
3283 * \param Module a module object.
3285 * \returns the number of top level headers associated with this module.
3287 CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXModule Module);
3290 * \param Module a module object.
3292 * \param Index top level header index (zero-based).
3294 * \returns the specified top level header associated with the module.
3297 CXFile clang_Module_getTopLevelHeader(CXModule Module, unsigned Index);
3304 * \defgroup CINDEX_COMMENT Comment AST introspection
3306 * The routines in this group provide access to information in the
3307 * documentation comment ASTs.
3313 * \brief Describes the type of the comment AST node (\c CXComment). A comment
3314 * node can be considered block content (e. g., paragraph), inline content
3315 * (plain text) or neither (the root AST node).
3317 enum CXCommentKind {
3319 * \brief Null comment. No AST node is constructed at the requested location
3320 * because there is no text or a syntax error.
3325 * \brief Plain text. Inline content.
3330 * \brief A command with word-like arguments that is considered inline content.
3332 * For example: \\c command.
3334 CXComment_InlineCommand = 2,
3337 * \brief HTML start tag with attributes (name-value pairs). Considered
3342 * <br> <br /> <a href="http://example.org/">
3345 CXComment_HTMLStartTag = 3,
3348 * \brief HTML end tag. Considered inline content.
3355 CXComment_HTMLEndTag = 4,
3358 * \brief A paragraph, contains inline comment. The paragraph itself is
3361 CXComment_Paragraph = 5,
3364 * \brief A command that has zero or more word-like arguments (number of
3365 * word-like arguments depends on command name) and a paragraph as an
3366 * argument. Block command is block content.
3368 * Paragraph argument is also a child of the block command.
3370 * For example: \\brief has 0 word-like arguments and a paragraph argument.
3372 * AST nodes of special kinds that parser knows about (e. g., \\param
3373 * command) have their own node kinds.
3375 CXComment_BlockCommand = 6,
3378 * \brief A \\param or \\arg command that describes the function parameter
3379 * (name, passing direction, description).
3381 * For example: \\param [in] ParamName description.
3383 CXComment_ParamCommand = 7,
3386 * \brief A \\tparam command that describes a template parameter (name and
3389 * For example: \\tparam T description.
3391 CXComment_TParamCommand = 8,
3394 * \brief A verbatim block command (e. g., preformatted code). Verbatim
3395 * block has an opening and a closing command and contains multiple lines of
3396 * text (\c CXComment_VerbatimBlockLine child nodes).
3403 CXComment_VerbatimBlockCommand = 9,
3406 * \brief A line of text that is contained within a
3407 * CXComment_VerbatimBlockCommand node.
3409 CXComment_VerbatimBlockLine = 10,
3412 * \brief A verbatim line command. Verbatim line has an opening command,
3413 * a single line of text (up to the newline after the opening command) and
3414 * has no closing command.
3416 CXComment_VerbatimLine = 11,
3419 * \brief A full comment attached to a declaration, contains block content.
3421 CXComment_FullComment = 12
3425 * \brief The most appropriate rendering mode for an inline command, chosen on
3426 * command semantics in Doxygen.
3428 enum CXCommentInlineCommandRenderKind {
3430 * \brief Command argument should be rendered in a normal font.
3432 CXCommentInlineCommandRenderKind_Normal,
3435 * \brief Command argument should be rendered in a bold font.
3437 CXCommentInlineCommandRenderKind_Bold,
3440 * \brief Command argument should be rendered in a monospaced font.
3442 CXCommentInlineCommandRenderKind_Monospaced,
3445 * \brief Command argument should be rendered emphasized (typically italic
3448 CXCommentInlineCommandRenderKind_Emphasized
3452 * \brief Describes parameter passing direction for \\param or \\arg command.
3454 enum CXCommentParamPassDirection {
3456 * \brief The parameter is an input parameter.
3458 CXCommentParamPassDirection_In,
3461 * \brief The parameter is an output parameter.
3463 CXCommentParamPassDirection_Out,
3466 * \brief The parameter is an input and output parameter.
3468 CXCommentParamPassDirection_InOut
3472 * \param Comment AST node of any kind.
3474 * \returns the type of the AST node.
3476 CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
3479 * \param Comment AST node of any kind.
3481 * \returns number of children of the AST node.
3483 CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
3486 * \param Comment AST node of any kind.
3488 * \param ChildIdx child index (zero-based).
3490 * \returns the specified child of the AST node.
3493 CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
3496 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
3497 * only \c CXComment_Text nodes that are empty or whitespace.
3499 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
3500 * never considered whitespace.
3502 * \returns non-zero if \c Comment is whitespace.
3504 CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
3507 * \returns non-zero if \c Comment is inline content and has a newline
3508 * immediately following it in the comment text. Newlines between paragraphs
3512 unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
3515 * \param Comment a \c CXComment_Text AST node.
3517 * \returns text contained in the AST node.
3519 CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
3522 * \param Comment a \c CXComment_InlineCommand AST node.
3524 * \returns name of the inline command.
3527 CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
3530 * \param Comment a \c CXComment_InlineCommand AST node.
3532 * \returns the most appropriate rendering mode, chosen on command
3533 * semantics in Doxygen.
3535 CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
3536 clang_InlineCommandComment_getRenderKind(CXComment Comment);
3539 * \param Comment a \c CXComment_InlineCommand AST node.
3541 * \returns number of command arguments.
3544 unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
3547 * \param Comment a \c CXComment_InlineCommand AST node.
3549 * \param ArgIdx argument index (zero-based).
3551 * \returns text of the specified argument.
3554 CXString clang_InlineCommandComment_getArgText(CXComment Comment,
3558 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3561 * \returns HTML tag name.
3563 CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
3566 * \param Comment a \c CXComment_HTMLStartTag AST node.
3568 * \returns non-zero if tag is self-closing (for example, <br />).
3571 unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
3574 * \param Comment a \c CXComment_HTMLStartTag AST node.
3576 * \returns number of attributes (name-value pairs) attached to the start tag.
3578 CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
3581 * \param Comment a \c CXComment_HTMLStartTag AST node.
3583 * \param AttrIdx attribute index (zero-based).
3585 * \returns name of the specified attribute.
3588 CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
3591 * \param Comment a \c CXComment_HTMLStartTag AST node.
3593 * \param AttrIdx attribute index (zero-based).
3595 * \returns value of the specified attribute.
3598 CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
3601 * \param Comment a \c CXComment_BlockCommand AST node.
3603 * \returns name of the block command.
3606 CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
3609 * \param Comment a \c CXComment_BlockCommand AST node.
3611 * \returns number of word-like arguments.
3614 unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
3617 * \param Comment a \c CXComment_BlockCommand AST node.
3619 * \param ArgIdx argument index (zero-based).
3621 * \returns text of the specified word-like argument.
3624 CXString clang_BlockCommandComment_getArgText(CXComment Comment,
3628 * \param Comment a \c CXComment_BlockCommand or
3629 * \c CXComment_VerbatimBlockCommand AST node.
3631 * \returns paragraph argument of the block command.
3634 CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
3637 * \param Comment a \c CXComment_ParamCommand AST node.
3639 * \returns parameter name.
3642 CXString clang_ParamCommandComment_getParamName(CXComment Comment);
3645 * \param Comment a \c CXComment_ParamCommand AST node.
3647 * \returns non-zero if the parameter that this AST node represents was found
3648 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
3649 * function will return a meaningful value.
3652 unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
3655 * \param Comment a \c CXComment_ParamCommand AST node.
3657 * \returns zero-based parameter index in function prototype.
3660 unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
3663 * \param Comment a \c CXComment_ParamCommand AST node.
3665 * \returns non-zero if parameter passing direction was specified explicitly in
3669 unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
3672 * \param Comment a \c CXComment_ParamCommand AST node.
3674 * \returns parameter passing direction.
3677 enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
3681 * \param Comment a \c CXComment_TParamCommand AST node.
3683 * \returns template parameter name.
3686 CXString clang_TParamCommandComment_getParamName(CXComment Comment);
3689 * \param Comment a \c CXComment_TParamCommand AST node.
3691 * \returns non-zero if the parameter that this AST node represents was found
3692 * in the template parameter list and
3693 * \c clang_TParamCommandComment_getDepth and
3694 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
3698 unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
3701 * \param Comment a \c CXComment_TParamCommand AST node.
3703 * \returns zero-based nesting depth of this parameter in the template parameter list.
3707 * template<typename C, template<typename T> class TT>
3708 * void test(TT<int> aaa);
3710 * for C and TT nesting depth is 0,
3711 * for T nesting depth is 1.
3714 unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
3717 * \param Comment a \c CXComment_TParamCommand AST node.
3719 * \returns zero-based parameter index in the template parameter list at a
3720 * given nesting depth.
3724 * template<typename C, template<typename T> class TT>
3725 * void test(TT<int> aaa);
3727 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
3728 * at depth 0 C's index is 0, TT's index is 1.
3730 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
3731 * at depth 0 T's index is 1 (same as TT's),
3732 * at depth 1 T's index is 0.
3735 unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
3738 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
3740 * \returns text contained in the AST node.
3743 CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
3746 * \param Comment a \c CXComment_VerbatimLine AST node.
3748 * \returns text contained in the AST node.
3750 CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
3753 * \brief Convert an HTML tag AST node to string.
3755 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
3758 * \returns string containing an HTML tag.
3760 CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
3763 * \brief Convert a given full parsed comment to an HTML fragment.
3765 * Specific details of HTML layout are subject to change. Don't try to parse
3766 * this HTML back into an AST, use other APIs instead.
3768 * Currently the following CSS classes are used:
3769 * \li "para-brief" for \\brief paragraph and equivalent commands;
3770 * \li "para-returns" for \\returns paragraph and equivalent commands;
3771 * \li "word-returns" for the "Returns" word in \\returns paragraph.
3773 * Function argument documentation is rendered as a \<dl\> list with arguments
3774 * sorted in function prototype order. CSS classes used:
3775 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
3776 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
3777 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
3778 * parameter index is invalid.
3780 * Template parameter documentation is rendered as a \<dl\> list with
3781 * parameters sorted in template parameter list order. CSS classes used:
3782 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
3783 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
3784 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
3785 * names inside template template parameters;
3786 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
3787 * parameter position is invalid.
3789 * \param Comment a \c CXComment_FullComment AST node.
3791 * \returns string containing an HTML fragment.
3793 CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
3796 * \brief Convert a given full parsed comment to an XML document.
3798 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
3799 * inside clang source tree.
3801 * \param Comment a \c CXComment_FullComment AST node.
3803 * \returns string containing an XML document.
3805 CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
3812 * \defgroup CINDEX_CPP C++ AST introspection
3814 * The routines in this group provide access information in the ASTs specific
3815 * to C++ language features.
3821 * \brief Determine if a C++ member function or member function template is
3822 * declared 'static'.
3824 CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3827 * \brief Determine if a C++ member function or member function template is
3828 * explicitly declared 'virtual' or if it overrides a virtual method from
3829 * one of the base classes.
3831 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3834 * \brief Given a cursor that represents a template, determine
3835 * the cursor kind of the specializations would be generated by instantiating
3838 * This routine can be used to determine what flavor of function template,
3839 * class template, or class template partial specialization is stored in the
3840 * cursor. For example, it can describe whether a class template cursor is
3841 * declared with "struct", "class" or "union".
3843 * \param C The cursor to query. This cursor should represent a template
3846 * \returns The cursor kind of the specializations that would be generated
3847 * by instantiating the template \p C. If \p C is not a template, returns
3848 * \c CXCursor_NoDeclFound.
3850 CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3853 * \brief Given a cursor that may represent a specialization or instantiation
3854 * of a template, retrieve the cursor that represents the template that it
3855 * specializes or from which it was instantiated.
3857 * This routine determines the template involved both for explicit
3858 * specializations of templates and for implicit instantiations of the template,
3859 * both of which are referred to as "specializations". For a class template
3860 * specialization (e.g., \c std::vector<bool>), this routine will return
3861 * either the primary template (\c std::vector) or, if the specialization was
3862 * instantiated from a class template partial specialization, the class template
3863 * partial specialization. For a class template partial specialization and a
3864 * function template specialization (including instantiations), this
3865 * this routine will return the specialized template.
3867 * For members of a class template (e.g., member functions, member classes, or
3868 * static data members), returns the specialized or instantiated member.
3869 * Although not strictly "templates" in the C++ language, members of class
3870 * templates have the same notions of specializations and instantiations that
3871 * templates do, so this routine treats them similarly.
3873 * \param C A cursor that may be a specialization of a template or a member
3876 * \returns If the given cursor is a specialization or instantiation of a
3877 * template or a member thereof, the template or member that it specializes or
3878 * from which it was instantiated. Otherwise, returns a NULL cursor.
3880 CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
3883 * \brief Given a cursor that references something else, return the source range
3884 * covering that reference.
3886 * \param C A cursor pointing to a member reference, a declaration reference, or
3888 * \param NameFlags A bitset with three independent flags:
3889 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3890 * CXNameRange_WantSinglePiece.
3891 * \param PieceIndex For contiguous names or when passing the flag
3892 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3893 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
3894 * non-contiguous names, this index can be used to retrieve the individual
3895 * pieces of the name. See also CXNameRange_WantSinglePiece.
3897 * \returns The piece of the name pointed to by the given cursor. If there is no
3898 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3900 CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3902 unsigned PieceIndex);
3904 enum CXNameRefFlags {
3906 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3909 CXNameRange_WantQualifier = 0x1,
3912 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
3915 CXNameRange_WantTemplateArgs = 0x2,
3918 * \brief If the name is non-contiguous, return the full spanning range.
3920 * Non-contiguous names occur in Objective-C when a selector with two or more
3921 * parameters is used, or in C++ when using an operator:
3923 * [object doSomething:here withValue:there]; // ObjC
3924 * return some_vector[1]; // C++
3927 CXNameRange_WantSinglePiece = 0x4
3935 * \defgroup CINDEX_LEX Token extraction and manipulation
3937 * The routines in this group provide access to the tokens within a
3938 * translation unit, along with a semantic mapping of those tokens to
3939 * their corresponding cursors.
3945 * \brief Describes a kind of token.
3947 typedef enum CXTokenKind {
3949 * \brief A token that contains some kind of punctuation.
3951 CXToken_Punctuation,
3954 * \brief A language keyword.
3959 * \brief An identifier (that is not a keyword).
3964 * \brief A numeric, string, or character literal.
3975 * \brief Describes a single preprocessing token.
3978 unsigned int_data[4];
3983 * \brief Determine the kind of the given token.
3985 CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
3988 * \brief Determine the spelling of the given token.
3990 * The spelling of a token is the textual representation of that token, e.g.,
3991 * the text of an identifier or keyword.
3993 CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
3996 * \brief Retrieve the source location of the given token.
3998 CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
4002 * \brief Retrieve a source range that covers the given token.
4004 CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4007 * \brief Tokenize the source code described by the given range into raw
4010 * \param TU the translation unit whose text is being tokenized.
4012 * \param Range the source range in which text should be tokenized. All of the
4013 * tokens produced by tokenization will fall within this source range,
4015 * \param Tokens this pointer will be set to point to the array of tokens
4016 * that occur within the given source range. The returned pointer must be
4017 * freed with clang_disposeTokens() before the translation unit is destroyed.
4019 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4023 CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4024 CXToken **Tokens, unsigned *NumTokens);
4027 * \brief Annotate the given set of tokens by providing cursors for each token
4028 * that can be mapped to a specific entity within the abstract syntax tree.
4030 * This token-annotation routine is equivalent to invoking
4031 * clang_getCursor() for the source locations of each of the
4032 * tokens. The cursors provided are filtered, so that only those
4033 * cursors that have a direct correspondence to the token are
4034 * accepted. For example, given a function call \c f(x),
4035 * clang_getCursor() would provide the following cursors:
4037 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4038 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4039 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4041 * Only the first and last of these cursors will occur within the
4042 * annotate, since the tokens "f" and "x' directly refer to a function
4043 * and a variable, respectively, but the parentheses are just a small
4044 * part of the full syntax of the function call expression, which is
4045 * not provided as an annotation.
4047 * \param TU the translation unit that owns the given tokens.
4049 * \param Tokens the set of tokens to annotate.
4051 * \param NumTokens the number of tokens in \p Tokens.
4053 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4054 * replaced with the cursors corresponding to each token.
4056 CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4057 CXToken *Tokens, unsigned NumTokens,
4061 * \brief Free the given set of tokens.
4063 CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
4064 CXToken *Tokens, unsigned NumTokens);
4071 * \defgroup CINDEX_DEBUG Debugging facilities
4073 * These routines are used for testing and debugging, only, and should not
4079 /* for debug/testing */
4080 CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
4081 CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4082 const char **startBuf,
4083 const char **endBuf,
4084 unsigned *startLine,
4085 unsigned *startColumn,
4087 unsigned *endColumn);
4088 CINDEX_LINKAGE void clang_enableStackTraces(void);
4089 CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4090 unsigned stack_size);
4097 * \defgroup CINDEX_CODE_COMPLET Code completion
4099 * Code completion involves taking an (incomplete) source file, along with
4100 * knowledge of where the user is actively editing that file, and suggesting
4101 * syntactically- and semantically-valid constructs that the user might want to
4102 * use at that particular point in the source code. These data structures and
4103 * routines provide support for code completion.
4109 * \brief A semantic string that describes a code-completion result.
4111 * A semantic string that describes the formatting of a code-completion
4112 * result as a single "template" of text that should be inserted into the
4113 * source buffer when a particular code-completion result is selected.
4114 * Each semantic string is made up of some number of "chunks", each of which
4115 * contains some text along with a description of what that text means, e.g.,
4116 * the name of the entity being referenced, whether the text chunk is part of
4117 * the template, or whether it is a "placeholder" that the user should replace
4118 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
4119 * description of the different kinds of chunks.
4121 typedef void *CXCompletionString;
4124 * \brief A single result of code completion.
4128 * \brief The kind of entity that this completion refers to.
4130 * The cursor kind will be a macro, keyword, or a declaration (one of the
4131 * *Decl cursor kinds), describing the entity that the completion is
4134 * \todo In the future, we would like to provide a full cursor, to allow
4135 * the client to extract additional information from declaration.
4137 enum CXCursorKind CursorKind;
4140 * \brief The code-completion string that describes how to insert this
4141 * code-completion result into the editing buffer.
4143 CXCompletionString CompletionString;
4144 } CXCompletionResult;
4147 * \brief Describes a single piece of text within a code-completion string.
4149 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4150 * either a piece of text with a specific "kind" that describes how that text
4151 * should be interpreted by the client or is another completion string.
4153 enum CXCompletionChunkKind {
4155 * \brief A code-completion string that describes "optional" text that
4156 * could be a part of the template (but is not required).
4158 * The Optional chunk is the only kind of chunk that has a code-completion
4159 * string for its representation, which is accessible via
4160 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4161 * describes an additional part of the template that is completely optional.
4162 * For example, optional chunks can be used to describe the placeholders for
4163 * arguments that match up with defaulted function parameters, e.g. given:
4166 * void f(int x, float y = 3.14, double z = 2.71828);
4169 * The code-completion string for this function would contain:
4170 * - a TypedText chunk for "f".
4171 * - a LeftParen chunk for "(".
4172 * - a Placeholder chunk for "int x"
4173 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4174 * - a Comma chunk for ","
4175 * - a Placeholder chunk for "float y"
4176 * - an Optional chunk containing the last defaulted argument:
4177 * - a Comma chunk for ","
4178 * - a Placeholder chunk for "double z"
4179 * - a RightParen chunk for ")"
4181 * There are many ways to handle Optional chunks. Two simple approaches are:
4182 * - Completely ignore optional chunks, in which case the template for the
4183 * function "f" would only include the first parameter ("int x").
4184 * - Fully expand all optional chunks, in which case the template for the
4185 * function "f" would have all of the parameters.
4187 CXCompletionChunk_Optional,
4189 * \brief Text that a user would be expected to type to get this
4190 * code-completion result.
4192 * There will be exactly one "typed text" chunk in a semantic string, which
4193 * will typically provide the spelling of a keyword or the name of a
4194 * declaration that could be used at the current code point. Clients are
4195 * expected to filter the code-completion results based on the text in this
4198 CXCompletionChunk_TypedText,
4200 * \brief Text that should be inserted as part of a code-completion result.
4202 * A "text" chunk represents text that is part of the template to be
4203 * inserted into user code should this particular code-completion result
4206 CXCompletionChunk_Text,
4208 * \brief Placeholder text that should be replaced by the user.
4210 * A "placeholder" chunk marks a place where the user should insert text
4211 * into the code-completion template. For example, placeholders might mark
4212 * the function parameters for a function declaration, to indicate that the
4213 * user should provide arguments for each of those parameters. The actual
4214 * text in a placeholder is a suggestion for the text to display before
4215 * the user replaces the placeholder with real code.
4217 CXCompletionChunk_Placeholder,
4219 * \brief Informative text that should be displayed but never inserted as
4220 * part of the template.
4222 * An "informative" chunk contains annotations that can be displayed to
4223 * help the user decide whether a particular code-completion result is the
4224 * right option, but which is not part of the actual template to be inserted
4225 * by code completion.
4227 CXCompletionChunk_Informative,
4229 * \brief Text that describes the current parameter when code-completion is
4230 * referring to function call, message send, or template specialization.
4232 * A "current parameter" chunk occurs when code-completion is providing
4233 * information about a parameter corresponding to the argument at the
4234 * code-completion point. For example, given a function
4237 * int add(int x, int y);
4240 * and the source code \c add(, where the code-completion point is after the
4241 * "(", the code-completion string will contain a "current parameter" chunk
4242 * for "int x", indicating that the current argument will initialize that
4243 * parameter. After typing further, to \c add(17, (where the code-completion
4244 * point is after the ","), the code-completion string will contain a
4245 * "current paremeter" chunk to "int y".
4247 CXCompletionChunk_CurrentParameter,
4249 * \brief A left parenthesis ('('), used to initiate a function call or
4250 * signal the beginning of a function parameter list.
4252 CXCompletionChunk_LeftParen,
4254 * \brief A right parenthesis (')'), used to finish a function call or
4255 * signal the end of a function parameter list.
4257 CXCompletionChunk_RightParen,
4259 * \brief A left bracket ('[').
4261 CXCompletionChunk_LeftBracket,
4263 * \brief A right bracket (']').
4265 CXCompletionChunk_RightBracket,
4267 * \brief A left brace ('{').
4269 CXCompletionChunk_LeftBrace,
4271 * \brief A right brace ('}').
4273 CXCompletionChunk_RightBrace,
4275 * \brief A left angle bracket ('<').
4277 CXCompletionChunk_LeftAngle,
4279 * \brief A right angle bracket ('>').
4281 CXCompletionChunk_RightAngle,
4283 * \brief A comma separator (',').
4285 CXCompletionChunk_Comma,
4287 * \brief Text that specifies the result type of a given result.
4289 * This special kind of informative chunk is not meant to be inserted into
4290 * the text buffer. Rather, it is meant to illustrate the type that an
4291 * expression using the given completion string would have.
4293 CXCompletionChunk_ResultType,
4295 * \brief A colon (':').
4297 CXCompletionChunk_Colon,
4299 * \brief A semicolon (';').
4301 CXCompletionChunk_SemiColon,
4303 * \brief An '=' sign.
4305 CXCompletionChunk_Equal,
4307 * Horizontal space (' ').
4309 CXCompletionChunk_HorizontalSpace,
4311 * Vertical space ('\n'), after which it is generally a good idea to
4312 * perform indentation.
4314 CXCompletionChunk_VerticalSpace
4318 * \brief Determine the kind of a particular chunk within a completion string.
4320 * \param completion_string the completion string to query.
4322 * \param chunk_number the 0-based index of the chunk in the completion string.
4324 * \returns the kind of the chunk at the index \c chunk_number.
4326 CINDEX_LINKAGE enum CXCompletionChunkKind
4327 clang_getCompletionChunkKind(CXCompletionString completion_string,
4328 unsigned chunk_number);
4331 * \brief Retrieve the text associated with a particular chunk within a
4332 * completion string.
4334 * \param completion_string the completion string to query.
4336 * \param chunk_number the 0-based index of the chunk in the completion string.
4338 * \returns the text associated with the chunk at index \c chunk_number.
4340 CINDEX_LINKAGE CXString
4341 clang_getCompletionChunkText(CXCompletionString completion_string,
4342 unsigned chunk_number);
4345 * \brief Retrieve the completion string associated with a particular chunk
4346 * within a completion string.
4348 * \param completion_string the completion string to query.
4350 * \param chunk_number the 0-based index of the chunk in the completion string.
4352 * \returns the completion string associated with the chunk at index
4355 CINDEX_LINKAGE CXCompletionString
4356 clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
4357 unsigned chunk_number);
4360 * \brief Retrieve the number of chunks in the given code-completion string.
4362 CINDEX_LINKAGE unsigned
4363 clang_getNumCompletionChunks(CXCompletionString completion_string);
4366 * \brief Determine the priority of this code completion.
4368 * The priority of a code completion indicates how likely it is that this
4369 * particular completion is the completion that the user will select. The
4370 * priority is selected by various internal heuristics.
4372 * \param completion_string The completion string to query.
4374 * \returns The priority of this completion string. Smaller values indicate
4375 * higher-priority (more likely) completions.
4377 CINDEX_LINKAGE unsigned
4378 clang_getCompletionPriority(CXCompletionString completion_string);
4381 * \brief Determine the availability of the entity that this code-completion
4384 * \param completion_string The completion string to query.
4386 * \returns The availability of the completion string.
4388 CINDEX_LINKAGE enum CXAvailabilityKind
4389 clang_getCompletionAvailability(CXCompletionString completion_string);
4392 * \brief Retrieve the number of annotations associated with the given
4393 * completion string.
4395 * \param completion_string the completion string to query.
4397 * \returns the number of annotations associated with the given completion
4400 CINDEX_LINKAGE unsigned
4401 clang_getCompletionNumAnnotations(CXCompletionString completion_string);
4404 * \brief Retrieve the annotation associated with the given completion string.
4406 * \param completion_string the completion string to query.
4408 * \param annotation_number the 0-based index of the annotation of the
4409 * completion string.
4411 * \returns annotation string associated with the completion at index
4412 * \c annotation_number, or a NULL string if that annotation is not available.
4414 CINDEX_LINKAGE CXString
4415 clang_getCompletionAnnotation(CXCompletionString completion_string,
4416 unsigned annotation_number);
4419 * \brief Retrieve the parent context of the given completion string.
4421 * The parent context of a completion string is the semantic parent of
4422 * the declaration (if any) that the code completion represents. For example,
4423 * a code completion for an Objective-C method would have the method's class
4424 * or protocol as its context.
4426 * \param completion_string The code completion string whose parent is
4429 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
4431 * \returns The name of the completion parent, e.g., "NSObject" if
4432 * the completion string represents a method in the NSObject class.
4434 CINDEX_LINKAGE CXString
4435 clang_getCompletionParent(CXCompletionString completion_string,
4436 enum CXCursorKind *kind);
4439 * \brief Retrieve the brief documentation comment attached to the declaration
4440 * that corresponds to the given completion string.
4442 CINDEX_LINKAGE CXString
4443 clang_getCompletionBriefComment(CXCompletionString completion_string);
4446 * \brief Retrieve a completion string for an arbitrary declaration or macro
4447 * definition cursor.
4449 * \param cursor The cursor to query.
4451 * \returns A non-context-sensitive completion string for declaration and macro
4452 * definition cursors, or NULL for other kinds of cursors.
4454 CINDEX_LINKAGE CXCompletionString
4455 clang_getCursorCompletionString(CXCursor cursor);
4458 * \brief Contains the results of code-completion.
4460 * This data structure contains the results of code completion, as
4461 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
4462 * \c clang_disposeCodeCompleteResults.
4466 * \brief The code-completion results.
4468 CXCompletionResult *Results;
4471 * \brief The number of code-completion results stored in the
4474 unsigned NumResults;
4475 } CXCodeCompleteResults;
4478 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
4479 * modify its behavior.
4481 * The enumerators in this enumeration can be bitwise-OR'd together to
4482 * provide multiple options to \c clang_codeCompleteAt().
4484 enum CXCodeComplete_Flags {
4486 * \brief Whether to include macros within the set of code
4487 * completions returned.
4489 CXCodeComplete_IncludeMacros = 0x01,
4492 * \brief Whether to include code patterns for language constructs
4493 * within the set of code completions, e.g., for loops.
4495 CXCodeComplete_IncludeCodePatterns = 0x02,
4498 * \brief Whether to include brief documentation within the set of code
4499 * completions returned.
4501 CXCodeComplete_IncludeBriefComments = 0x04
4505 * \brief Bits that represent the context under which completion is occurring.
4507 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
4508 * contexts are occurring simultaneously.
4510 enum CXCompletionContext {
4512 * \brief The context for completions is unexposed, as only Clang results
4513 * should be included. (This is equivalent to having no context bits set.)
4515 CXCompletionContext_Unexposed = 0,
4518 * \brief Completions for any possible type should be included in the results.
4520 CXCompletionContext_AnyType = 1 << 0,
4523 * \brief Completions for any possible value (variables, function calls, etc.)
4524 * should be included in the results.
4526 CXCompletionContext_AnyValue = 1 << 1,
4528 * \brief Completions for values that resolve to an Objective-C object should
4529 * be included in the results.
4531 CXCompletionContext_ObjCObjectValue = 1 << 2,
4533 * \brief Completions for values that resolve to an Objective-C selector
4534 * should be included in the results.
4536 CXCompletionContext_ObjCSelectorValue = 1 << 3,
4538 * \brief Completions for values that resolve to a C++ class type should be
4539 * included in the results.
4541 CXCompletionContext_CXXClassTypeValue = 1 << 4,
4544 * \brief Completions for fields of the member being accessed using the dot
4545 * operator should be included in the results.
4547 CXCompletionContext_DotMemberAccess = 1 << 5,
4549 * \brief Completions for fields of the member being accessed using the arrow
4550 * operator should be included in the results.
4552 CXCompletionContext_ArrowMemberAccess = 1 << 6,
4554 * \brief Completions for properties of the Objective-C object being accessed
4555 * using the dot operator should be included in the results.
4557 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
4560 * \brief Completions for enum tags should be included in the results.
4562 CXCompletionContext_EnumTag = 1 << 8,
4564 * \brief Completions for union tags should be included in the results.
4566 CXCompletionContext_UnionTag = 1 << 9,
4568 * \brief Completions for struct tags should be included in the results.
4570 CXCompletionContext_StructTag = 1 << 10,
4573 * \brief Completions for C++ class names should be included in the results.
4575 CXCompletionContext_ClassTag = 1 << 11,
4577 * \brief Completions for C++ namespaces and namespace aliases should be
4578 * included in the results.
4580 CXCompletionContext_Namespace = 1 << 12,
4582 * \brief Completions for C++ nested name specifiers should be included in
4585 CXCompletionContext_NestedNameSpecifier = 1 << 13,
4588 * \brief Completions for Objective-C interfaces (classes) should be included
4591 CXCompletionContext_ObjCInterface = 1 << 14,
4593 * \brief Completions for Objective-C protocols should be included in
4596 CXCompletionContext_ObjCProtocol = 1 << 15,
4598 * \brief Completions for Objective-C categories should be included in
4601 CXCompletionContext_ObjCCategory = 1 << 16,
4603 * \brief Completions for Objective-C instance messages should be included
4606 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
4608 * \brief Completions for Objective-C class messages should be included in
4611 CXCompletionContext_ObjCClassMessage = 1 << 18,
4613 * \brief Completions for Objective-C selector names should be included in
4616 CXCompletionContext_ObjCSelectorName = 1 << 19,
4619 * \brief Completions for preprocessor macro names should be included in
4622 CXCompletionContext_MacroName = 1 << 20,
4625 * \brief Natural language completions should be included in the results.
4627 CXCompletionContext_NaturalLanguage = 1 << 21,
4630 * \brief The current context is unknown, so set all contexts.
4632 CXCompletionContext_Unknown = ((1 << 22) - 1)
4636 * \brief Returns a default set of code-completion options that can be
4637 * passed to\c clang_codeCompleteAt().
4639 CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
4642 * \brief Perform code completion at a given location in a translation unit.
4644 * This function performs code completion at a particular file, line, and
4645 * column within source code, providing results that suggest potential
4646 * code snippets based on the context of the completion. The basic model
4647 * for code completion is that Clang will parse a complete source file,
4648 * performing syntax checking up to the location where code-completion has
4649 * been requested. At that point, a special code-completion token is passed
4650 * to the parser, which recognizes this token and determines, based on the
4651 * current location in the C/Objective-C/C++ grammar and the state of
4652 * semantic analysis, what completions to provide. These completions are
4653 * returned via a new \c CXCodeCompleteResults structure.
4655 * Code completion itself is meant to be triggered by the client when the
4656 * user types punctuation characters or whitespace, at which point the
4657 * code-completion location will coincide with the cursor. For example, if \c p
4658 * is a pointer, code-completion might be triggered after the "-" and then
4659 * after the ">" in \c p->. When the code-completion location is afer the ">",
4660 * the completion results will provide, e.g., the members of the struct that
4661 * "p" points to. The client is responsible for placing the cursor at the
4662 * beginning of the token currently being typed, then filtering the results
4663 * based on the contents of the token. For example, when code-completing for
4664 * the expression \c p->get, the client should provide the location just after
4665 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
4666 * client can filter the results based on the current token text ("get"), only
4667 * showing those results that start with "get". The intent of this interface
4668 * is to separate the relatively high-latency acquisition of code-completion
4669 * results from the filtering of results on a per-character basis, which must
4670 * have a lower latency.
4672 * \param TU The translation unit in which code-completion should
4673 * occur. The source files for this translation unit need not be
4674 * completely up-to-date (and the contents of those source files may
4675 * be overridden via \p unsaved_files). Cursors referring into the
4676 * translation unit may be invalidated by this invocation.
4678 * \param complete_filename The name of the source file where code
4679 * completion should be performed. This filename may be any file
4680 * included in the translation unit.
4682 * \param complete_line The line at which code-completion should occur.
4684 * \param complete_column The column at which code-completion should occur.
4685 * Note that the column should point just after the syntactic construct that
4686 * initiated code completion, and not in the middle of a lexical token.
4688 * \param unsaved_files the Tiles that have not yet been saved to disk
4689 * but may be required for parsing or code completion, including the
4690 * contents of those files. The contents and name of these files (as
4691 * specified by CXUnsavedFile) are copied when necessary, so the
4692 * client only needs to guarantee their validity until the call to
4693 * this function returns.
4695 * \param num_unsaved_files The number of unsaved file entries in \p
4698 * \param options Extra options that control the behavior of code
4699 * completion, expressed as a bitwise OR of the enumerators of the
4700 * CXCodeComplete_Flags enumeration. The
4701 * \c clang_defaultCodeCompleteOptions() function returns a default set
4702 * of code-completion options.
4704 * \returns If successful, a new \c CXCodeCompleteResults structure
4705 * containing code-completion results, which should eventually be
4706 * freed with \c clang_disposeCodeCompleteResults(). If code
4707 * completion fails, returns NULL.
4710 CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
4711 const char *complete_filename,
4712 unsigned complete_line,
4713 unsigned complete_column,
4714 struct CXUnsavedFile *unsaved_files,
4715 unsigned num_unsaved_files,
4719 * \brief Sort the code-completion results in case-insensitive alphabetical
4722 * \param Results The set of results to sort.
4723 * \param NumResults The number of results in \p Results.
4726 void clang_sortCodeCompletionResults(CXCompletionResult *Results,
4727 unsigned NumResults);
4730 * \brief Free the given set of code-completion results.
4733 void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
4736 * \brief Determine the number of diagnostics produced prior to the
4737 * location where code completion was performed.
4740 unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
4743 * \brief Retrieve a diagnostic associated with the given code completion.
4745 * \param Results the code completion results to query.
4746 * \param Index the zero-based diagnostic number to retrieve.
4748 * \returns the requested diagnostic. This diagnostic must be freed
4749 * via a call to \c clang_disposeDiagnostic().
4752 CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4756 * \brief Determines what compeltions are appropriate for the context
4757 * the given code completion.
4759 * \param Results the code completion results to query
4761 * \returns the kinds of completions that are appropriate for use
4762 * along with the given code completion results.
4765 unsigned long long clang_codeCompleteGetContexts(
4766 CXCodeCompleteResults *Results);
4769 * \brief Returns the cursor kind for the container for the current code
4770 * completion context. The container is only guaranteed to be set for
4771 * contexts where a container exists (i.e. member accesses or Objective-C
4772 * message sends); if there is not a container, this function will return
4773 * CXCursor_InvalidCode.
4775 * \param Results the code completion results to query
4777 * \param IsIncomplete on return, this value will be false if Clang has complete
4778 * information about the container. If Clang does not have complete
4779 * information, this value will be true.
4781 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4785 enum CXCursorKind clang_codeCompleteGetContainerKind(
4786 CXCodeCompleteResults *Results,
4787 unsigned *IsIncomplete);
4790 * \brief Returns the USR for the container for the current code completion
4791 * context. If there is not a container for the current context, this
4792 * function will return the empty string.
4794 * \param Results the code completion results to query
4796 * \returns the USR for the container
4799 CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
4803 * \brief Returns the currently-entered selector for an Objective-C message
4804 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4805 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4806 * CXCompletionContext_ObjCClassMessage.
4808 * \param Results the code completion results to query
4810 * \returns the selector (or partial selector) that has been entered thus far
4811 * for an Objective-C message send.
4814 CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4822 * \defgroup CINDEX_MISC Miscellaneous utility functions
4828 * \brief Return a version string, suitable for showing to a user, but not
4829 * intended to be parsed (the format is not guaranteed to be stable).
4831 CINDEX_LINKAGE CXString clang_getClangVersion();
4835 * \brief Enable/disable crash recovery.
4837 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
4838 * value enables crash recovery, while 0 disables it.
4840 CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4843 * \brief Visitor invoked for each file in a translation unit
4844 * (used with clang_getInclusions()).
4846 * This visitor function will be invoked by clang_getInclusions() for each
4847 * file included (either at the top-level or by \#include directives) within
4848 * a translation unit. The first argument is the file being included, and
4849 * the second and third arguments provide the inclusion stack. The
4850 * array is sorted in order of immediate inclusion. For example,
4851 * the first element refers to the location that included 'included_file'.
4853 typedef void (*CXInclusionVisitor)(CXFile included_file,
4854 CXSourceLocation* inclusion_stack,
4855 unsigned include_len,
4856 CXClientData client_data);
4859 * \brief Visit the set of preprocessor inclusions in a translation unit.
4860 * The visitor function is called with the provided data for every included
4861 * file. This does not include headers included by the PCH file (unless one
4862 * is inspecting the inclusions in the PCH file itself).
4864 CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4865 CXInclusionVisitor visitor,
4866 CXClientData client_data);
4872 /** \defgroup CINDEX_REMAPPING Remapping functions
4878 * \brief A remapping of original source files and their translated files.
4880 typedef void *CXRemapping;
4883 * \brief Retrieve a remapping.
4885 * \param path the path that contains metadata about remappings.
4887 * \returns the requested remapping. This remapping must be freed
4888 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4890 CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4893 * \brief Retrieve a remapping.
4895 * \param filePaths pointer to an array of file paths containing remapping info.
4897 * \param numFiles number of file paths.
4899 * \returns the requested remapping. This remapping must be freed
4900 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4903 CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4907 * \brief Determine the number of remappings.
4909 CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4912 * \brief Get the original and the associated filename from the remapping.
4914 * \param original If non-NULL, will be set to the original filename.
4916 * \param transformed If non-NULL, will be set to the filename that the original
4917 * is associated with.
4919 CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4920 CXString *original, CXString *transformed);
4923 * \brief Dispose the remapping.
4925 CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4931 /** \defgroup CINDEX_HIGH Higher level API functions
4936 enum CXVisitorResult {
4943 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4944 } CXCursorAndRangeVisitor;
4947 * \brief Find references of a declaration in a specific file.
4949 * \param cursor pointing to a declaration or a reference of one.
4951 * \param file to search for references.
4953 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4954 * each reference found.
4955 * The CXSourceRange will point inside the file; if the reference is inside
4956 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4958 CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4959 CXCursorAndRangeVisitor visitor);
4961 #ifdef __has_feature
4962 # if __has_feature(blocks)
4964 typedef enum CXVisitorResult
4965 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4968 void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4969 CXCursorAndRangeVisitorBlock);
4975 * \brief The client's data object that is associated with a CXFile.
4977 typedef void *CXIdxClientFile;
4980 * \brief The client's data object that is associated with a semantic entity.
4982 typedef void *CXIdxClientEntity;
4985 * \brief The client's data object that is associated with a semantic container
4988 typedef void *CXIdxClientContainer;
4991 * \brief The client's data object that is associated with an AST file (PCH
4994 typedef void *CXIdxClientASTFile;
4997 * \brief Source location passed to index callbacks.
5005 * \brief Data for ppIncludedFile callback.
5009 * \brief Location of '#' in the \#include/\#import directive.
5013 * \brief Filename as written in the \#include/\#import directive.
5015 const char *filename;
5017 * \brief The actual file that the \#include/\#import directive resolved to.
5023 * \brief Non-zero if the directive was automatically turned into a module
5027 } CXIdxIncludedFileInfo;
5030 * \brief Data for IndexerCallbacks#importedASTFile.
5034 * \brief Top level AST file containing the imported PCH, module or submodule.
5038 * \brief The imported module or NULL if the AST file is a PCH.
5042 * \brief Location where the file is imported. Applicable only for modules.
5046 * \brief Non-zero if an inclusion directive was automatically turned into
5047 * a module import. Applicable only for modules.
5051 } CXIdxImportedASTFileInfo;
5054 CXIdxEntity_Unexposed = 0,
5055 CXIdxEntity_Typedef = 1,
5056 CXIdxEntity_Function = 2,
5057 CXIdxEntity_Variable = 3,
5058 CXIdxEntity_Field = 4,
5059 CXIdxEntity_EnumConstant = 5,
5061 CXIdxEntity_ObjCClass = 6,
5062 CXIdxEntity_ObjCProtocol = 7,
5063 CXIdxEntity_ObjCCategory = 8,
5065 CXIdxEntity_ObjCInstanceMethod = 9,
5066 CXIdxEntity_ObjCClassMethod = 10,
5067 CXIdxEntity_ObjCProperty = 11,
5068 CXIdxEntity_ObjCIvar = 12,
5070 CXIdxEntity_Enum = 13,
5071 CXIdxEntity_Struct = 14,
5072 CXIdxEntity_Union = 15,
5074 CXIdxEntity_CXXClass = 16,
5075 CXIdxEntity_CXXNamespace = 17,
5076 CXIdxEntity_CXXNamespaceAlias = 18,
5077 CXIdxEntity_CXXStaticVariable = 19,
5078 CXIdxEntity_CXXStaticMethod = 20,
5079 CXIdxEntity_CXXInstanceMethod = 21,
5080 CXIdxEntity_CXXConstructor = 22,
5081 CXIdxEntity_CXXDestructor = 23,
5082 CXIdxEntity_CXXConversionFunction = 24,
5083 CXIdxEntity_CXXTypeAlias = 25,
5084 CXIdxEntity_CXXInterface = 26
5089 CXIdxEntityLang_None = 0,
5090 CXIdxEntityLang_C = 1,
5091 CXIdxEntityLang_ObjC = 2,
5092 CXIdxEntityLang_CXX = 3
5093 } CXIdxEntityLanguage;
5096 * \brief Extra C++ template information for an entity. This can apply to:
5097 * CXIdxEntity_Function
5098 * CXIdxEntity_CXXClass
5099 * CXIdxEntity_CXXStaticMethod
5100 * CXIdxEntity_CXXInstanceMethod
5101 * CXIdxEntity_CXXConstructor
5102 * CXIdxEntity_CXXConversionFunction
5103 * CXIdxEntity_CXXTypeAlias
5106 CXIdxEntity_NonTemplate = 0,
5107 CXIdxEntity_Template = 1,
5108 CXIdxEntity_TemplatePartialSpecialization = 2,
5109 CXIdxEntity_TemplateSpecialization = 3
5110 } CXIdxEntityCXXTemplateKind;
5113 CXIdxAttr_Unexposed = 0,
5114 CXIdxAttr_IBAction = 1,
5115 CXIdxAttr_IBOutlet = 2,
5116 CXIdxAttr_IBOutletCollection = 3
5126 CXIdxEntityKind kind;
5127 CXIdxEntityCXXTemplateKind templateKind;
5128 CXIdxEntityLanguage lang;
5132 const CXIdxAttrInfo *const *attributes;
5133 unsigned numAttributes;
5138 } CXIdxContainerInfo;
5141 const CXIdxAttrInfo *attrInfo;
5142 const CXIdxEntityInfo *objcClass;
5143 CXCursor classCursor;
5145 } CXIdxIBOutletCollectionAttrInfo;
5148 const CXIdxEntityInfo *entityInfo;
5151 const CXIdxContainerInfo *semanticContainer;
5153 * \brief Generally same as #semanticContainer but can be different in
5154 * cases like out-of-line C++ member functions.
5156 const CXIdxContainerInfo *lexicalContainer;
5157 int isRedeclaration;
5160 const CXIdxContainerInfo *declAsContainer;
5162 * \brief Whether the declaration exists in code or was created implicitly
5163 * by the compiler, e.g. implicit objc methods for properties.
5166 const CXIdxAttrInfo *const *attributes;
5167 unsigned numAttributes;
5171 CXIdxObjCContainer_ForwardRef = 0,
5172 CXIdxObjCContainer_Interface = 1,
5173 CXIdxObjCContainer_Implementation = 2
5174 } CXIdxObjCContainerKind;
5177 const CXIdxDeclInfo *declInfo;
5178 CXIdxObjCContainerKind kind;
5179 } CXIdxObjCContainerDeclInfo;
5182 const CXIdxEntityInfo *base;
5185 } CXIdxBaseClassInfo;
5188 const CXIdxEntityInfo *protocol;
5191 } CXIdxObjCProtocolRefInfo;
5194 const CXIdxObjCProtocolRefInfo *const *protocols;
5195 unsigned numProtocols;
5196 } CXIdxObjCProtocolRefListInfo;
5199 const CXIdxObjCContainerDeclInfo *containerInfo;
5200 const CXIdxBaseClassInfo *superInfo;
5201 const CXIdxObjCProtocolRefListInfo *protocols;
5202 } CXIdxObjCInterfaceDeclInfo;
5205 const CXIdxObjCContainerDeclInfo *containerInfo;
5206 const CXIdxEntityInfo *objcClass;
5207 CXCursor classCursor;
5209 const CXIdxObjCProtocolRefListInfo *protocols;
5210 } CXIdxObjCCategoryDeclInfo;
5213 const CXIdxDeclInfo *declInfo;
5214 const CXIdxEntityInfo *getter;
5215 const CXIdxEntityInfo *setter;
5216 } CXIdxObjCPropertyDeclInfo;
5219 const CXIdxDeclInfo *declInfo;
5220 const CXIdxBaseClassInfo *const *bases;
5222 } CXIdxCXXClassDeclInfo;
5225 * \brief Data for IndexerCallbacks#indexEntityReference.
5229 * \brief The entity is referenced directly in user's code.
5231 CXIdxEntityRef_Direct = 1,
5233 * \brief An implicit reference, e.g. a reference of an ObjC method via the
5236 CXIdxEntityRef_Implicit = 2
5237 } CXIdxEntityRefKind;
5240 * \brief Data for IndexerCallbacks#indexEntityReference.
5243 CXIdxEntityRefKind kind;
5245 * \brief Reference cursor.
5250 * \brief The entity that gets referenced.
5252 const CXIdxEntityInfo *referencedEntity;
5254 * \brief Immediate "parent" of the reference. For example:
5260 * The parent of reference of type 'Foo' is the variable 'var'.
5261 * For references inside statement bodies of functions/methods,
5262 * the parentEntity will be the function/method.
5264 const CXIdxEntityInfo *parentEntity;
5266 * \brief Lexical container context of the reference.
5268 const CXIdxContainerInfo *container;
5269 } CXIdxEntityRefInfo;
5272 * \brief A group of callbacks used by #clang_indexSourceFile and
5273 * #clang_indexTranslationUnit.
5277 * \brief Called periodically to check whether indexing should be aborted.
5278 * Should return 0 to continue, and non-zero to abort.
5280 int (*abortQuery)(CXClientData client_data, void *reserved);
5283 * \brief Called at the end of indexing; passes the complete diagnostic set.
5285 void (*diagnostic)(CXClientData client_data,
5286 CXDiagnosticSet, void *reserved);
5288 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
5289 CXFile mainFile, void *reserved);
5292 * \brief Called when a file gets \#included/\#imported.
5294 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
5295 const CXIdxIncludedFileInfo *);
5298 * \brief Called when a AST file (PCH or module) gets imported.
5300 * AST files will not get indexed (there will not be callbacks to index all
5301 * the entities in an AST file). The recommended action is that, if the AST
5302 * file is not already indexed, to initiate a new indexing job specific to
5305 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
5306 const CXIdxImportedASTFileInfo *);
5309 * \brief Called at the beginning of indexing a translation unit.
5311 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
5314 void (*indexDeclaration)(CXClientData client_data,
5315 const CXIdxDeclInfo *);
5318 * \brief Called to index a reference of an entity.
5320 void (*indexEntityReference)(CXClientData client_data,
5321 const CXIdxEntityRefInfo *);
5325 CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
5326 CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
5327 clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
5329 CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
5330 clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
5333 const CXIdxObjCCategoryDeclInfo *
5334 clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
5336 CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
5337 clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
5339 CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
5340 clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
5342 CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
5343 clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
5345 CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
5346 clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
5349 * \brief For retrieving a custom CXIdxClientContainer attached to a
5352 CINDEX_LINKAGE CXIdxClientContainer
5353 clang_index_getClientContainer(const CXIdxContainerInfo *);
5356 * \brief For setting a custom CXIdxClientContainer attached to a
5360 clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
5363 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
5365 CINDEX_LINKAGE CXIdxClientEntity
5366 clang_index_getClientEntity(const CXIdxEntityInfo *);
5369 * \brief For setting a custom CXIdxClientEntity attached to an entity.
5372 clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
5375 * \brief An indexing action, to be applied to one or multiple translation units
5376 * but not on concurrent threads. If there are threads doing indexing
5377 * concurrently, they should use different CXIndexAction objects.
5379 typedef void *CXIndexAction;
5382 * \brief An indexing action, to be applied to one or multiple translation units
5383 * but not on concurrent threads. If there are threads doing indexing
5384 * concurrently, they should use different CXIndexAction objects.
5386 * \param CIdx The index object with which the index action will be associated.
5388 CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
5391 * \brief Destroy the given index action.
5393 * The index action must not be destroyed until all of the translation units
5394 * created within that index action have been destroyed.
5396 CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
5400 * \brief Used to indicate that no special indexing options are needed.
5402 CXIndexOpt_None = 0x0,
5405 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
5406 * be invoked for only one reference of an entity per source file that does
5407 * not also include a declaration/definition of the entity.
5409 CXIndexOpt_SuppressRedundantRefs = 0x1,
5412 * \brief Function-local symbols should be indexed. If this is not set
5413 * function-local symbols will be ignored.
5415 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
5418 * \brief Implicit function/class template instantiations should be indexed.
5419 * If this is not set, implicit instantiations will be ignored.
5421 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
5424 * \brief Suppress all compiler warnings when parsing for indexing.
5426 CXIndexOpt_SuppressWarnings = 0x8
5430 * \brief Index the given source file and the translation unit corresponding
5431 * to that file via callbacks implemented through #IndexerCallbacks.
5433 * \param client_data pointer data supplied by the client, which will
5434 * be passed to the invoked callbacks.
5436 * \param index_callbacks Pointer to indexing callbacks that the client
5439 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
5440 * passed in index_callbacks.
5442 * \param index_options A bitmask of options that affects how indexing is
5443 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
5445 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
5446 * after indexing is finished. Set to NULL if you do not require it.
5448 * \returns If there is a failure from which the there is no recovery, returns
5449 * non-zero, otherwise returns 0.
5451 * The rest of the parameters are the same as #clang_parseTranslationUnit.
5453 CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
5454 CXClientData client_data,
5455 IndexerCallbacks *index_callbacks,
5456 unsigned index_callbacks_size,
5457 unsigned index_options,
5458 const char *source_filename,
5459 const char * const *command_line_args,
5460 int num_command_line_args,
5461 struct CXUnsavedFile *unsaved_files,
5462 unsigned num_unsaved_files,
5463 CXTranslationUnit *out_TU,
5464 unsigned TU_options);
5467 * \brief Index the given translation unit via callbacks implemented through
5468 * #IndexerCallbacks.
5470 * The order of callback invocations is not guaranteed to be the same as
5471 * when indexing a source file. The high level order will be:
5473 * -Preprocessor callbacks invocations
5474 * -Declaration/reference callbacks invocations
5475 * -Diagnostic callback invocations
5477 * The parameters are the same as #clang_indexSourceFile.
5479 * \returns If there is a failure from which the there is no recovery, returns
5480 * non-zero, otherwise returns 0.
5482 CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
5483 CXClientData client_data,
5484 IndexerCallbacks *index_callbacks,
5485 unsigned index_callbacks_size,
5486 unsigned index_options,
5490 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
5491 * the given CXIdxLoc.
5493 * If the location refers into a macro expansion, retrieves the
5494 * location of the macro expansion and if it refers into a macro argument
5495 * retrieves the location of the argument.
5497 CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
5498 CXIdxClientFile *indexFile,
5505 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
5508 CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);