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
27 /* MSVC DLL import/export. */
30 #define CINDEX_LINKAGE __declspec(dllexport)
32 #define CINDEX_LINKAGE __declspec(dllimport)
35 #define CINDEX_LINKAGE
39 #define CINDEX_DEPRECATED __attribute__((deprecated))
42 #define CINDEX_DEPRECATED __declspec(deprecated)
44 #define CINDEX_DEPRECATED
48 /** \defgroup CINDEX libclang: C Interface to Clang
50 * The C Interface to Clang provides a relatively small API that exposes
51 * facilities for parsing source code into an abstract syntax tree (AST),
52 * loading already-parsed ASTs, traversing the AST, associating
53 * physical source locations with elements within the AST, and other
54 * facilities that support Clang-based development tools.
56 * This C interface to Clang will never provide all of the information
57 * representation stored in Clang's C++ AST, nor should it: the intent is to
58 * maintain an API that is relatively stable from one release to the next,
59 * providing only the basic functionality needed to support development tools.
61 * To avoid namespace pollution, data types are prefixed with "CX" and
62 * functions are prefixed with "clang_".
68 * \brief An "index" that consists of a set of translation units that would
69 * typically be linked together into an executable or library.
71 typedef void *CXIndex;
74 * \brief A single translation unit, which resides in an index.
76 typedef struct CXTranslationUnitImpl *CXTranslationUnit;
79 * \brief Opaque pointer representing client data that will be passed through
80 * to various callbacks and visitors.
82 typedef void *CXClientData;
85 * \brief Provides the contents of a file that has not yet been saved to disk.
87 * Each CXUnsavedFile instance provides the name of a file on the
88 * system along with the current contents of that file that have not
89 * yet been saved to disk.
91 struct CXUnsavedFile {
93 * \brief The file whose contents have not yet been saved.
95 * This file must already exist in the file system.
100 * \brief A buffer containing the unsaved contents of this file.
102 const char *Contents;
105 * \brief The length of the unsaved contents of this buffer.
107 unsigned long Length;
111 * \brief Describes the availability of a particular entity, which indicates
112 * whether the use of this entity will result in a warning or error due to
113 * it being deprecated or unavailable.
115 enum CXAvailabilityKind {
117 * \brief The entity is available.
119 CXAvailability_Available,
121 * \brief The entity is available, but has been deprecated (and its use is
124 CXAvailability_Deprecated,
126 * \brief The entity is not available; any use of it will be an error.
128 CXAvailability_NotAvailable,
130 * \brief The entity is available, but not accessible; any use of it will be
133 CXAvailability_NotAccessible
137 * \defgroup CINDEX_STRING String manipulation routines
143 * \brief A character string.
145 * The \c CXString type is used to return strings from the interface when
146 * the ownership of that string might different from one call to the next.
147 * Use \c clang_getCString() to retrieve the string data and, once finished
148 * with the string data, call \c clang_disposeString() to free the string.
152 unsigned private_flags;
156 * \brief Retrieve the character data associated with the given string.
158 CINDEX_LINKAGE const char *clang_getCString(CXString string);
161 * \brief Free the given string,
163 CINDEX_LINKAGE void clang_disposeString(CXString string);
170 * \brief clang_createIndex() provides a shared context for creating
171 * translation units. It provides two options:
173 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
174 * declarations (when loading any new translation units). A "local" declaration
175 * is one that belongs in the translation unit itself and not in a precompiled
176 * header that was used by the translation unit. If zero, all declarations
177 * will be enumerated.
179 * Here is an example:
181 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
182 * Idx = clang_createIndex(1, 1);
184 * // IndexTest.pch was produced with the following command:
185 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
186 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
188 * // This will load all the symbols from 'IndexTest.pch'
189 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
190 * TranslationUnitVisitor, 0);
191 * clang_disposeTranslationUnit(TU);
193 * // This will load all the symbols from 'IndexTest.c', excluding symbols
194 * // from 'IndexTest.pch'.
195 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
196 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
198 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
199 * TranslationUnitVisitor, 0);
200 * clang_disposeTranslationUnit(TU);
202 * This process of creating the 'pch', loading it separately, and using it (via
203 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
204 * (which gives the indexer the same performance benefit as the compiler).
206 CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
207 int displayDiagnostics);
210 * \brief Destroy the given index.
212 * The index must not be destroyed until all of the translation units created
213 * within that index have been destroyed.
215 CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
219 * \brief Used to indicate that no special CXIndex options are needed.
221 CXGlobalOpt_None = 0x0,
224 * \brief Used to indicate that threads that libclang creates for indexing
225 * purposes should use background priority.
226 * Affects \see clang_indexSourceFile, \see clang_indexTranslationUnit,
227 * \see clang_parseTranslationUnit, \see clang_saveTranslationUnit.
229 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
232 * \brief Used to indicate that threads that libclang creates for editing
233 * purposes should use background priority.
234 * Affects \see clang_reparseTranslationUnit, \see clang_codeCompleteAt,
235 * \see clang_annotateTokens
237 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
240 * \brief Used to indicate that all threads that libclang creates should use
241 * background priority.
243 CXGlobalOpt_ThreadBackgroundPriorityForAll =
244 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
245 CXGlobalOpt_ThreadBackgroundPriorityForEditing
250 * \brief Sets general options associated with a CXIndex.
255 * clang_CXIndex_setGlobalOptions(idx,
256 * clang_CXIndex_getGlobalOptions(idx) |
257 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
260 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
262 CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
265 * \brief Gets the general options associated with a CXIndex.
267 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
268 * are associated with the given CXIndex object.
270 CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
273 * \defgroup CINDEX_FILES File manipulation routines
279 * \brief A particular source file that is part of a translation unit.
281 typedef void *CXFile;
285 * \brief Retrieve the complete file and path name of the given file.
287 CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
290 * \brief Retrieve the last modification time of the given file.
292 CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
295 * \brief Determine whether the given header is guarded against
296 * multiple inclusions, either with the conventional
297 * #ifndef/#define/#endif macro guards or with #pragma once.
299 CINDEX_LINKAGE unsigned
300 clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
303 * \brief Retrieve a file handle within the given translation unit.
305 * \param tu the translation unit
307 * \param file_name the name of the file.
309 * \returns the file handle for the named file in the translation unit \p tu,
310 * or a NULL file handle if the file was not a part of this translation unit.
312 CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
313 const char *file_name);
320 * \defgroup CINDEX_LOCATIONS Physical source locations
322 * Clang represents physical source locations in its abstract syntax tree in
323 * great detail, with file, line, and column information for the majority of
324 * the tokens parsed in the source code. These data types and functions are
325 * used to represent source location information, either for a particular
326 * point in the program or for a range of points in the program, and extract
327 * specific location information from those data types.
333 * \brief Identifies a specific source location within a translation
336 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
337 * to map a source location to a particular file, line, and column.
345 * \brief Identifies a half-open character range in the source code.
347 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
348 * starting and end locations from a source range, respectively.
352 unsigned begin_int_data;
353 unsigned end_int_data;
357 * \brief Retrieve a NULL (invalid) source location.
359 CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
362 * \determine Determine whether two source locations, which must refer into
363 * the same translation unit, refer to exactly the same point in the source
366 * \returns non-zero if the source locations refer to the same location, zero
367 * if they refer to different locations.
369 CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
370 CXSourceLocation loc2);
373 * \brief Retrieves the source location associated with a given file/line/column
374 * in a particular translation unit.
376 CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
381 * \brief Retrieves the source location associated with a given character offset
382 * in a particular translation unit.
384 CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
389 * \brief Retrieve a NULL (invalid) source range.
391 CINDEX_LINKAGE CXSourceRange clang_getNullRange();
394 * \brief Retrieve a source range given the beginning and ending source
397 CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
398 CXSourceLocation end);
401 * \brief Determine whether two ranges are equivalent.
403 * \returns non-zero if the ranges are the same, zero if they differ.
405 CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
406 CXSourceRange range2);
409 * \brief Returns non-zero if \arg range is null.
411 CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
414 * \brief Retrieve the file, line, column, and offset represented by
415 * the given source location.
417 * If the location refers into a macro expansion, retrieves the
418 * location of the macro expansion.
420 * \param location the location within a source file that will be decomposed
423 * \param file [out] if non-NULL, will be set to the file to which the given
424 * source location points.
426 * \param line [out] if non-NULL, will be set to the line to which the given
427 * source location points.
429 * \param column [out] if non-NULL, will be set to the column to which the given
430 * source location points.
432 * \param offset [out] if non-NULL, will be set to the offset into the
433 * buffer to which the given source location points.
435 CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
442 * \brief Retrieve the file, line, column, and offset represented by
443 * the given source location, as specified in a # line directive.
445 * Example: given the following source code in a file somefile.c
449 * static int func(void)
454 * the location information returned by this function would be
456 * File: dummy.c Line: 124 Column: 12
458 * whereas clang_getExpansionLocation would have returned
460 * File: somefile.c Line: 3 Column: 12
462 * \param location the location within a source file that will be decomposed
465 * \param filename [out] if non-NULL, will be set to the filename of the
466 * source location. Note that filenames returned will be for "virtual" files,
467 * which don't necessarily exist on the machine running clang - e.g. when
468 * parsing preprocessed output obtained from a different environment. If
469 * a non-NULL value is passed in, remember to dispose of the returned value
470 * using \c clang_disposeString() once you've finished with it. For an invalid
471 * source location, an empty string is returned.
473 * \param line [out] if non-NULL, will be set to the line number of the
474 * source location. For an invalid source location, zero is returned.
476 * \param column [out] if non-NULL, will be set to the column number of the
477 * source location. For an invalid source location, zero is returned.
479 CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
485 * \brief Legacy API to retrieve the file, line, column, and offset represented
486 * by the given source location.
488 * This interface has been replaced by the newer interface
489 * \see clang_getExpansionLocation(). See that interface's documentation for
492 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
499 * \brief Retrieve the file, line, column, and offset represented by
500 * the given source location.
502 * If the location refers into a macro instantiation, return where the
503 * location was originally spelled in the source file.
505 * \param location the location within a source file that will be decomposed
508 * \param file [out] if non-NULL, will be set to the file to which the given
509 * source location points.
511 * \param line [out] if non-NULL, will be set to the line to which the given
512 * source location points.
514 * \param column [out] if non-NULL, will be set to the column to which the given
515 * source location points.
517 * \param offset [out] if non-NULL, will be set to the offset into the
518 * buffer to which the given source location points.
520 CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
527 * \brief Retrieve a source location representing the first character within a
530 CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
533 * \brief Retrieve a source location representing the last character within a
536 CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
543 * \defgroup CINDEX_DIAG Diagnostic reporting
549 * \brief Describes the severity of a particular diagnostic.
551 enum CXDiagnosticSeverity {
553 * \brief A diagnostic that has been suppressed, e.g., by a command-line
556 CXDiagnostic_Ignored = 0,
559 * \brief This diagnostic is a note that should be attached to the
560 * previous (non-note) diagnostic.
562 CXDiagnostic_Note = 1,
565 * \brief This diagnostic indicates suspicious code that may not be
568 CXDiagnostic_Warning = 2,
571 * \brief This diagnostic indicates that the code is ill-formed.
573 CXDiagnostic_Error = 3,
576 * \brief This diagnostic indicates that the code is ill-formed such
577 * that future parser recovery is unlikely to produce useful
580 CXDiagnostic_Fatal = 4
584 * \brief A single diagnostic, containing the diagnostic's severity,
585 * location, text, source ranges, and fix-it hints.
587 typedef void *CXDiagnostic;
590 * \brief A group of CXDiagnostics.
592 typedef void *CXDiagnosticSet;
595 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
597 CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
600 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
602 * \param Unit the CXDiagnosticSet to query.
603 * \param Index the zero-based diagnostic number to retrieve.
605 * \returns the requested diagnostic. This diagnostic must be freed
606 * via a call to \c clang_disposeDiagnostic().
608 CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
613 * \brief Describes the kind of error that occurred (if any) in a call to
614 * \c clang_loadDiagnostics.
616 enum CXLoadDiag_Error {
618 * \brief Indicates that no error occurred.
623 * \brief Indicates that an unknown error occurred while attempting to
624 * deserialize diagnostics.
626 CXLoadDiag_Unknown = 1,
629 * \brief Indicates that the file containing the serialized diagnostics
630 * could not be opened.
632 CXLoadDiag_CannotLoad = 2,
635 * \brief Indicates that the serialized diagnostics file is invalid or
638 CXLoadDiag_InvalidFile = 3
642 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
645 * \param The name of the file to deserialize.
646 * \param A pointer to a enum value recording if there was a problem
647 * deserializing the diagnostics.
648 * \param A pointer to a CXString for recording the error string
649 * if the file was not successfully loaded.
651 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
652 * diagnostics should be released using clang_disposeDiagnosticSet().
654 CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
655 enum CXLoadDiag_Error *error,
656 CXString *errorString);
659 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
661 CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
664 * \brief Retrieve the child diagnostics of a CXDiagnostic. This
665 * CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet.
667 CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
670 * \brief Determine the number of diagnostics produced for the given
673 CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
676 * \brief Retrieve a diagnostic associated with the given translation unit.
678 * \param Unit the translation unit to query.
679 * \param Index the zero-based diagnostic number to retrieve.
681 * \returns the requested diagnostic. This diagnostic must be freed
682 * via a call to \c clang_disposeDiagnostic().
684 CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
688 * \brief Retrieve the complete set of diagnostics associated with a
691 * \param Unit the translation unit to query.
693 CINDEX_LINKAGE CXDiagnosticSet
694 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
697 * \brief Destroy a diagnostic.
699 CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
702 * \brief Options to control the display of diagnostics.
704 * The values in this enum are meant to be combined to customize the
705 * behavior of \c clang_displayDiagnostic().
707 enum CXDiagnosticDisplayOptions {
709 * \brief Display the source-location information where the
710 * diagnostic was located.
712 * When set, diagnostics will be prefixed by the file, line, and
713 * (optionally) column to which the diagnostic refers. For example,
716 * test.c:28: warning: extra tokens at end of #endif directive
719 * This option corresponds to the clang flag \c -fshow-source-location.
721 CXDiagnostic_DisplaySourceLocation = 0x01,
724 * \brief If displaying the source-location information of the
725 * diagnostic, also include the column number.
727 * This option corresponds to the clang flag \c -fshow-column.
729 CXDiagnostic_DisplayColumn = 0x02,
732 * \brief If displaying the source-location information of the
733 * diagnostic, also include information about source ranges in a
734 * machine-parsable format.
736 * This option corresponds to the clang flag
737 * \c -fdiagnostics-print-source-range-info.
739 CXDiagnostic_DisplaySourceRanges = 0x04,
742 * \brief Display the option name associated with this diagnostic, if any.
744 * The option name displayed (e.g., -Wconversion) will be placed in brackets
745 * after the diagnostic text. This option corresponds to the clang flag
746 * \c -fdiagnostics-show-option.
748 CXDiagnostic_DisplayOption = 0x08,
751 * \brief Display the category number associated with this diagnostic, if any.
753 * The category number is displayed within brackets after the diagnostic text.
754 * This option corresponds to the clang flag
755 * \c -fdiagnostics-show-category=id.
757 CXDiagnostic_DisplayCategoryId = 0x10,
760 * \brief Display the category name associated with this diagnostic, if any.
762 * The category name is displayed within brackets after the diagnostic text.
763 * This option corresponds to the clang flag
764 * \c -fdiagnostics-show-category=name.
766 CXDiagnostic_DisplayCategoryName = 0x20
770 * \brief Format the given diagnostic in a manner that is suitable for display.
772 * This routine will format the given diagnostic to a string, rendering
773 * the diagnostic according to the various options given. The
774 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
775 * options that most closely mimics the behavior of the clang compiler.
777 * \param Diagnostic The diagnostic to print.
779 * \param Options A set of options that control the diagnostic display,
780 * created by combining \c CXDiagnosticDisplayOptions values.
782 * \returns A new string containing for formatted diagnostic.
784 CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
788 * \brief Retrieve the set of display options most similar to the
789 * default behavior of the clang compiler.
791 * \returns A set of display options suitable for use with \c
792 * clang_displayDiagnostic().
794 CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
797 * \brief Determine the severity of the given diagnostic.
799 CINDEX_LINKAGE enum CXDiagnosticSeverity
800 clang_getDiagnosticSeverity(CXDiagnostic);
803 * \brief Retrieve the source location of the given diagnostic.
805 * This location is where Clang would print the caret ('^') when
806 * displaying the diagnostic on the command line.
808 CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
811 * \brief Retrieve the text of the given diagnostic.
813 CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
816 * \brief Retrieve the name of the command-line option that enabled this
819 * \param Diag The diagnostic to be queried.
821 * \param Disable If non-NULL, will be set to the option that disables this
822 * diagnostic (if any).
824 * \returns A string that contains the command-line option used to enable this
825 * warning, such as "-Wconversion" or "-pedantic".
827 CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
831 * \brief Retrieve the category number for this diagnostic.
833 * Diagnostics can be categorized into groups along with other, related
834 * diagnostics (e.g., diagnostics under the same warning flag). This routine
835 * retrieves the category number for the given diagnostic.
837 * \returns The number of the category that contains this diagnostic, or zero
838 * if this diagnostic is uncategorized.
840 CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
843 * \brief Retrieve the name of a particular diagnostic category. This
844 * is now deprecated. Use clang_getDiagnosticCategoryText()
847 * \param Category A diagnostic category number, as returned by
848 * \c clang_getDiagnosticCategory().
850 * \returns The name of the given diagnostic category.
852 CINDEX_DEPRECATED CINDEX_LINKAGE
853 CXString clang_getDiagnosticCategoryName(unsigned Category);
856 * \brief Retrieve the diagnostic category text for a given diagnostic.
859 * \returns The text of the given diagnostic category.
861 CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
864 * \brief Determine the number of source ranges associated with the given
867 CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
870 * \brief Retrieve a source range associated with the diagnostic.
872 * A diagnostic's source ranges highlight important elements in the source
873 * code. On the command line, Clang displays source ranges by
874 * underlining them with '~' characters.
876 * \param Diagnostic the diagnostic whose range is being extracted.
878 * \param Range the zero-based index specifying which range to
880 * \returns the requested source range.
882 CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
886 * \brief Determine the number of fix-it hints associated with the
889 CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
892 * \brief Retrieve the replacement information for a given fix-it.
894 * Fix-its are described in terms of a source range whose contents
895 * should be replaced by a string. This approach generalizes over
896 * three kinds of operations: removal of source code (the range covers
897 * the code to be removed and the replacement string is empty),
898 * replacement of source code (the range covers the code to be
899 * replaced and the replacement string provides the new code), and
900 * insertion (both the start and end of the range point at the
901 * insertion location, and the replacement string provides the text to
904 * \param Diagnostic The diagnostic whose fix-its are being queried.
906 * \param FixIt The zero-based index of the fix-it.
908 * \param ReplacementRange The source range whose contents will be
909 * replaced with the returned replacement string. Note that source
910 * ranges are half-open ranges [a, b), so the source code should be
911 * replaced from a and up to (but not including) b.
913 * \returns A string containing text that should be replace the source
914 * code indicated by the \c ReplacementRange.
916 CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
918 CXSourceRange *ReplacementRange);
925 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
927 * The routines in this group provide the ability to create and destroy
928 * translation units from files, either by parsing the contents of the files or
929 * by reading in a serialized representation of a translation unit.
935 * \brief Get the original translation unit source file name.
937 CINDEX_LINKAGE CXString
938 clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
941 * \brief Return the CXTranslationUnit for a given source file and the provided
942 * command line arguments one would pass to the compiler.
944 * Note: The 'source_filename' argument is optional. If the caller provides a
945 * NULL pointer, the name of the source file is expected to reside in the
946 * specified command line arguments.
948 * Note: When encountered in 'clang_command_line_args', the following options
954 * '-o <output file>' (both '-o' and '<output file>' are ignored)
956 * \param CIdx The index object with which the translation unit will be
959 * \param source_filename - The name of the source file to load, or NULL if the
960 * source file is included in \p clang_command_line_args.
962 * \param num_clang_command_line_args The number of command-line arguments in
963 * \p clang_command_line_args.
965 * \param clang_command_line_args The command-line arguments that would be
966 * passed to the \c clang executable if it were being invoked out-of-process.
967 * These command-line options will be parsed and will affect how the translation
968 * unit is parsed. Note that the following options are ignored: '-c',
969 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
971 * \param num_unsaved_files the number of unsaved file entries in \p
974 * \param unsaved_files the files that have not yet been saved to disk
975 * but may be required for code completion, including the contents of
976 * those files. The contents and name of these files (as specified by
977 * CXUnsavedFile) are copied when necessary, so the client only needs to
978 * guarantee their validity until the call to this function returns.
980 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
982 const char *source_filename,
983 int num_clang_command_line_args,
984 const char * const *clang_command_line_args,
985 unsigned num_unsaved_files,
986 struct CXUnsavedFile *unsaved_files);
989 * \brief Create a translation unit from an AST file (-emit-ast).
991 CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
992 const char *ast_filename);
995 * \brief Flags that control the creation of translation units.
997 * The enumerators in this enumeration type are meant to be bitwise
998 * ORed together to specify which options should be used when
999 * constructing the translation unit.
1001 enum CXTranslationUnit_Flags {
1003 * \brief Used to indicate that no special translation-unit options are
1006 CXTranslationUnit_None = 0x0,
1009 * \brief Used to indicate that the parser should construct a "detailed"
1010 * preprocessing record, including all macro definitions and instantiations.
1012 * Constructing a detailed preprocessing record requires more memory
1013 * and time to parse, since the information contained in the record
1014 * is usually not retained. However, it can be useful for
1015 * applications that require more detailed information about the
1016 * behavior of the preprocessor.
1018 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1021 * \brief Used to indicate that the translation unit is incomplete.
1023 * When a translation unit is considered "incomplete", semantic
1024 * analysis that is typically performed at the end of the
1025 * translation unit will be suppressed. For example, this suppresses
1026 * the completion of tentative declarations in C and of
1027 * instantiation of implicitly-instantiation function templates in
1028 * C++. This option is typically used when parsing a header with the
1029 * intent of producing a precompiled header.
1031 CXTranslationUnit_Incomplete = 0x02,
1034 * \brief Used to indicate that the translation unit should be built with an
1035 * implicit precompiled header for the preamble.
1037 * An implicit precompiled header is used as an optimization when a
1038 * particular translation unit is likely to be reparsed many times
1039 * when the sources aren't changing that often. In this case, an
1040 * implicit precompiled header will be built containing all of the
1041 * initial includes at the top of the main file (what we refer to as
1042 * the "preamble" of the file). In subsequent parses, if the
1043 * preamble or the files in it have not changed, \c
1044 * clang_reparseTranslationUnit() will re-use the implicit
1045 * precompiled header to improve parsing performance.
1047 CXTranslationUnit_PrecompiledPreamble = 0x04,
1050 * \brief Used to indicate that the translation unit should cache some
1051 * code-completion results with each reparse of the source file.
1053 * Caching of code-completion results is a performance optimization that
1054 * introduces some overhead to reparsing but improves the performance of
1055 * code-completion operations.
1057 CXTranslationUnit_CacheCompletionResults = 0x08,
1059 * \brief DEPRECATED: Enable precompiled preambles in C++.
1061 * Note: this is a *temporary* option that is available only while
1062 * we are testing C++ precompiled preamble support. It is deprecated.
1064 CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
1067 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
1069 * Note: this is a *temporary* option that is available only while
1070 * we are testing C++ precompiled preamble support. It is deprecated.
1072 CXTranslationUnit_CXXChainedPCH = 0x20,
1075 * \brief Used to indicate that function/method bodies should be skipped while
1078 * This option can be used to search for declarations/definitions while
1079 * ignoring the usages.
1081 CXTranslationUnit_SkipFunctionBodies = 0x40
1085 * \brief Returns the set of flags that is suitable for parsing a translation
1086 * unit that is being edited.
1088 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1089 * to indicate that the translation unit is likely to be reparsed many times,
1090 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1091 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1092 * set contains an unspecified set of optimizations (e.g., the precompiled
1093 * preamble) geared toward improving the performance of these routines. The
1094 * set of optimizations enabled may change from one version to the next.
1096 CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
1099 * \brief Parse the given source file and the translation unit corresponding
1102 * This routine is the main entry point for the Clang C API, providing the
1103 * ability to parse a source file into a translation unit that can then be
1104 * queried by other functions in the API. This routine accepts a set of
1105 * command-line arguments so that the compilation can be configured in the same
1106 * way that the compiler is configured on the command line.
1108 * \param CIdx The index object with which the translation unit will be
1111 * \param source_filename The name of the source file to load, or NULL if the
1112 * source file is included in \p command_line_args.
1114 * \param command_line_args The command-line arguments that would be
1115 * passed to the \c clang executable if it were being invoked out-of-process.
1116 * These command-line options will be parsed and will affect how the translation
1117 * unit is parsed. Note that the following options are ignored: '-c',
1118 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
1120 * \param num_command_line_args The number of command-line arguments in
1121 * \p command_line_args.
1123 * \param unsaved_files the files that have not yet been saved to disk
1124 * but may be required for parsing, including the contents of
1125 * those files. The contents and name of these files (as specified by
1126 * CXUnsavedFile) are copied when necessary, so the client only needs to
1127 * guarantee their validity until the call to this function returns.
1129 * \param num_unsaved_files the number of unsaved file entries in \p
1132 * \param options A bitmask of options that affects how the translation unit
1133 * is managed but not its compilation. This should be a bitwise OR of the
1134 * CXTranslationUnit_XXX flags.
1136 * \returns A new translation unit describing the parsed code and containing
1137 * any diagnostics produced by the compiler. If there is a failure from which
1138 * the compiler cannot recover, returns NULL.
1140 CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1141 const char *source_filename,
1142 const char * const *command_line_args,
1143 int num_command_line_args,
1144 struct CXUnsavedFile *unsaved_files,
1145 unsigned num_unsaved_files,
1149 * \brief Flags that control how translation units are saved.
1151 * The enumerators in this enumeration type are meant to be bitwise
1152 * ORed together to specify which options should be used when
1153 * saving the translation unit.
1155 enum CXSaveTranslationUnit_Flags {
1157 * \brief Used to indicate that no special saving options are needed.
1159 CXSaveTranslationUnit_None = 0x0
1163 * \brief Returns the set of flags that is suitable for saving a translation
1166 * The set of flags returned provide options for
1167 * \c clang_saveTranslationUnit() by default. The returned flag
1168 * set contains an unspecified set of options that save translation units with
1169 * the most commonly-requested data.
1171 CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1174 * \brief Describes the kind of error that occurred (if any) in a call to
1175 * \c clang_saveTranslationUnit().
1179 * \brief Indicates that no error occurred while saving a translation unit.
1181 CXSaveError_None = 0,
1184 * \brief Indicates that an unknown error occurred while attempting to save
1187 * This error typically indicates that file I/O failed when attempting to
1190 CXSaveError_Unknown = 1,
1193 * \brief Indicates that errors during translation prevented this attempt
1194 * to save the translation unit.
1196 * Errors that prevent the translation unit from being saved can be
1197 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1199 CXSaveError_TranslationErrors = 2,
1202 * \brief Indicates that the translation unit to be saved was somehow
1203 * invalid (e.g., NULL).
1205 CXSaveError_InvalidTU = 3
1209 * \brief Saves a translation unit into a serialized representation of
1210 * that translation unit on disk.
1212 * Any translation unit that was parsed without error can be saved
1213 * into a file. The translation unit can then be deserialized into a
1214 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1215 * if it is an incomplete translation unit that corresponds to a
1216 * header, used as a precompiled header when parsing other translation
1219 * \param TU The translation unit to save.
1221 * \param FileName The file to which the translation unit will be saved.
1223 * \param options A bitmask of options that affects how the translation unit
1224 * is saved. This should be a bitwise OR of the
1225 * CXSaveTranslationUnit_XXX flags.
1227 * \returns A value that will match one of the enumerators of the CXSaveError
1228 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1229 * saved successfully, while a non-zero value indicates that a problem occurred.
1231 CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
1232 const char *FileName,
1236 * \brief Destroy the specified CXTranslationUnit object.
1238 CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
1241 * \brief Flags that control the reparsing of translation units.
1243 * The enumerators in this enumeration type are meant to be bitwise
1244 * ORed together to specify which options should be used when
1245 * reparsing the translation unit.
1247 enum CXReparse_Flags {
1249 * \brief Used to indicate that no special reparsing options are needed.
1251 CXReparse_None = 0x0
1255 * \brief Returns the set of flags that is suitable for reparsing a translation
1258 * The set of flags returned provide options for
1259 * \c clang_reparseTranslationUnit() by default. The returned flag
1260 * set contains an unspecified set of optimizations geared toward common uses
1261 * of reparsing. The set of optimizations enabled may change from one version
1264 CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1267 * \brief Reparse the source files that produced this translation unit.
1269 * This routine can be used to re-parse the source files that originally
1270 * created the given translation unit, for example because those source files
1271 * have changed (either on disk or as passed via \p unsaved_files). The
1272 * source code will be reparsed with the same command-line options as it
1273 * was originally parsed.
1275 * Reparsing a translation unit invalidates all cursors and source locations
1276 * that refer into that translation unit. This makes reparsing a translation
1277 * unit semantically equivalent to destroying the translation unit and then
1278 * creating a new translation unit with the same command-line arguments.
1279 * However, it may be more efficient to reparse a translation
1280 * unit using this routine.
1282 * \param TU The translation unit whose contents will be re-parsed. The
1283 * translation unit must originally have been built with
1284 * \c clang_createTranslationUnitFromSourceFile().
1286 * \param num_unsaved_files The number of unsaved file entries in \p
1289 * \param unsaved_files The files that have not yet been saved to disk
1290 * but may be required for parsing, including the contents of
1291 * those files. The contents and name of these files (as specified by
1292 * CXUnsavedFile) are copied when necessary, so the client only needs to
1293 * guarantee their validity until the call to this function returns.
1295 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1296 * The function \c clang_defaultReparseOptions() produces a default set of
1297 * options recommended for most uses, based on the translation unit.
1299 * \returns 0 if the sources could be reparsed. A non-zero value will be
1300 * returned if reparsing was impossible, such that the translation unit is
1301 * invalid. In such cases, the only valid call for \p TU is
1302 * \c clang_disposeTranslationUnit(TU).
1304 CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1305 unsigned num_unsaved_files,
1306 struct CXUnsavedFile *unsaved_files,
1310 * \brief Categorizes how memory is being used by a translation unit.
1312 enum CXTUResourceUsageKind {
1313 CXTUResourceUsage_AST = 1,
1314 CXTUResourceUsage_Identifiers = 2,
1315 CXTUResourceUsage_Selectors = 3,
1316 CXTUResourceUsage_GlobalCompletionResults = 4,
1317 CXTUResourceUsage_SourceManagerContentCache = 5,
1318 CXTUResourceUsage_AST_SideTables = 6,
1319 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
1320 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1321 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1322 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
1323 CXTUResourceUsage_Preprocessor = 11,
1324 CXTUResourceUsage_PreprocessingRecord = 12,
1325 CXTUResourceUsage_SourceManager_DataStructures = 13,
1326 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
1327 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1328 CXTUResourceUsage_MEMORY_IN_BYTES_END =
1329 CXTUResourceUsage_Preprocessor_HeaderSearch,
1331 CXTUResourceUsage_First = CXTUResourceUsage_AST,
1332 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
1336 * \brief Returns the human-readable null-terminated C string that represents
1337 * the name of the memory category. This string should never be freed.
1340 const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
1342 typedef struct CXTUResourceUsageEntry {
1343 /* \brief The memory usage category. */
1344 enum CXTUResourceUsageKind kind;
1345 /* \brief Amount of resources used.
1346 The units will depend on the resource kind. */
1347 unsigned long amount;
1348 } CXTUResourceUsageEntry;
1351 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1353 typedef struct CXTUResourceUsage {
1354 /* \brief Private data member, used for queries. */
1357 /* \brief The number of entries in the 'entries' array. */
1358 unsigned numEntries;
1360 /* \brief An array of key-value pairs, representing the breakdown of memory
1362 CXTUResourceUsageEntry *entries;
1364 } CXTUResourceUsage;
1367 * \brief Return the memory usage of a translation unit. This object
1368 * should be released with clang_disposeCXTUResourceUsage().
1370 CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
1372 CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
1379 * \brief Describes the kind of entity that a cursor refers to.
1384 * \brief A declaration whose specific kind is not exposed via this
1387 * Unexposed declarations have the same operations as any other kind
1388 * of declaration; one can extract their location information,
1389 * spelling, find their definitions, etc. However, the specific kind
1390 * of the declaration is not reported.
1392 CXCursor_UnexposedDecl = 1,
1393 /** \brief A C or C++ struct. */
1394 CXCursor_StructDecl = 2,
1395 /** \brief A C or C++ union. */
1396 CXCursor_UnionDecl = 3,
1397 /** \brief A C++ class. */
1398 CXCursor_ClassDecl = 4,
1399 /** \brief An enumeration. */
1400 CXCursor_EnumDecl = 5,
1402 * \brief A field (in C) or non-static data member (in C++) in a
1403 * struct, union, or C++ class.
1405 CXCursor_FieldDecl = 6,
1406 /** \brief An enumerator constant. */
1407 CXCursor_EnumConstantDecl = 7,
1408 /** \brief A function. */
1409 CXCursor_FunctionDecl = 8,
1410 /** \brief A variable. */
1411 CXCursor_VarDecl = 9,
1412 /** \brief A function or method parameter. */
1413 CXCursor_ParmDecl = 10,
1414 /** \brief An Objective-C @interface. */
1415 CXCursor_ObjCInterfaceDecl = 11,
1416 /** \brief An Objective-C @interface for a category. */
1417 CXCursor_ObjCCategoryDecl = 12,
1418 /** \brief An Objective-C @protocol declaration. */
1419 CXCursor_ObjCProtocolDecl = 13,
1420 /** \brief An Objective-C @property declaration. */
1421 CXCursor_ObjCPropertyDecl = 14,
1422 /** \brief An Objective-C instance variable. */
1423 CXCursor_ObjCIvarDecl = 15,
1424 /** \brief An Objective-C instance method. */
1425 CXCursor_ObjCInstanceMethodDecl = 16,
1426 /** \brief An Objective-C class method. */
1427 CXCursor_ObjCClassMethodDecl = 17,
1428 /** \brief An Objective-C @implementation. */
1429 CXCursor_ObjCImplementationDecl = 18,
1430 /** \brief An Objective-C @implementation for a category. */
1431 CXCursor_ObjCCategoryImplDecl = 19,
1432 /** \brief A typedef */
1433 CXCursor_TypedefDecl = 20,
1434 /** \brief A C++ class method. */
1435 CXCursor_CXXMethod = 21,
1436 /** \brief A C++ namespace. */
1437 CXCursor_Namespace = 22,
1438 /** \brief A linkage specification, e.g. 'extern "C"'. */
1439 CXCursor_LinkageSpec = 23,
1440 /** \brief A C++ constructor. */
1441 CXCursor_Constructor = 24,
1442 /** \brief A C++ destructor. */
1443 CXCursor_Destructor = 25,
1444 /** \brief A C++ conversion function. */
1445 CXCursor_ConversionFunction = 26,
1446 /** \brief A C++ template type parameter. */
1447 CXCursor_TemplateTypeParameter = 27,
1448 /** \brief A C++ non-type template parameter. */
1449 CXCursor_NonTypeTemplateParameter = 28,
1450 /** \brief A C++ template template parameter. */
1451 CXCursor_TemplateTemplateParameter = 29,
1452 /** \brief A C++ function template. */
1453 CXCursor_FunctionTemplate = 30,
1454 /** \brief A C++ class template. */
1455 CXCursor_ClassTemplate = 31,
1456 /** \brief A C++ class template partial specialization. */
1457 CXCursor_ClassTemplatePartialSpecialization = 32,
1458 /** \brief A C++ namespace alias declaration. */
1459 CXCursor_NamespaceAlias = 33,
1460 /** \brief A C++ using directive. */
1461 CXCursor_UsingDirective = 34,
1462 /** \brief A C++ using declaration. */
1463 CXCursor_UsingDeclaration = 35,
1464 /** \brief A C++ alias declaration */
1465 CXCursor_TypeAliasDecl = 36,
1466 /** \brief An Objective-C @synthesize definition. */
1467 CXCursor_ObjCSynthesizeDecl = 37,
1468 /** \brief An Objective-C @dynamic definition. */
1469 CXCursor_ObjCDynamicDecl = 38,
1470 /** \brief An access specifier. */
1471 CXCursor_CXXAccessSpecifier = 39,
1473 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
1474 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
1477 CXCursor_FirstRef = 40, /* Decl references */
1478 CXCursor_ObjCSuperClassRef = 40,
1479 CXCursor_ObjCProtocolRef = 41,
1480 CXCursor_ObjCClassRef = 42,
1482 * \brief A reference to a type declaration.
1484 * A type reference occurs anywhere where a type is named but not
1485 * declared. For example, given:
1488 * typedef unsigned size_type;
1492 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1493 * while the type of the variable "size" is referenced. The cursor
1494 * referenced by the type of size is the typedef for size_type.
1496 CXCursor_TypeRef = 43,
1497 CXCursor_CXXBaseSpecifier = 44,
1499 * \brief A reference to a class template, function template, template
1500 * template parameter, or class template partial specialization.
1502 CXCursor_TemplateRef = 45,
1504 * \brief A reference to a namespace or namespace alias.
1506 CXCursor_NamespaceRef = 46,
1508 * \brief A reference to a member of a struct, union, or class that occurs in
1509 * some non-expression context, e.g., a designated initializer.
1511 CXCursor_MemberRef = 47,
1513 * \brief A reference to a labeled statement.
1515 * This cursor kind is used to describe the jump to "start_over" in the
1516 * goto statement in the following example:
1525 * A label reference cursor refers to a label statement.
1527 CXCursor_LabelRef = 48,
1530 * \brief A reference to a set of overloaded functions or function templates
1531 * that has not yet been resolved to a specific function or function template.
1533 * An overloaded declaration reference cursor occurs in C++ templates where
1534 * a dependent name refers to a function. For example:
1537 * template<typename T> void swap(T&, T&);
1540 * void swap(X&, X&);
1542 * template<typename T>
1543 * void reverse(T* first, T* last) {
1544 * while (first < last - 1) {
1545 * swap(*first, *--last);
1551 * void swap(Y&, Y&);
1554 * Here, the identifier "swap" is associated with an overloaded declaration
1555 * reference. In the template definition, "swap" refers to either of the two
1556 * "swap" functions declared above, so both results will be available. At
1557 * instantiation time, "swap" may also refer to other functions found via
1558 * argument-dependent lookup (e.g., the "swap" function at the end of the
1561 * The functions \c clang_getNumOverloadedDecls() and
1562 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1563 * referenced by this cursor.
1565 CXCursor_OverloadedDeclRef = 49,
1568 * \brief A reference to a variable that occurs in some non-expression
1569 * context, e.g., a C++ lambda capture list.
1571 CXCursor_VariableRef = 50,
1573 CXCursor_LastRef = CXCursor_VariableRef,
1575 /* Error conditions */
1576 CXCursor_FirstInvalid = 70,
1577 CXCursor_InvalidFile = 70,
1578 CXCursor_NoDeclFound = 71,
1579 CXCursor_NotImplemented = 72,
1580 CXCursor_InvalidCode = 73,
1581 CXCursor_LastInvalid = CXCursor_InvalidCode,
1584 CXCursor_FirstExpr = 100,
1587 * \brief An expression whose specific kind is not exposed via this
1590 * Unexposed expressions have the same operations as any other kind
1591 * of expression; one can extract their location information,
1592 * spelling, children, etc. However, the specific kind of the
1593 * expression is not reported.
1595 CXCursor_UnexposedExpr = 100,
1598 * \brief An expression that refers to some value declaration, such
1599 * as a function, varible, or enumerator.
1601 CXCursor_DeclRefExpr = 101,
1604 * \brief An expression that refers to a member of a struct, union,
1605 * class, Objective-C class, etc.
1607 CXCursor_MemberRefExpr = 102,
1609 /** \brief An expression that calls a function. */
1610 CXCursor_CallExpr = 103,
1612 /** \brief An expression that sends a message to an Objective-C
1614 CXCursor_ObjCMessageExpr = 104,
1616 /** \brief An expression that represents a block literal. */
1617 CXCursor_BlockExpr = 105,
1619 /** \brief An integer literal.
1621 CXCursor_IntegerLiteral = 106,
1623 /** \brief A floating point number literal.
1625 CXCursor_FloatingLiteral = 107,
1627 /** \brief An imaginary number literal.
1629 CXCursor_ImaginaryLiteral = 108,
1631 /** \brief A string literal.
1633 CXCursor_StringLiteral = 109,
1635 /** \brief A character literal.
1637 CXCursor_CharacterLiteral = 110,
1639 /** \brief A parenthesized expression, e.g. "(1)".
1641 * This AST node is only formed if full location information is requested.
1643 CXCursor_ParenExpr = 111,
1645 /** \brief This represents the unary-expression's (except sizeof and
1648 CXCursor_UnaryOperator = 112,
1650 /** \brief [C99 6.5.2.1] Array Subscripting.
1652 CXCursor_ArraySubscriptExpr = 113,
1654 /** \brief A builtin binary operation expression such as "x + y" or
1657 CXCursor_BinaryOperator = 114,
1659 /** \brief Compound assignment such as "+=".
1661 CXCursor_CompoundAssignOperator = 115,
1663 /** \brief The ?: ternary operator.
1665 CXCursor_ConditionalOperator = 116,
1667 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1668 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1670 * For example: (int)f.
1672 CXCursor_CStyleCastExpr = 117,
1674 /** \brief [C99 6.5.2.5]
1676 CXCursor_CompoundLiteralExpr = 118,
1678 /** \brief Describes an C or C++ initializer list.
1680 CXCursor_InitListExpr = 119,
1682 /** \brief The GNU address of label extension, representing &&label.
1684 CXCursor_AddrLabelExpr = 120,
1686 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1688 CXCursor_StmtExpr = 121,
1690 /** \brief Represents a C11 generic selection.
1692 CXCursor_GenericSelectionExpr = 122,
1694 /** \brief Implements the GNU __null extension, which is a name for a null
1695 * pointer constant that has integral type (e.g., int or long) and is the same
1696 * size and alignment as a pointer.
1698 * The __null extension is typically only used by system headers, which define
1699 * NULL as __null in C++ rather than using 0 (which is an integer that may not
1700 * match the size of a pointer).
1702 CXCursor_GNUNullExpr = 123,
1704 /** \brief C++'s static_cast<> expression.
1706 CXCursor_CXXStaticCastExpr = 124,
1708 /** \brief C++'s dynamic_cast<> expression.
1710 CXCursor_CXXDynamicCastExpr = 125,
1712 /** \brief C++'s reinterpret_cast<> expression.
1714 CXCursor_CXXReinterpretCastExpr = 126,
1716 /** \brief C++'s const_cast<> expression.
1718 CXCursor_CXXConstCastExpr = 127,
1720 /** \brief Represents an explicit C++ type conversion that uses "functional"
1721 * notion (C++ [expr.type.conv]).
1728 CXCursor_CXXFunctionalCastExpr = 128,
1730 /** \brief A C++ typeid expression (C++ [expr.typeid]).
1732 CXCursor_CXXTypeidExpr = 129,
1734 /** \brief [C++ 2.13.5] C++ Boolean Literal.
1736 CXCursor_CXXBoolLiteralExpr = 130,
1738 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1740 CXCursor_CXXNullPtrLiteralExpr = 131,
1742 /** \brief Represents the "this" expression in C++
1744 CXCursor_CXXThisExpr = 132,
1746 /** \brief [C++ 15] C++ Throw Expression.
1748 * This handles 'throw' and 'throw' assignment-expression. When
1749 * assignment-expression isn't present, Op will be null.
1751 CXCursor_CXXThrowExpr = 133,
1753 /** \brief A new expression for memory allocation and constructor calls, e.g:
1754 * "new CXXNewExpr(foo)".
1756 CXCursor_CXXNewExpr = 134,
1758 /** \brief A delete expression for memory deallocation and destructor calls,
1759 * e.g. "delete[] pArray".
1761 CXCursor_CXXDeleteExpr = 135,
1763 /** \brief A unary expression.
1765 CXCursor_UnaryExpr = 136,
1767 /** \brief An Objective-C string literal i.e. @"foo".
1769 CXCursor_ObjCStringLiteral = 137,
1771 /** \brief An Objective-C @encode expression.
1773 CXCursor_ObjCEncodeExpr = 138,
1775 /** \brief An Objective-C @selector expression.
1777 CXCursor_ObjCSelectorExpr = 139,
1779 /** \brief An Objective-C @protocol expression.
1781 CXCursor_ObjCProtocolExpr = 140,
1783 /** \brief An Objective-C "bridged" cast expression, which casts between
1784 * Objective-C pointers and C pointers, transferring ownership in the process.
1787 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
1790 CXCursor_ObjCBridgedCastExpr = 141,
1792 /** \brief Represents a C++0x pack expansion that produces a sequence of
1795 * A pack expansion expression contains a pattern (which itself is an
1796 * expression) followed by an ellipsis. For example:
1799 * template<typename F, typename ...Types>
1800 * void forward(F f, Types &&...args) {
1801 * f(static_cast<Types&&>(args)...);
1805 CXCursor_PackExpansionExpr = 142,
1807 /** \brief Represents an expression that computes the length of a parameter
1811 * template<typename ...Types>
1813 * static const unsigned value = sizeof...(Types);
1817 CXCursor_SizeOfPackExpr = 143,
1819 /* \brief Represents a C++ lambda expression that produces a local function
1823 * void abssort(float *x, unsigned N) {
1824 * std::sort(x, x + N,
1825 * [](float a, float b) {
1826 * return std::abs(a) < std::abs(b);
1831 CXCursor_LambdaExpr = 144,
1833 /** \brief Objective-c Boolean Literal.
1835 CXCursor_ObjCBoolLiteralExpr = 145,
1837 CXCursor_LastExpr = CXCursor_ObjCBoolLiteralExpr,
1840 CXCursor_FirstStmt = 200,
1842 * \brief A statement whose specific kind is not exposed via this
1845 * Unexposed statements have the same operations as any other kind of
1846 * statement; one can extract their location information, spelling,
1847 * children, etc. However, the specific kind of the statement is not
1850 CXCursor_UnexposedStmt = 200,
1852 /** \brief A labelled statement in a function.
1854 * This cursor kind is used to describe the "start_over:" label statement in
1855 * the following example:
1863 CXCursor_LabelStmt = 201,
1865 /** \brief A group of statements like { stmt stmt }.
1867 * This cursor kind is used to describe compound statements, e.g. function
1870 CXCursor_CompoundStmt = 202,
1872 /** \brief A case statment.
1874 CXCursor_CaseStmt = 203,
1876 /** \brief A default statement.
1878 CXCursor_DefaultStmt = 204,
1880 /** \brief An if statement
1882 CXCursor_IfStmt = 205,
1884 /** \brief A switch statement.
1886 CXCursor_SwitchStmt = 206,
1888 /** \brief A while statement.
1890 CXCursor_WhileStmt = 207,
1892 /** \brief A do statement.
1894 CXCursor_DoStmt = 208,
1896 /** \brief A for statement.
1898 CXCursor_ForStmt = 209,
1900 /** \brief A goto statement.
1902 CXCursor_GotoStmt = 210,
1904 /** \brief An indirect goto statement.
1906 CXCursor_IndirectGotoStmt = 211,
1908 /** \brief A continue statement.
1910 CXCursor_ContinueStmt = 212,
1912 /** \brief A break statement.
1914 CXCursor_BreakStmt = 213,
1916 /** \brief A return statement.
1918 CXCursor_ReturnStmt = 214,
1920 /** \brief A GNU inline assembly statement extension.
1922 CXCursor_AsmStmt = 215,
1924 /** \brief Objective-C's overall @try-@catch-@finally statement.
1926 CXCursor_ObjCAtTryStmt = 216,
1928 /** \brief Objective-C's @catch statement.
1930 CXCursor_ObjCAtCatchStmt = 217,
1932 /** \brief Objective-C's @finally statement.
1934 CXCursor_ObjCAtFinallyStmt = 218,
1936 /** \brief Objective-C's @throw statement.
1938 CXCursor_ObjCAtThrowStmt = 219,
1940 /** \brief Objective-C's @synchronized statement.
1942 CXCursor_ObjCAtSynchronizedStmt = 220,
1944 /** \brief Objective-C's autorelease pool statement.
1946 CXCursor_ObjCAutoreleasePoolStmt = 221,
1948 /** \brief Objective-C's collection statement.
1950 CXCursor_ObjCForCollectionStmt = 222,
1952 /** \brief C++'s catch statement.
1954 CXCursor_CXXCatchStmt = 223,
1956 /** \brief C++'s try statement.
1958 CXCursor_CXXTryStmt = 224,
1960 /** \brief C++'s for (* : *) statement.
1962 CXCursor_CXXForRangeStmt = 225,
1964 /** \brief Windows Structured Exception Handling's try statement.
1966 CXCursor_SEHTryStmt = 226,
1968 /** \brief Windows Structured Exception Handling's except statement.
1970 CXCursor_SEHExceptStmt = 227,
1972 /** \brief Windows Structured Exception Handling's finally statement.
1974 CXCursor_SEHFinallyStmt = 228,
1976 /** \brief The null satement ";": C99 6.8.3p3.
1978 * This cursor kind is used to describe the null statement.
1980 CXCursor_NullStmt = 230,
1982 /** \brief Adaptor class for mixing declarations with statements and
1985 CXCursor_DeclStmt = 231,
1987 CXCursor_LastStmt = CXCursor_DeclStmt,
1990 * \brief Cursor that represents the translation unit itself.
1992 * The translation unit cursor exists primarily to act as the root
1993 * cursor for traversing the contents of a translation unit.
1995 CXCursor_TranslationUnit = 300,
1998 CXCursor_FirstAttr = 400,
2000 * \brief An attribute whose specific kind is not exposed via this
2003 CXCursor_UnexposedAttr = 400,
2005 CXCursor_IBActionAttr = 401,
2006 CXCursor_IBOutletAttr = 402,
2007 CXCursor_IBOutletCollectionAttr = 403,
2008 CXCursor_CXXFinalAttr = 404,
2009 CXCursor_CXXOverrideAttr = 405,
2010 CXCursor_AnnotateAttr = 406,
2011 CXCursor_AsmLabelAttr = 407,
2012 CXCursor_LastAttr = CXCursor_AsmLabelAttr,
2015 CXCursor_PreprocessingDirective = 500,
2016 CXCursor_MacroDefinition = 501,
2017 CXCursor_MacroExpansion = 502,
2018 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
2019 CXCursor_InclusionDirective = 503,
2020 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
2021 CXCursor_LastPreprocessing = CXCursor_InclusionDirective
2025 * \brief A cursor representing some element in the abstract syntax tree for
2026 * a translation unit.
2028 * The cursor abstraction unifies the different kinds of entities in a
2029 * program--declaration, statements, expressions, references to declarations,
2030 * etc.--under a single "cursor" abstraction with a common set of operations.
2031 * Common operation for a cursor include: getting the physical location in
2032 * a source file where the cursor points, getting the name associated with a
2033 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2035 * Cursors can be produced in two specific ways.
2036 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2037 * from which one can use clang_visitChildren() to explore the rest of the
2038 * translation unit. clang_getCursor() maps from a physical source location
2039 * to the entity that resides at that location, allowing one to map from the
2040 * source code into the AST.
2043 enum CXCursorKind kind;
2049 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2055 * \brief Retrieve the NULL cursor, which represents no entity.
2057 CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
2060 * \brief Retrieve the cursor that represents the given translation unit.
2062 * The translation unit cursor can be used to start traversing the
2063 * various declarations within the given translation unit.
2065 CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2068 * \brief Determine whether two cursors are equivalent.
2070 CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
2073 * \brief Returns non-zero if \arg cursor is null.
2075 CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
2078 * \brief Compute a hash value for the given cursor.
2080 CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2083 * \brief Retrieve the kind of the given cursor.
2085 CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2088 * \brief Determine whether the given cursor kind represents a declaration.
2090 CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2093 * \brief Determine whether the given cursor kind represents a simple
2096 * Note that other kinds of cursors (such as expressions) can also refer to
2097 * other cursors. Use clang_getCursorReferenced() to determine whether a
2098 * particular cursor refers to another entity.
2100 CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2103 * \brief Determine whether the given cursor kind represents an expression.
2105 CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2108 * \brief Determine whether the given cursor kind represents a statement.
2110 CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2113 * \brief Determine whether the given cursor kind represents an attribute.
2115 CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2118 * \brief Determine whether the given cursor kind represents an invalid
2121 CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2124 * \brief Determine whether the given cursor kind represents a translation
2127 CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
2130 * \brief Determine whether the given cursor represents a preprocessing
2131 * element, such as a preprocessor directive or macro instantiation.
2133 CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2136 * \brief Determine whether the given cursor represents a currently
2137 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2139 CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2142 * \brief Describe the linkage of the entity referred to by a cursor.
2144 enum CXLinkageKind {
2145 /** \brief This value indicates that no linkage information is available
2146 * for a provided CXCursor. */
2149 * \brief This is the linkage for variables, parameters, and so on that
2150 * have automatic storage. This covers normal (non-extern) local variables.
2152 CXLinkage_NoLinkage,
2153 /** \brief This is the linkage for static variables and static functions. */
2155 /** \brief This is the linkage for entities with external linkage that live
2156 * in C++ anonymous namespaces.*/
2157 CXLinkage_UniqueExternal,
2158 /** \brief This is the linkage for entities with true, external linkage. */
2163 * \brief Determine the linkage of the entity referred to by a given cursor.
2165 CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2168 * \brief Determine the availability of the entity that this cursor refers to.
2170 * \param cursor The cursor to query.
2172 * \returns The availability of the cursor.
2174 CINDEX_LINKAGE enum CXAvailabilityKind
2175 clang_getCursorAvailability(CXCursor cursor);
2178 * \brief Describe the "language" of the entity referred to by a cursor.
2180 CINDEX_LINKAGE enum CXLanguageKind {
2181 CXLanguage_Invalid = 0,
2184 CXLanguage_CPlusPlus
2188 * \brief Determine the "language" of the entity referred to by a given cursor.
2190 CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2193 * \brief Returns the translation unit that a cursor originated from.
2195 CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2199 * \brief A fast container representing a set of CXCursors.
2201 typedef struct CXCursorSetImpl *CXCursorSet;
2204 * \brief Creates an empty CXCursorSet.
2206 CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2209 * \brief Disposes a CXCursorSet and releases its associated memory.
2211 CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2214 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2216 * \returns non-zero if the set contains the specified cursor.
2218 CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2222 * \brief Inserts a CXCursor into a CXCursorSet.
2224 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2226 CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2230 * \brief Determine the semantic parent of the given cursor.
2232 * The semantic parent of a cursor is the cursor that semantically contains
2233 * the given \p cursor. For many declarations, the lexical and semantic parents
2234 * are equivalent (the lexical parent is returned by
2235 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2236 * definitions are provided out-of-line. For example:
2246 * In the out-of-line definition of \c C::f, the semantic parent is the
2247 * the class \c C, of which this function is a member. The lexical parent is
2248 * the place where the declaration actually occurs in the source code; in this
2249 * case, the definition occurs in the translation unit. In general, the
2250 * lexical parent for a given entity can change without affecting the semantics
2251 * of the program, and the lexical parent of different declarations of the
2252 * same entity may be different. Changing the semantic parent of a declaration,
2253 * on the other hand, can have a major impact on semantics, and redeclarations
2254 * of a particular entity should all have the same semantic context.
2256 * In the example above, both declarations of \c C::f have \c C as their
2257 * semantic context, while the lexical context of the first \c C::f is \c C
2258 * and the lexical context of the second \c C::f is the translation unit.
2260 * For global declarations, the semantic parent is the translation unit.
2262 CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2265 * \brief Determine the lexical parent of the given cursor.
2267 * The lexical parent of a cursor is the cursor in which the given \p cursor
2268 * was actually written. For many declarations, the lexical and semantic parents
2269 * are equivalent (the semantic parent is returned by
2270 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2271 * definitions are provided out-of-line. For example:
2281 * In the out-of-line definition of \c C::f, the semantic parent is the
2282 * the class \c C, of which this function is a member. The lexical parent is
2283 * the place where the declaration actually occurs in the source code; in this
2284 * case, the definition occurs in the translation unit. In general, the
2285 * lexical parent for a given entity can change without affecting the semantics
2286 * of the program, and the lexical parent of different declarations of the
2287 * same entity may be different. Changing the semantic parent of a declaration,
2288 * on the other hand, can have a major impact on semantics, and redeclarations
2289 * of a particular entity should all have the same semantic context.
2291 * In the example above, both declarations of \c C::f have \c C as their
2292 * semantic context, while the lexical context of the first \c C::f is \c C
2293 * and the lexical context of the second \c C::f is the translation unit.
2295 * For declarations written in the global scope, the lexical parent is
2296 * the translation unit.
2298 CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
2301 * \brief Determine the set of methods that are overridden by the given
2304 * In both Objective-C and C++, a method (aka virtual member function,
2305 * in C++) can override a virtual method in a base class. For
2306 * Objective-C, a method is said to override any method in the class's
2307 * base class, its protocols, or its categories' protocols, that has the same
2308 * selector and is of the same kind (class or instance).
2309 * If no such method exists, the search continues to the class's superclass,
2310 * its protocols, and its categories, and so on. A method from an Objective-C
2311 * implementation is considered to override the same methods as its
2312 * corresponding method in the interface.
2314 * For C++, a virtual member function overrides any virtual member
2315 * function with the same signature that occurs in its base
2316 * classes. With multiple inheritance, a virtual member function can
2317 * override several virtual member functions coming from different
2320 * In all cases, this function determines the immediate overridden
2321 * method, rather than all of the overridden methods. For example, if
2322 * a method is originally declared in a class A, then overridden in B
2323 * (which in inherits from A) and also in C (which inherited from B),
2324 * then the only overridden method returned from this function when
2325 * invoked on C's method will be B's method. The client may then
2326 * invoke this function again, given the previously-found overridden
2327 * methods, to map out the complete method-override set.
2329 * \param cursor A cursor representing an Objective-C or C++
2330 * method. This routine will compute the set of methods that this
2333 * \param overridden A pointer whose pointee will be replaced with a
2334 * pointer to an array of cursors, representing the set of overridden
2335 * methods. If there are no overridden methods, the pointee will be
2336 * set to NULL. The pointee must be freed via a call to
2337 * \c clang_disposeOverriddenCursors().
2339 * \param num_overridden A pointer to the number of overridden
2340 * functions, will be set to the number of overridden functions in the
2341 * array pointed to by \p overridden.
2343 CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2344 CXCursor **overridden,
2345 unsigned *num_overridden);
2348 * \brief Free the set of overridden cursors returned by \c
2349 * clang_getOverriddenCursors().
2351 CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2354 * \brief Retrieve the file that is included by the given inclusion directive
2357 CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2364 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2366 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2367 * routines help map between cursors and the physical locations where the
2368 * described entities occur in the source code. The mapping is provided in
2369 * both directions, so one can map from source code to the AST and back.
2375 * \brief Map a source location to the cursor that describes the entity at that
2376 * location in the source code.
2378 * clang_getCursor() maps an arbitrary source location within a translation
2379 * unit down to the most specific cursor that describes the entity at that
2380 * location. For example, given an expression \c x + y, invoking
2381 * clang_getCursor() with a source location pointing to "x" will return the
2382 * cursor for "x"; similarly for "y". If the cursor points anywhere between
2383 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2384 * will return a cursor referring to the "+" expression.
2386 * \returns a cursor representing the entity at the given source location, or
2387 * a NULL cursor if no such entity can be found.
2389 CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
2392 * \brief Retrieve the physical location of the source constructor referenced
2393 * by the given cursor.
2395 * The location of a declaration is typically the location of the name of that
2396 * declaration, where the name of that declaration would occur if it is
2397 * unnamed, or some keyword that introduces that particular declaration.
2398 * The location of a reference is where that reference occurs within the
2401 CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
2404 * \brief Retrieve the physical extent of the source construct referenced by
2407 * The extent of a cursor starts with the file/line/column pointing at the
2408 * first character within the source construct that the cursor refers to and
2409 * ends with the last character withinin that source construct. For a
2410 * declaration, the extent covers the declaration itself. For a reference,
2411 * the extent covers the location of the reference (e.g., where the referenced
2412 * entity was actually used).
2414 CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
2421 * \defgroup CINDEX_TYPES Type information for CXCursors
2427 * \brief Describes the kind of type
2431 * \brief Reprents an invalid type (e.g., where no type is available).
2436 * \brief A type whose specific kind is not exposed via this
2439 CXType_Unexposed = 1,
2451 CXType_ULongLong = 11,
2452 CXType_UInt128 = 12,
2459 CXType_LongLong = 19,
2463 CXType_LongDouble = 23,
2464 CXType_NullPtr = 24,
2465 CXType_Overload = 25,
2466 CXType_Dependent = 26,
2468 CXType_ObjCClass = 28,
2469 CXType_ObjCSel = 29,
2470 CXType_FirstBuiltin = CXType_Void,
2471 CXType_LastBuiltin = CXType_ObjCSel,
2473 CXType_Complex = 100,
2474 CXType_Pointer = 101,
2475 CXType_BlockPointer = 102,
2476 CXType_LValueReference = 103,
2477 CXType_RValueReference = 104,
2478 CXType_Record = 105,
2480 CXType_Typedef = 107,
2481 CXType_ObjCInterface = 108,
2482 CXType_ObjCObjectPointer = 109,
2483 CXType_FunctionNoProto = 110,
2484 CXType_FunctionProto = 111,
2485 CXType_ConstantArray = 112,
2490 * \brief Describes the calling convention of a function type
2492 enum CXCallingConv {
2493 CXCallingConv_Default = 0,
2494 CXCallingConv_C = 1,
2495 CXCallingConv_X86StdCall = 2,
2496 CXCallingConv_X86FastCall = 3,
2497 CXCallingConv_X86ThisCall = 4,
2498 CXCallingConv_X86Pascal = 5,
2499 CXCallingConv_AAPCS = 6,
2500 CXCallingConv_AAPCS_VFP = 7,
2502 CXCallingConv_Invalid = 100,
2503 CXCallingConv_Unexposed = 200
2508 * \brief The type of an element in the abstract syntax tree.
2512 enum CXTypeKind kind;
2517 * \brief Retrieve the type of a CXCursor (if any).
2519 CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2522 * \brief Retrieve the underlying type of a typedef declaration.
2524 * If the cursor does not reference a typedef declaration, an invalid type is
2527 CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2530 * \brief Retrieve the integer type of an enum declaration.
2532 * If the cursor does not reference an enum declaration, an invalid type is
2535 CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2538 * \brief Retrieve the integer value of an enum constant declaration as a signed
2541 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2542 * Since this is also potentially a valid constant value, the kind of the cursor
2543 * must be verified before calling this function.
2545 CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2548 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2551 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2552 * Since this is also potentially a valid constant value, the kind of the cursor
2553 * must be verified before calling this function.
2555 CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2558 * \brief Retrieve the number of non-variadic arguments associated with a given
2561 * If a cursor that is not a function or method is passed in, -1 is returned.
2563 CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
2566 * \brief Retrieve the argument cursor of a function or method.
2568 * If a cursor that is not a function or method is passed in or the index
2569 * exceeds the number of arguments, an invalid cursor is returned.
2571 CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
2574 * \determine Determine whether two CXTypes represent the same type.
2576 * \returns non-zero if the CXTypes represent the same type and
2579 CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2582 * \brief Return the canonical type for a CXType.
2584 * Clang's type system explicitly models typedefs and all the ways
2585 * a specific type can be represented. The canonical type is the underlying
2586 * type with all the "sugar" removed. For example, if 'T' is a typedef
2587 * for 'int', the canonical type for 'T' would be 'int'.
2589 CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2592 * \determine Determine whether a CXType has the "const" qualifier set,
2593 * without looking through typedefs that may have added "const" at a different level.
2595 CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2598 * \determine Determine whether a CXType has the "volatile" qualifier set,
2599 * without looking through typedefs that may have added "volatile" at a different level.
2601 CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2604 * \determine Determine whether a CXType has the "restrict" qualifier set,
2605 * without looking through typedefs that may have added "restrict" at a different level.
2607 CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2610 * \brief For pointer types, returns the type of the pointee.
2613 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2616 * \brief Return the cursor for the declaration of the given type.
2618 CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2621 * Returns the Objective-C type encoding for the specified declaration.
2623 CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
2626 * \brief Retrieve the spelling of a given CXTypeKind.
2628 CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2631 * \brief Retrieve the calling convention associated with a function type.
2633 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2635 CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2638 * \brief Retrieve the result type associated with a function type.
2640 * If a non-function type is passed in, an invalid type is returned.
2642 CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2645 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2647 * If a non-function type is passed in, -1 is returned.
2649 CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
2652 * \brief Retrieve the type of an argument of a function type.
2654 * If a non-function type is passed in or the function does not have enough parameters,
2655 * an invalid type is returned.
2657 CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2660 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2663 CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2666 * \brief Retrieve the result type associated with a given cursor.
2668 * This only returns a valid type if the cursor refers to a function or method.
2670 CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2673 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2676 CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2679 * \brief Return the element type of an array, complex, or vector type.
2681 * If a type is passed in that is not an array, complex, or vector type,
2682 * an invalid type is returned.
2684 CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2687 * \brief Return the number of elements of an array or vector type.
2689 * If a type is passed in that is not an array or vector type,
2692 CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2695 * \brief Return the element type of an array type.
2697 * If a non-array type is passed in, an invalid type is returned.
2699 CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2702 * \brief Return the the array size of a constant array.
2704 * If a non-array type is passed in, -1 is returned.
2706 CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2709 * \brief Returns 1 if the base class specified by the cursor with kind
2710 * CX_CXXBaseSpecifier is virtual.
2712 CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2715 * \brief Represents the C++ access control level to a base class for a
2716 * cursor with kind CX_CXXBaseSpecifier.
2718 enum CX_CXXAccessSpecifier {
2719 CX_CXXInvalidAccessSpecifier,
2726 * \brief Returns the access control level for the C++ base specifier
2727 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2728 * CXCursor_AccessSpecifier.
2730 CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2733 * \brief Determine the number of overloaded declarations referenced by a
2734 * \c CXCursor_OverloadedDeclRef cursor.
2736 * \param cursor The cursor whose overloaded declarations are being queried.
2738 * \returns The number of overloaded declarations referenced by \c cursor. If it
2739 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2741 CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2744 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2745 * by a \c CXCursor_OverloadedDeclRef cursor.
2747 * \param cursor The cursor whose overloaded declarations are being queried.
2749 * \param index The zero-based index into the set of overloaded declarations in
2752 * \returns A cursor representing the declaration referenced by the given
2753 * \c cursor at the specified \c index. If the cursor does not have an
2754 * associated set of overloaded declarations, or if the index is out of bounds,
2755 * returns \c clang_getNullCursor();
2757 CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2765 * \defgroup CINDEX_ATTRIBUTES Information for attributes
2772 * \brief For cursors representing an iboutletcollection attribute,
2773 * this function returns the collection element type.
2776 CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2783 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2785 * These routines provide the ability to traverse the abstract syntax tree
2792 * \brief Describes how the traversal of the children of a particular
2793 * cursor should proceed after visiting a particular child cursor.
2795 * A value of this enumeration type should be returned by each
2796 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2798 enum CXChildVisitResult {
2800 * \brief Terminates the cursor traversal.
2804 * \brief Continues the cursor traversal with the next sibling of
2805 * the cursor just visited, without visiting its children.
2807 CXChildVisit_Continue,
2809 * \brief Recursively traverse the children of this cursor, using
2810 * the same visitor and client data.
2812 CXChildVisit_Recurse
2816 * \brief Visitor invoked for each cursor found by a traversal.
2818 * This visitor function will be invoked for each cursor found by
2819 * clang_visitCursorChildren(). Its first argument is the cursor being
2820 * visited, its second argument is the parent visitor for that cursor,
2821 * and its third argument is the client data provided to
2822 * clang_visitCursorChildren().
2824 * The visitor should return one of the \c CXChildVisitResult values
2825 * to direct clang_visitCursorChildren().
2827 typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2829 CXClientData client_data);
2832 * \brief Visit the children of a particular cursor.
2834 * This function visits all the direct children of the given cursor,
2835 * invoking the given \p visitor function with the cursors of each
2836 * visited child. The traversal may be recursive, if the visitor returns
2837 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2838 * the visitor returns \c CXChildVisit_Break.
2840 * \param parent the cursor whose child may be visited. All kinds of
2841 * cursors can be visited, including invalid cursors (which, by
2842 * definition, have no children).
2844 * \param visitor the visitor function that will be invoked for each
2845 * child of \p parent.
2847 * \param client_data pointer data supplied by the client, which will
2848 * be passed to the visitor each time it is invoked.
2850 * \returns a non-zero value if the traversal was terminated
2851 * prematurely by the visitor returning \c CXChildVisit_Break.
2853 CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
2854 CXCursorVisitor visitor,
2855 CXClientData client_data);
2856 #ifdef __has_feature
2857 # if __has_feature(blocks)
2859 * \brief Visitor invoked for each cursor found by a traversal.
2861 * This visitor block will be invoked for each cursor found by
2862 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2863 * visited, its second argument is the parent visitor for that cursor.
2865 * The visitor should return one of the \c CXChildVisitResult values
2866 * to direct clang_visitChildrenWithBlock().
2868 typedef enum CXChildVisitResult
2869 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2872 * Visits the children of a cursor using the specified block. Behaves
2873 * identically to clang_visitChildren() in all other respects.
2875 unsigned clang_visitChildrenWithBlock(CXCursor parent,
2876 CXCursorVisitorBlock block);
2885 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2887 * These routines provide the ability to determine references within and
2888 * across translation units, by providing the names of the entities referenced
2889 * by cursors, follow reference cursors to the declarations they reference,
2890 * and associate declarations with their definitions.
2896 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2897 * by the given cursor.
2899 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2900 * entity (function, class, variable, etc.) within a program. USRs can be
2901 * compared across translation units to determine, e.g., when references in
2902 * one translation refer to an entity defined in another translation unit.
2904 CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2907 * \brief Construct a USR for a specified Objective-C class.
2909 CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2912 * \brief Construct a USR for a specified Objective-C category.
2914 CINDEX_LINKAGE CXString
2915 clang_constructUSR_ObjCCategory(const char *class_name,
2916 const char *category_name);
2919 * \brief Construct a USR for a specified Objective-C protocol.
2921 CINDEX_LINKAGE CXString
2922 clang_constructUSR_ObjCProtocol(const char *protocol_name);
2926 * \brief Construct a USR for a specified Objective-C instance variable and
2927 * the USR for its containing class.
2929 CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2933 * \brief Construct a USR for a specified Objective-C method and
2934 * the USR for its containing class.
2936 CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2937 unsigned isInstanceMethod,
2941 * \brief Construct a USR for a specified Objective-C property and the USR
2942 * for its containing class.
2944 CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2948 * \brief Retrieve a name for the entity referenced by this cursor.
2950 CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2953 * \brief Retrieve a range for a piece that forms the cursors spelling name.
2954 * Most of the times there is only one range for the complete spelling but for
2955 * objc methods and objc message expressions, there are multiple pieces for each
2956 * selector identifier.
2958 * \param pieceIndex the index of the spelling name piece. If this is greater
2959 * than the actual number of pieces, it will return a NULL (invalid) range.
2961 * \param options Reserved.
2963 CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
2964 unsigned pieceIndex,
2968 * \brief Retrieve the display name for the entity referenced by this cursor.
2970 * The display name contains extra information that helps identify the cursor,
2971 * such as the parameters of a function or template or the arguments of a
2972 * class template specialization.
2974 CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2976 /** \brief For a cursor that is a reference, retrieve a cursor representing the
2977 * entity that it references.
2979 * Reference cursors refer to other entities in the AST. For example, an
2980 * Objective-C superclass reference cursor refers to an Objective-C class.
2981 * This function produces the cursor for the Objective-C class from the
2982 * cursor for the superclass reference. If the input cursor is a declaration or
2983 * definition, it returns that declaration or definition unchanged.
2984 * Otherwise, returns the NULL cursor.
2986 CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
2989 * \brief For a cursor that is either a reference to or a declaration
2990 * of some entity, retrieve a cursor that describes the definition of
2993 * Some entities can be declared multiple times within a translation
2994 * unit, but only one of those declarations can also be a
2995 * definition. For example, given:
2999 * int g(int x, int y) { return f(x, y); }
3000 * int f(int a, int b) { return a + b; }
3004 * there are three declarations of the function "f", but only the
3005 * second one is a definition. The clang_getCursorDefinition()
3006 * function will take any cursor pointing to a declaration of "f"
3007 * (the first or fourth lines of the example) or a cursor referenced
3008 * that uses "f" (the call to "f' inside "g") and will return a
3009 * declaration cursor pointing to the definition (the second "f"
3012 * If given a cursor for which there is no corresponding definition,
3013 * e.g., because there is no definition of that entity within this
3014 * translation unit, returns a NULL cursor.
3016 CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
3019 * \brief Determine whether the declaration pointed to by this cursor
3020 * is also a definition of that entity.
3022 CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
3025 * \brief Retrieve the canonical cursor corresponding to the given cursor.
3027 * In the C family of languages, many kinds of entities can be declared several
3028 * times within a single translation unit. For example, a structure type can
3029 * be forward-declared (possibly multiple times) and later defined:
3039 * The declarations and the definition of \c X are represented by three
3040 * different cursors, all of which are declarations of the same underlying
3041 * entity. One of these cursor is considered the "canonical" cursor, which
3042 * is effectively the representative for the underlying entity. One can
3043 * determine if two cursors are declarations of the same underlying entity by
3044 * comparing their canonical cursors.
3046 * \returns The canonical cursor for the entity referred to by the given cursor.
3048 CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
3052 * \brief If the cursor points to a selector identifier in a objc method or
3053 * message expression, this returns the selector index.
3055 * After getting a cursor with \see clang_getCursor, this can be called to
3056 * determine if the location points to a selector identifier.
3058 * \returns The selector index if the cursor is an objc method or message
3059 * expression and the cursor is pointing to a selector identifier, or -1
3062 CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
3069 * \defgroup CINDEX_CPP C++ AST introspection
3071 * The routines in this group provide access information in the ASTs specific
3072 * to C++ language features.
3078 * \brief Determine if a C++ member function or member function template is
3079 * declared 'static'.
3081 CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
3084 * \brief Determine if a C++ member function or member function template is
3085 * explicitly declared 'virtual' or if it overrides a virtual method from
3086 * one of the base classes.
3088 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
3091 * \brief Given a cursor that represents a template, determine
3092 * the cursor kind of the specializations would be generated by instantiating
3095 * This routine can be used to determine what flavor of function template,
3096 * class template, or class template partial specialization is stored in the
3097 * cursor. For example, it can describe whether a class template cursor is
3098 * declared with "struct", "class" or "union".
3100 * \param C The cursor to query. This cursor should represent a template
3103 * \returns The cursor kind of the specializations that would be generated
3104 * by instantiating the template \p C. If \p C is not a template, returns
3105 * \c CXCursor_NoDeclFound.
3107 CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
3110 * \brief Given a cursor that may represent a specialization or instantiation
3111 * of a template, retrieve the cursor that represents the template that it
3112 * specializes or from which it was instantiated.
3114 * This routine determines the template involved both for explicit
3115 * specializations of templates and for implicit instantiations of the template,
3116 * both of which are referred to as "specializations". For a class template
3117 * specialization (e.g., \c std::vector<bool>), this routine will return
3118 * either the primary template (\c std::vector) or, if the specialization was
3119 * instantiated from a class template partial specialization, the class template
3120 * partial specialization. For a class template partial specialization and a
3121 * function template specialization (including instantiations), this
3122 * this routine will return the specialized template.
3124 * For members of a class template (e.g., member functions, member classes, or
3125 * static data members), returns the specialized or instantiated member.
3126 * Although not strictly "templates" in the C++ language, members of class
3127 * templates have the same notions of specializations and instantiations that
3128 * templates do, so this routine treats them similarly.
3130 * \param C A cursor that may be a specialization of a template or a member
3133 * \returns If the given cursor is a specialization or instantiation of a
3134 * template or a member thereof, the template or member that it specializes or
3135 * from which it was instantiated. Otherwise, returns a NULL cursor.
3137 CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
3140 * \brief Given a cursor that references something else, return the source range
3141 * covering that reference.
3143 * \param C A cursor pointing to a member reference, a declaration reference, or
3145 * \param NameFlags A bitset with three independent flags:
3146 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3147 * CXNameRange_WantSinglePiece.
3148 * \param PieceIndex For contiguous names or when passing the flag
3149 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3150 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
3151 * non-contiguous names, this index can be used to retreive the individual
3152 * pieces of the name. See also CXNameRange_WantSinglePiece.
3154 * \returns The piece of the name pointed to by the given cursor. If there is no
3155 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3157 CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3159 unsigned PieceIndex);
3161 enum CXNameRefFlags {
3163 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3166 CXNameRange_WantQualifier = 0x1,
3169 * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3172 CXNameRange_WantTemplateArgs = 0x2,
3175 * \brief If the name is non-contiguous, return the full spanning range.
3177 * Non-contiguous names occur in Objective-C when a selector with two or more
3178 * parameters is used, or in C++ when using an operator:
3180 * [object doSomething:here withValue:there]; // ObjC
3181 * return some_vector[1]; // C++
3184 CXNameRange_WantSinglePiece = 0x4
3192 * \defgroup CINDEX_LEX Token extraction and manipulation
3194 * The routines in this group provide access to the tokens within a
3195 * translation unit, along with a semantic mapping of those tokens to
3196 * their corresponding cursors.
3202 * \brief Describes a kind of token.
3204 typedef enum CXTokenKind {
3206 * \brief A token that contains some kind of punctuation.
3208 CXToken_Punctuation,
3211 * \brief A language keyword.
3216 * \brief An identifier (that is not a keyword).
3221 * \brief A numeric, string, or character literal.
3232 * \brief Describes a single preprocessing token.
3235 unsigned int_data[4];
3240 * \brief Determine the kind of the given token.
3242 CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
3245 * \brief Determine the spelling of the given token.
3247 * The spelling of a token is the textual representation of that token, e.g.,
3248 * the text of an identifier or keyword.
3250 CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
3253 * \brief Retrieve the source location of the given token.
3255 CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
3259 * \brief Retrieve a source range that covers the given token.
3261 CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3264 * \brief Tokenize the source code described by the given range into raw
3267 * \param TU the translation unit whose text is being tokenized.
3269 * \param Range the source range in which text should be tokenized. All of the
3270 * tokens produced by tokenization will fall within this source range,
3272 * \param Tokens this pointer will be set to point to the array of tokens
3273 * that occur within the given source range. The returned pointer must be
3274 * freed with clang_disposeTokens() before the translation unit is destroyed.
3276 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3280 CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3281 CXToken **Tokens, unsigned *NumTokens);
3284 * \brief Annotate the given set of tokens by providing cursors for each token
3285 * that can be mapped to a specific entity within the abstract syntax tree.
3287 * This token-annotation routine is equivalent to invoking
3288 * clang_getCursor() for the source locations of each of the
3289 * tokens. The cursors provided are filtered, so that only those
3290 * cursors that have a direct correspondence to the token are
3291 * accepted. For example, given a function call \c f(x),
3292 * clang_getCursor() would provide the following cursors:
3294 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3295 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3296 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3298 * Only the first and last of these cursors will occur within the
3299 * annotate, since the tokens "f" and "x' directly refer to a function
3300 * and a variable, respectively, but the parentheses are just a small
3301 * part of the full syntax of the function call expression, which is
3302 * not provided as an annotation.
3304 * \param TU the translation unit that owns the given tokens.
3306 * \param Tokens the set of tokens to annotate.
3308 * \param NumTokens the number of tokens in \p Tokens.
3310 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3311 * replaced with the cursors corresponding to each token.
3313 CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3314 CXToken *Tokens, unsigned NumTokens,
3318 * \brief Free the given set of tokens.
3320 CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
3321 CXToken *Tokens, unsigned NumTokens);
3328 * \defgroup CINDEX_DEBUG Debugging facilities
3330 * These routines are used for testing and debugging, only, and should not
3336 /* for debug/testing */
3337 CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
3338 CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3339 const char **startBuf,
3340 const char **endBuf,
3341 unsigned *startLine,
3342 unsigned *startColumn,
3344 unsigned *endColumn);
3345 CINDEX_LINKAGE void clang_enableStackTraces(void);
3346 CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3347 unsigned stack_size);
3354 * \defgroup CINDEX_CODE_COMPLET Code completion
3356 * Code completion involves taking an (incomplete) source file, along with
3357 * knowledge of where the user is actively editing that file, and suggesting
3358 * syntactically- and semantically-valid constructs that the user might want to
3359 * use at that particular point in the source code. These data structures and
3360 * routines provide support for code completion.
3366 * \brief A semantic string that describes a code-completion result.
3368 * A semantic string that describes the formatting of a code-completion
3369 * result as a single "template" of text that should be inserted into the
3370 * source buffer when a particular code-completion result is selected.
3371 * Each semantic string is made up of some number of "chunks", each of which
3372 * contains some text along with a description of what that text means, e.g.,
3373 * the name of the entity being referenced, whether the text chunk is part of
3374 * the template, or whether it is a "placeholder" that the user should replace
3375 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
3376 * description of the different kinds of chunks.
3378 typedef void *CXCompletionString;
3381 * \brief A single result of code completion.
3385 * \brief The kind of entity that this completion refers to.
3387 * The cursor kind will be a macro, keyword, or a declaration (one of the
3388 * *Decl cursor kinds), describing the entity that the completion is
3391 * \todo In the future, we would like to provide a full cursor, to allow
3392 * the client to extract additional information from declaration.
3394 enum CXCursorKind CursorKind;
3397 * \brief The code-completion string that describes how to insert this
3398 * code-completion result into the editing buffer.
3400 CXCompletionString CompletionString;
3401 } CXCompletionResult;
3404 * \brief Describes a single piece of text within a code-completion string.
3406 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3407 * either a piece of text with a specific "kind" that describes how that text
3408 * should be interpreted by the client or is another completion string.
3410 enum CXCompletionChunkKind {
3412 * \brief A code-completion string that describes "optional" text that
3413 * could be a part of the template (but is not required).
3415 * The Optional chunk is the only kind of chunk that has a code-completion
3416 * string for its representation, which is accessible via
3417 * \c clang_getCompletionChunkCompletionString(). The code-completion string
3418 * describes an additional part of the template that is completely optional.
3419 * For example, optional chunks can be used to describe the placeholders for
3420 * arguments that match up with defaulted function parameters, e.g. given:
3423 * void f(int x, float y = 3.14, double z = 2.71828);
3426 * The code-completion string for this function would contain:
3427 * - a TypedText chunk for "f".
3428 * - a LeftParen chunk for "(".
3429 * - a Placeholder chunk for "int x"
3430 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
3431 * - a Comma chunk for ","
3432 * - a Placeholder chunk for "float y"
3433 * - an Optional chunk containing the last defaulted argument:
3434 * - a Comma chunk for ","
3435 * - a Placeholder chunk for "double z"
3436 * - a RightParen chunk for ")"
3438 * There are many ways to handle Optional chunks. Two simple approaches are:
3439 * - Completely ignore optional chunks, in which case the template for the
3440 * function "f" would only include the first parameter ("int x").
3441 * - Fully expand all optional chunks, in which case the template for the
3442 * function "f" would have all of the parameters.
3444 CXCompletionChunk_Optional,
3446 * \brief Text that a user would be expected to type to get this
3447 * code-completion result.
3449 * There will be exactly one "typed text" chunk in a semantic string, which
3450 * will typically provide the spelling of a keyword or the name of a
3451 * declaration that could be used at the current code point. Clients are
3452 * expected to filter the code-completion results based on the text in this
3455 CXCompletionChunk_TypedText,
3457 * \brief Text that should be inserted as part of a code-completion result.
3459 * A "text" chunk represents text that is part of the template to be
3460 * inserted into user code should this particular code-completion result
3463 CXCompletionChunk_Text,
3465 * \brief Placeholder text that should be replaced by the user.
3467 * A "placeholder" chunk marks a place where the user should insert text
3468 * into the code-completion template. For example, placeholders might mark
3469 * the function parameters for a function declaration, to indicate that the
3470 * user should provide arguments for each of those parameters. The actual
3471 * text in a placeholder is a suggestion for the text to display before
3472 * the user replaces the placeholder with real code.
3474 CXCompletionChunk_Placeholder,
3476 * \brief Informative text that should be displayed but never inserted as
3477 * part of the template.
3479 * An "informative" chunk contains annotations that can be displayed to
3480 * help the user decide whether a particular code-completion result is the
3481 * right option, but which is not part of the actual template to be inserted
3482 * by code completion.
3484 CXCompletionChunk_Informative,
3486 * \brief Text that describes the current parameter when code-completion is
3487 * referring to function call, message send, or template specialization.
3489 * A "current parameter" chunk occurs when code-completion is providing
3490 * information about a parameter corresponding to the argument at the
3491 * code-completion point. For example, given a function
3494 * int add(int x, int y);
3497 * and the source code \c add(, where the code-completion point is after the
3498 * "(", the code-completion string will contain a "current parameter" chunk
3499 * for "int x", indicating that the current argument will initialize that
3500 * parameter. After typing further, to \c add(17, (where the code-completion
3501 * point is after the ","), the code-completion string will contain a
3502 * "current paremeter" chunk to "int y".
3504 CXCompletionChunk_CurrentParameter,
3506 * \brief A left parenthesis ('('), used to initiate a function call or
3507 * signal the beginning of a function parameter list.
3509 CXCompletionChunk_LeftParen,
3511 * \brief A right parenthesis (')'), used to finish a function call or
3512 * signal the end of a function parameter list.
3514 CXCompletionChunk_RightParen,
3516 * \brief A left bracket ('[').
3518 CXCompletionChunk_LeftBracket,
3520 * \brief A right bracket (']').
3522 CXCompletionChunk_RightBracket,
3524 * \brief A left brace ('{').
3526 CXCompletionChunk_LeftBrace,
3528 * \brief A right brace ('}').
3530 CXCompletionChunk_RightBrace,
3532 * \brief A left angle bracket ('<').
3534 CXCompletionChunk_LeftAngle,
3536 * \brief A right angle bracket ('>').
3538 CXCompletionChunk_RightAngle,
3540 * \brief A comma separator (',').
3542 CXCompletionChunk_Comma,
3544 * \brief Text that specifies the result type of a given result.
3546 * This special kind of informative chunk is not meant to be inserted into
3547 * the text buffer. Rather, it is meant to illustrate the type that an
3548 * expression using the given completion string would have.
3550 CXCompletionChunk_ResultType,
3552 * \brief A colon (':').
3554 CXCompletionChunk_Colon,
3556 * \brief A semicolon (';').
3558 CXCompletionChunk_SemiColon,
3560 * \brief An '=' sign.
3562 CXCompletionChunk_Equal,
3564 * Horizontal space (' ').
3566 CXCompletionChunk_HorizontalSpace,
3568 * Vertical space ('\n'), after which it is generally a good idea to
3569 * perform indentation.
3571 CXCompletionChunk_VerticalSpace
3575 * \brief Determine the kind of a particular chunk within a completion string.
3577 * \param completion_string the completion string to query.
3579 * \param chunk_number the 0-based index of the chunk in the completion string.
3581 * \returns the kind of the chunk at the index \c chunk_number.
3583 CINDEX_LINKAGE enum CXCompletionChunkKind
3584 clang_getCompletionChunkKind(CXCompletionString completion_string,
3585 unsigned chunk_number);
3588 * \brief Retrieve the text associated with a particular chunk within a
3589 * completion string.
3591 * \param completion_string the completion string to query.
3593 * \param chunk_number the 0-based index of the chunk in the completion string.
3595 * \returns the text associated with the chunk at index \c chunk_number.
3597 CINDEX_LINKAGE CXString
3598 clang_getCompletionChunkText(CXCompletionString completion_string,
3599 unsigned chunk_number);
3602 * \brief Retrieve the completion string associated with a particular chunk
3603 * within a completion string.
3605 * \param completion_string the completion string to query.
3607 * \param chunk_number the 0-based index of the chunk in the completion string.
3609 * \returns the completion string associated with the chunk at index
3612 CINDEX_LINKAGE CXCompletionString
3613 clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3614 unsigned chunk_number);
3617 * \brief Retrieve the number of chunks in the given code-completion string.
3619 CINDEX_LINKAGE unsigned
3620 clang_getNumCompletionChunks(CXCompletionString completion_string);
3623 * \brief Determine the priority of this code completion.
3625 * The priority of a code completion indicates how likely it is that this
3626 * particular completion is the completion that the user will select. The
3627 * priority is selected by various internal heuristics.
3629 * \param completion_string The completion string to query.
3631 * \returns The priority of this completion string. Smaller values indicate
3632 * higher-priority (more likely) completions.
3634 CINDEX_LINKAGE unsigned
3635 clang_getCompletionPriority(CXCompletionString completion_string);
3638 * \brief Determine the availability of the entity that this code-completion
3641 * \param completion_string The completion string to query.
3643 * \returns The availability of the completion string.
3645 CINDEX_LINKAGE enum CXAvailabilityKind
3646 clang_getCompletionAvailability(CXCompletionString completion_string);
3649 * \brief Retrieve the number of annotations associated with the given
3650 * completion string.
3652 * \param completion_string the completion string to query.
3654 * \returns the number of annotations associated with the given completion
3657 CINDEX_LINKAGE unsigned
3658 clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3661 * \brief Retrieve the annotation associated with the given completion string.
3663 * \param completion_string the completion string to query.
3665 * \param annotation_number the 0-based index of the annotation of the
3666 * completion string.
3668 * \returns annotation string associated with the completion at index
3669 * \c annotation_number, or a NULL string if that annotation is not available.
3671 CINDEX_LINKAGE CXString
3672 clang_getCompletionAnnotation(CXCompletionString completion_string,
3673 unsigned annotation_number);
3676 * \brief Retrieve the parent context of the given completion string.
3678 * The parent context of a completion string is the semantic parent of
3679 * the declaration (if any) that the code completion represents. For example,
3680 * a code completion for an Objective-C method would have the method's class
3681 * or protocol as its context.
3683 * \param completion_string The code completion string whose parent is
3686 * \param kind If non-NULL, will be set to the kind of the parent context,
3687 * or CXCursor_NotImplemented if there is no context.
3689 * \param Returns the name of the completion parent, e.g., "NSObject" if
3690 * the completion string represents a method in the NSObject class.
3692 CINDEX_LINKAGE CXString
3693 clang_getCompletionParent(CXCompletionString completion_string,
3694 enum CXCursorKind *kind);
3696 * \brief Retrieve a completion string for an arbitrary declaration or macro
3697 * definition cursor.
3699 * \param cursor The cursor to query.
3701 * \returns A non-context-sensitive completion string for declaration and macro
3702 * definition cursors, or NULL for other kinds of cursors.
3704 CINDEX_LINKAGE CXCompletionString
3705 clang_getCursorCompletionString(CXCursor cursor);
3708 * \brief Contains the results of code-completion.
3710 * This data structure contains the results of code completion, as
3711 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
3712 * \c clang_disposeCodeCompleteResults.
3716 * \brief The code-completion results.
3718 CXCompletionResult *Results;
3721 * \brief The number of code-completion results stored in the
3724 unsigned NumResults;
3725 } CXCodeCompleteResults;
3728 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3729 * modify its behavior.
3731 * The enumerators in this enumeration can be bitwise-OR'd together to
3732 * provide multiple options to \c clang_codeCompleteAt().
3734 enum CXCodeComplete_Flags {
3736 * \brief Whether to include macros within the set of code
3737 * completions returned.
3739 CXCodeComplete_IncludeMacros = 0x01,
3742 * \brief Whether to include code patterns for language constructs
3743 * within the set of code completions, e.g., for loops.
3745 CXCodeComplete_IncludeCodePatterns = 0x02
3749 * \brief Bits that represent the context under which completion is occurring.
3751 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3752 * contexts are occurring simultaneously.
3754 enum CXCompletionContext {
3756 * \brief The context for completions is unexposed, as only Clang results
3757 * should be included. (This is equivalent to having no context bits set.)
3759 CXCompletionContext_Unexposed = 0,
3762 * \brief Completions for any possible type should be included in the results.
3764 CXCompletionContext_AnyType = 1 << 0,
3767 * \brief Completions for any possible value (variables, function calls, etc.)
3768 * should be included in the results.
3770 CXCompletionContext_AnyValue = 1 << 1,
3772 * \brief Completions for values that resolve to an Objective-C object should
3773 * be included in the results.
3775 CXCompletionContext_ObjCObjectValue = 1 << 2,
3777 * \brief Completions for values that resolve to an Objective-C selector
3778 * should be included in the results.
3780 CXCompletionContext_ObjCSelectorValue = 1 << 3,
3782 * \brief Completions for values that resolve to a C++ class type should be
3783 * included in the results.
3785 CXCompletionContext_CXXClassTypeValue = 1 << 4,
3788 * \brief Completions for fields of the member being accessed using the dot
3789 * operator should be included in the results.
3791 CXCompletionContext_DotMemberAccess = 1 << 5,
3793 * \brief Completions for fields of the member being accessed using the arrow
3794 * operator should be included in the results.
3796 CXCompletionContext_ArrowMemberAccess = 1 << 6,
3798 * \brief Completions for properties of the Objective-C object being accessed
3799 * using the dot operator should be included in the results.
3801 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3804 * \brief Completions for enum tags should be included in the results.
3806 CXCompletionContext_EnumTag = 1 << 8,
3808 * \brief Completions for union tags should be included in the results.
3810 CXCompletionContext_UnionTag = 1 << 9,
3812 * \brief Completions for struct tags should be included in the results.
3814 CXCompletionContext_StructTag = 1 << 10,
3817 * \brief Completions for C++ class names should be included in the results.
3819 CXCompletionContext_ClassTag = 1 << 11,
3821 * \brief Completions for C++ namespaces and namespace aliases should be
3822 * included in the results.
3824 CXCompletionContext_Namespace = 1 << 12,
3826 * \brief Completions for C++ nested name specifiers should be included in
3829 CXCompletionContext_NestedNameSpecifier = 1 << 13,
3832 * \brief Completions for Objective-C interfaces (classes) should be included
3835 CXCompletionContext_ObjCInterface = 1 << 14,
3837 * \brief Completions for Objective-C protocols should be included in
3840 CXCompletionContext_ObjCProtocol = 1 << 15,
3842 * \brief Completions for Objective-C categories should be included in
3845 CXCompletionContext_ObjCCategory = 1 << 16,
3847 * \brief Completions for Objective-C instance messages should be included
3850 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3852 * \brief Completions for Objective-C class messages should be included in
3855 CXCompletionContext_ObjCClassMessage = 1 << 18,
3857 * \brief Completions for Objective-C selector names should be included in
3860 CXCompletionContext_ObjCSelectorName = 1 << 19,
3863 * \brief Completions for preprocessor macro names should be included in
3866 CXCompletionContext_MacroName = 1 << 20,
3869 * \brief Natural language completions should be included in the results.
3871 CXCompletionContext_NaturalLanguage = 1 << 21,
3874 * \brief The current context is unknown, so set all contexts.
3876 CXCompletionContext_Unknown = ((1 << 22) - 1)
3880 * \brief Returns a default set of code-completion options that can be
3881 * passed to\c clang_codeCompleteAt().
3883 CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3886 * \brief Perform code completion at a given location in a translation unit.
3888 * This function performs code completion at a particular file, line, and
3889 * column within source code, providing results that suggest potential
3890 * code snippets based on the context of the completion. The basic model
3891 * for code completion is that Clang will parse a complete source file,
3892 * performing syntax checking up to the location where code-completion has
3893 * been requested. At that point, a special code-completion token is passed
3894 * to the parser, which recognizes this token and determines, based on the
3895 * current location in the C/Objective-C/C++ grammar and the state of
3896 * semantic analysis, what completions to provide. These completions are
3897 * returned via a new \c CXCodeCompleteResults structure.
3899 * Code completion itself is meant to be triggered by the client when the
3900 * user types punctuation characters or whitespace, at which point the
3901 * code-completion location will coincide with the cursor. For example, if \c p
3902 * is a pointer, code-completion might be triggered after the "-" and then
3903 * after the ">" in \c p->. When the code-completion location is afer the ">",
3904 * the completion results will provide, e.g., the members of the struct that
3905 * "p" points to. The client is responsible for placing the cursor at the
3906 * beginning of the token currently being typed, then filtering the results
3907 * based on the contents of the token. For example, when code-completing for
3908 * the expression \c p->get, the client should provide the location just after
3909 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3910 * client can filter the results based on the current token text ("get"), only
3911 * showing those results that start with "get". The intent of this interface
3912 * is to separate the relatively high-latency acquisition of code-completion
3913 * results from the filtering of results on a per-character basis, which must
3914 * have a lower latency.
3916 * \param TU The translation unit in which code-completion should
3917 * occur. The source files for this translation unit need not be
3918 * completely up-to-date (and the contents of those source files may
3919 * be overridden via \p unsaved_files). Cursors referring into the
3920 * translation unit may be invalidated by this invocation.
3922 * \param complete_filename The name of the source file where code
3923 * completion should be performed. This filename may be any file
3924 * included in the translation unit.
3926 * \param complete_line The line at which code-completion should occur.
3928 * \param complete_column The column at which code-completion should occur.
3929 * Note that the column should point just after the syntactic construct that
3930 * initiated code completion, and not in the middle of a lexical token.
3932 * \param unsaved_files the Tiles that have not yet been saved to disk
3933 * but may be required for parsing or code completion, including the
3934 * contents of those files. The contents and name of these files (as
3935 * specified by CXUnsavedFile) are copied when necessary, so the
3936 * client only needs to guarantee their validity until the call to
3937 * this function returns.
3939 * \param num_unsaved_files The number of unsaved file entries in \p
3942 * \param options Extra options that control the behavior of code
3943 * completion, expressed as a bitwise OR of the enumerators of the
3944 * CXCodeComplete_Flags enumeration. The
3945 * \c clang_defaultCodeCompleteOptions() function returns a default set
3946 * of code-completion options.
3948 * \returns If successful, a new \c CXCodeCompleteResults structure
3949 * containing code-completion results, which should eventually be
3950 * freed with \c clang_disposeCodeCompleteResults(). If code
3951 * completion fails, returns NULL.
3954 CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3955 const char *complete_filename,
3956 unsigned complete_line,
3957 unsigned complete_column,
3958 struct CXUnsavedFile *unsaved_files,
3959 unsigned num_unsaved_files,
3963 * \brief Sort the code-completion results in case-insensitive alphabetical
3966 * \param Results The set of results to sort.
3967 * \param NumResults The number of results in \p Results.
3970 void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3971 unsigned NumResults);
3974 * \brief Free the given set of code-completion results.
3977 void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
3980 * \brief Determine the number of diagnostics produced prior to the
3981 * location where code completion was performed.
3984 unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3987 * \brief Retrieve a diagnostic associated with the given code completion.
3989 * \param Result the code completion results to query.
3990 * \param Index the zero-based diagnostic number to retrieve.
3992 * \returns the requested diagnostic. This diagnostic must be freed
3993 * via a call to \c clang_disposeDiagnostic().
3996 CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
4000 * \brief Determines what compeltions are appropriate for the context
4001 * the given code completion.
4003 * \param Results the code completion results to query
4005 * \returns the kinds of completions that are appropriate for use
4006 * along with the given code completion results.
4009 unsigned long long clang_codeCompleteGetContexts(
4010 CXCodeCompleteResults *Results);
4013 * \brief Returns the cursor kind for the container for the current code
4014 * completion context. The container is only guaranteed to be set for
4015 * contexts where a container exists (i.e. member accesses or Objective-C
4016 * message sends); if there is not a container, this function will return
4017 * CXCursor_InvalidCode.
4019 * \param Results the code completion results to query
4021 * \param IsIncomplete on return, this value will be false if Clang has complete
4022 * information about the container. If Clang does not have complete
4023 * information, this value will be true.
4025 * \returns the container kind, or CXCursor_InvalidCode if there is not a
4029 enum CXCursorKind clang_codeCompleteGetContainerKind(
4030 CXCodeCompleteResults *Results,
4031 unsigned *IsIncomplete);
4034 * \brief Returns the USR for the container for the current code completion
4035 * context. If there is not a container for the current context, this
4036 * function will return the empty string.
4038 * \param Results the code completion results to query
4040 * \returns the USR for the container
4043 CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
4047 * \brief Returns the currently-entered selector for an Objective-C message
4048 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
4049 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
4050 * CXCompletionContext_ObjCClassMessage.
4052 * \param Results the code completion results to query
4054 * \returns the selector (or partial selector) that has been entered thus far
4055 * for an Objective-C message send.
4058 CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
4066 * \defgroup CINDEX_MISC Miscellaneous utility functions
4072 * \brief Return a version string, suitable for showing to a user, but not
4073 * intended to be parsed (the format is not guaranteed to be stable).
4075 CINDEX_LINKAGE CXString clang_getClangVersion();
4079 * \brief Enable/disable crash recovery.
4081 * \param Flag to indicate if crash recovery is enabled. A non-zero value
4082 * enables crash recovery, while 0 disables it.
4084 CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
4087 * \brief Visitor invoked for each file in a translation unit
4088 * (used with clang_getInclusions()).
4090 * This visitor function will be invoked by clang_getInclusions() for each
4091 * file included (either at the top-level or by #include directives) within
4092 * a translation unit. The first argument is the file being included, and
4093 * the second and third arguments provide the inclusion stack. The
4094 * array is sorted in order of immediate inclusion. For example,
4095 * the first element refers to the location that included 'included_file'.
4097 typedef void (*CXInclusionVisitor)(CXFile included_file,
4098 CXSourceLocation* inclusion_stack,
4099 unsigned include_len,
4100 CXClientData client_data);
4103 * \brief Visit the set of preprocessor inclusions in a translation unit.
4104 * The visitor function is called with the provided data for every included
4105 * file. This does not include headers included by the PCH file (unless one
4106 * is inspecting the inclusions in the PCH file itself).
4108 CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
4109 CXInclusionVisitor visitor,
4110 CXClientData client_data);
4116 /** \defgroup CINDEX_REMAPPING Remapping functions
4122 * \brief A remapping of original source files and their translated files.
4124 typedef void *CXRemapping;
4127 * \brief Retrieve a remapping.
4129 * \param path the path that contains metadata about remappings.
4131 * \returns the requested remapping. This remapping must be freed
4132 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4134 CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
4137 * \brief Retrieve a remapping.
4139 * \param filePaths pointer to an array of file paths containing remapping info.
4141 * \param numFiles number of file paths.
4143 * \returns the requested remapping. This remapping must be freed
4144 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
4147 CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
4151 * \brief Determine the number of remappings.
4153 CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
4156 * \brief Get the original and the associated filename from the remapping.
4158 * \param original If non-NULL, will be set to the original filename.
4160 * \param transformed If non-NULL, will be set to the filename that the original
4161 * is associated with.
4163 CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
4164 CXString *original, CXString *transformed);
4167 * \brief Dispose the remapping.
4169 CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4175 /** \defgroup CINDEX_HIGH Higher level API functions
4180 enum CXVisitorResult {
4187 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4188 } CXCursorAndRangeVisitor;
4191 * \brief Find references of a declaration in a specific file.
4193 * \param cursor pointing to a declaration or a reference of one.
4195 * \param file to search for references.
4197 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4198 * each reference found.
4199 * The CXSourceRange will point inside the file; if the reference is inside
4200 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4202 CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4203 CXCursorAndRangeVisitor visitor);
4205 #ifdef __has_feature
4206 # if __has_feature(blocks)
4208 typedef enum CXVisitorResult
4209 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4212 void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4213 CXCursorAndRangeVisitorBlock);
4219 * \brief The client's data object that is associated with a CXFile.
4221 typedef void *CXIdxClientFile;
4224 * \brief The client's data object that is associated with a semantic entity.
4226 typedef void *CXIdxClientEntity;
4229 * \brief The client's data object that is associated with a semantic container
4232 typedef void *CXIdxClientContainer;
4235 * \brief The client's data object that is associated with an AST file (PCH
4238 typedef void *CXIdxClientASTFile;
4241 * \brief Source location passed to index callbacks.
4249 * \brief Data for \see ppIncludedFile callback.
4253 * \brief Location of '#' in the #include/#import directive.
4257 * \brief Filename as written in the #include/#import directive.
4259 const char *filename;
4261 * \brief The actual file that the #include/#import directive resolved to.
4266 } CXIdxIncludedFileInfo;
4269 * \brief Data for \see importedASTFile callback.
4274 * \brief Location where the file is imported. It is useful mostly for
4279 * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4282 } CXIdxImportedASTFileInfo;
4285 CXIdxEntity_Unexposed = 0,
4286 CXIdxEntity_Typedef = 1,
4287 CXIdxEntity_Function = 2,
4288 CXIdxEntity_Variable = 3,
4289 CXIdxEntity_Field = 4,
4290 CXIdxEntity_EnumConstant = 5,
4292 CXIdxEntity_ObjCClass = 6,
4293 CXIdxEntity_ObjCProtocol = 7,
4294 CXIdxEntity_ObjCCategory = 8,
4296 CXIdxEntity_ObjCInstanceMethod = 9,
4297 CXIdxEntity_ObjCClassMethod = 10,
4298 CXIdxEntity_ObjCProperty = 11,
4299 CXIdxEntity_ObjCIvar = 12,
4301 CXIdxEntity_Enum = 13,
4302 CXIdxEntity_Struct = 14,
4303 CXIdxEntity_Union = 15,
4305 CXIdxEntity_CXXClass = 16,
4306 CXIdxEntity_CXXNamespace = 17,
4307 CXIdxEntity_CXXNamespaceAlias = 18,
4308 CXIdxEntity_CXXStaticVariable = 19,
4309 CXIdxEntity_CXXStaticMethod = 20,
4310 CXIdxEntity_CXXInstanceMethod = 21,
4311 CXIdxEntity_CXXConstructor = 22,
4312 CXIdxEntity_CXXDestructor = 23,
4313 CXIdxEntity_CXXConversionFunction = 24,
4314 CXIdxEntity_CXXTypeAlias = 25
4319 CXIdxEntityLang_None = 0,
4320 CXIdxEntityLang_C = 1,
4321 CXIdxEntityLang_ObjC = 2,
4322 CXIdxEntityLang_CXX = 3
4323 } CXIdxEntityLanguage;
4326 * \brief Extra C++ template information for an entity. This can apply to:
4327 * CXIdxEntity_Function
4328 * CXIdxEntity_CXXClass
4329 * CXIdxEntity_CXXStaticMethod
4330 * CXIdxEntity_CXXInstanceMethod
4331 * CXIdxEntity_CXXConstructor
4332 * CXIdxEntity_CXXConversionFunction
4333 * CXIdxEntity_CXXTypeAlias
4336 CXIdxEntity_NonTemplate = 0,
4337 CXIdxEntity_Template = 1,
4338 CXIdxEntity_TemplatePartialSpecialization = 2,
4339 CXIdxEntity_TemplateSpecialization = 3
4340 } CXIdxEntityCXXTemplateKind;
4343 CXIdxAttr_Unexposed = 0,
4344 CXIdxAttr_IBAction = 1,
4345 CXIdxAttr_IBOutlet = 2,
4346 CXIdxAttr_IBOutletCollection = 3
4356 CXIdxEntityKind kind;
4357 CXIdxEntityCXXTemplateKind templateKind;
4358 CXIdxEntityLanguage lang;
4362 const CXIdxAttrInfo *const *attributes;
4363 unsigned numAttributes;
4368 } CXIdxContainerInfo;
4371 const CXIdxAttrInfo *attrInfo;
4372 const CXIdxEntityInfo *objcClass;
4373 CXCursor classCursor;
4375 } CXIdxIBOutletCollectionAttrInfo;
4378 const CXIdxEntityInfo *entityInfo;
4381 const CXIdxContainerInfo *semanticContainer;
4383 * \brief Generally same as \see semanticContainer but can be different in
4384 * cases like out-of-line C++ member functions.
4386 const CXIdxContainerInfo *lexicalContainer;
4387 int isRedeclaration;
4390 const CXIdxContainerInfo *declAsContainer;
4392 * \brief Whether the declaration exists in code or was created implicitly
4393 * by the compiler, e.g. implicit objc methods for properties.
4396 const CXIdxAttrInfo *const *attributes;
4397 unsigned numAttributes;
4401 CXIdxObjCContainer_ForwardRef = 0,
4402 CXIdxObjCContainer_Interface = 1,
4403 CXIdxObjCContainer_Implementation = 2
4404 } CXIdxObjCContainerKind;
4407 const CXIdxDeclInfo *declInfo;
4408 CXIdxObjCContainerKind kind;
4409 } CXIdxObjCContainerDeclInfo;
4412 const CXIdxEntityInfo *base;
4415 } CXIdxBaseClassInfo;
4418 const CXIdxEntityInfo *protocol;
4421 } CXIdxObjCProtocolRefInfo;
4424 const CXIdxObjCProtocolRefInfo *const *protocols;
4425 unsigned numProtocols;
4426 } CXIdxObjCProtocolRefListInfo;
4429 const CXIdxObjCContainerDeclInfo *containerInfo;
4430 const CXIdxBaseClassInfo *superInfo;
4431 const CXIdxObjCProtocolRefListInfo *protocols;
4432 } CXIdxObjCInterfaceDeclInfo;
4435 const CXIdxObjCContainerDeclInfo *containerInfo;
4436 const CXIdxEntityInfo *objcClass;
4437 CXCursor classCursor;
4439 const CXIdxObjCProtocolRefListInfo *protocols;
4440 } CXIdxObjCCategoryDeclInfo;
4443 const CXIdxDeclInfo *declInfo;
4444 const CXIdxEntityInfo *getter;
4445 const CXIdxEntityInfo *setter;
4446 } CXIdxObjCPropertyDeclInfo;
4449 const CXIdxDeclInfo *declInfo;
4450 const CXIdxBaseClassInfo *const *bases;
4452 } CXIdxCXXClassDeclInfo;
4455 * \brief Data for \see indexEntityReference callback.
4459 * \brief The entity is referenced directly in user's code.
4461 CXIdxEntityRef_Direct = 1,
4463 * \brief An implicit reference, e.g. a reference of an ObjC method via the
4466 CXIdxEntityRef_Implicit = 2
4467 } CXIdxEntityRefKind;
4470 * \brief Data for \see indexEntityReference callback.
4473 CXIdxEntityRefKind kind;
4475 * \brief Reference cursor.
4480 * \brief The entity that gets referenced.
4482 const CXIdxEntityInfo *referencedEntity;
4484 * \brief Immediate "parent" of the reference. For example:
4490 * The parent of reference of type 'Foo' is the variable 'var'.
4491 * For references inside statement bodies of functions/methods,
4492 * the parentEntity will be the function/method.
4494 const CXIdxEntityInfo *parentEntity;
4496 * \brief Lexical container context of the reference.
4498 const CXIdxContainerInfo *container;
4499 } CXIdxEntityRefInfo;
4503 * \brief Called periodically to check whether indexing should be aborted.
4504 * Should return 0 to continue, and non-zero to abort.
4506 int (*abortQuery)(CXClientData client_data, void *reserved);
4509 * \brief Called at the end of indexing; passes the complete diagnostic set.
4511 void (*diagnostic)(CXClientData client_data,
4512 CXDiagnosticSet, void *reserved);
4514 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4515 CXFile mainFile, void *reserved);
4518 * \brief Called when a file gets #included/#imported.
4520 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
4521 const CXIdxIncludedFileInfo *);
4524 * \brief Called when a AST file (PCH or module) gets imported.
4526 * AST files will not get indexed (there will not be callbacks to index all
4527 * the entities in an AST file). The recommended action is that, if the AST
4528 * file is not already indexed, to block further indexing and initiate a new
4529 * indexing job specific to the AST file.
4531 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
4532 const CXIdxImportedASTFileInfo *);
4535 * \brief Called at the beginning of indexing a translation unit.
4537 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
4540 void (*indexDeclaration)(CXClientData client_data,
4541 const CXIdxDeclInfo *);
4544 * \brief Called to index a reference of an entity.
4546 void (*indexEntityReference)(CXClientData client_data,
4547 const CXIdxEntityRefInfo *);
4551 CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
4552 CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4553 clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
4555 CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4556 clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4559 const CXIdxObjCCategoryDeclInfo *
4560 clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4562 CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4563 clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
4565 CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
4566 clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
4568 CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4569 clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4571 CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4572 clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4575 * \brief For retrieving a custom CXIdxClientContainer attached to a
4578 CINDEX_LINKAGE CXIdxClientContainer
4579 clang_index_getClientContainer(const CXIdxContainerInfo *);
4582 * \brief For setting a custom CXIdxClientContainer attached to a
4586 clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4589 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4591 CINDEX_LINKAGE CXIdxClientEntity
4592 clang_index_getClientEntity(const CXIdxEntityInfo *);
4595 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4598 clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4601 * \brief An indexing action, to be applied to one or multiple translation units
4602 * but not on concurrent threads. If there are threads doing indexing
4603 * concurrently, they should use different CXIndexAction objects.
4605 typedef void *CXIndexAction;
4608 * \brief An indexing action, to be applied to one or multiple translation units
4609 * but not on concurrent threads. If there are threads doing indexing
4610 * concurrently, they should use different CXIndexAction objects.
4612 * \param CIdx The index object with which the index action will be associated.
4614 CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4617 * \brief Destroy the given index action.
4619 * The index action must not be destroyed until all of the translation units
4620 * created within that index action have been destroyed.
4622 CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4626 * \brief Used to indicate that no special indexing options are needed.
4628 CXIndexOpt_None = 0x0,
4631 * \brief Used to indicate that \see indexEntityReference should be invoked
4632 * for only one reference of an entity per source file that does not also
4633 * include a declaration/definition of the entity.
4635 CXIndexOpt_SuppressRedundantRefs = 0x1,
4638 * \brief Function-local symbols should be indexed. If this is not set
4639 * function-local symbols will be ignored.
4641 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
4644 * \brief Implicit function/class template instantiations should be indexed.
4645 * If this is not set, implicit instantiations will be ignored.
4647 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
4650 * \brief Suppress all compiler warnings when parsing for indexing.
4652 CXIndexOpt_SuppressWarnings = 0x8
4656 * \brief Index the given source file and the translation unit corresponding
4657 * to that file via callbacks implemented through \see IndexerCallbacks.
4659 * \param client_data pointer data supplied by the client, which will
4660 * be passed to the invoked callbacks.
4662 * \param index_callbacks Pointer to indexing callbacks that the client
4665 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4666 * passed in index_callbacks.
4668 * \param index_options A bitmask of options that affects how indexing is
4669 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
4671 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4672 * after indexing is finished. Set to NULL if you do not require it.
4674 * \returns If there is a failure from which the there is no recovery, returns
4675 * non-zero, otherwise returns 0.
4677 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4679 CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
4680 CXClientData client_data,
4681 IndexerCallbacks *index_callbacks,
4682 unsigned index_callbacks_size,
4683 unsigned index_options,
4684 const char *source_filename,
4685 const char * const *command_line_args,
4686 int num_command_line_args,
4687 struct CXUnsavedFile *unsaved_files,
4688 unsigned num_unsaved_files,
4689 CXTranslationUnit *out_TU,
4690 unsigned TU_options);
4693 * \brief Index the given translation unit via callbacks implemented through
4694 * \see IndexerCallbacks.
4696 * The order of callback invocations is not guaranteed to be the same as
4697 * when indexing a source file. The high level order will be:
4699 * -Preprocessor callbacks invocations
4700 * -Declaration/reference callbacks invocations
4701 * -Diagnostic callback invocations
4703 * The parameters are the same as \see clang_indexSourceFile.
4705 * \returns If there is a failure from which the there is no recovery, returns
4706 * non-zero, otherwise returns 0.
4708 CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
4709 CXClientData client_data,
4710 IndexerCallbacks *index_callbacks,
4711 unsigned index_callbacks_size,
4712 unsigned index_options,
4716 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4717 * the given CXIdxLoc.
4719 * If the location refers into a macro expansion, retrieves the
4720 * location of the macro expansion and if it refers into a macro argument
4721 * retrieves the location of the argument.
4723 CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
4724 CXIdxClientFile *indexFile,
4731 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4734 CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);