blob: 6468d1aa404f13bf412e822747792d6945e5bfbc [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public interface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef LLVM_CLANG_C_INDEX_H
17#define LLVM_CLANG_C_INDEX_H
18
19#include <time.h>
20
21#include "clang-c/Platform.h"
22#include "clang-c/CXErrorCode.h"
23#include "clang-c/CXString.h"
24#include "clang-c/BuildSystem.h"
25
26/**
27 * \brief The version constants for the libclang API.
28 * CINDEX_VERSION_MINOR should increase when there are API additions.
29 * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
30 *
31 * The policy about the libclang API was always to keep it source and ABI
32 * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
33 */
34#define CINDEX_VERSION_MAJOR 0
35#define CINDEX_VERSION_MINOR 48
36
37#define CINDEX_VERSION_ENCODE(major, minor) ( \
38 ((major) * 10000) \
39 + ((minor) * 1))
40
41#define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
42 CINDEX_VERSION_MAJOR, \
43 CINDEX_VERSION_MINOR )
44
45#define CINDEX_VERSION_STRINGIZE_(major, minor) \
46 #major"."#minor
47#define CINDEX_VERSION_STRINGIZE(major, minor) \
48 CINDEX_VERSION_STRINGIZE_(major, minor)
49
50#define CINDEX_VERSION_STRING CINDEX_VERSION_STRINGIZE( \
51 CINDEX_VERSION_MAJOR, \
52 CINDEX_VERSION_MINOR)
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58/** \defgroup CINDEX libclang: C Interface to Clang
59 *
60 * The C Interface to Clang provides a relatively small API that exposes
61 * facilities for parsing source code into an abstract syntax tree (AST),
62 * loading already-parsed ASTs, traversing the AST, associating
63 * physical source locations with elements within the AST, and other
64 * facilities that support Clang-based development tools.
65 *
66 * This C interface to Clang will never provide all of the information
67 * representation stored in Clang's C++ AST, nor should it: the intent is to
68 * maintain an API that is relatively stable from one release to the next,
69 * providing only the basic functionality needed to support development tools.
70 *
71 * To avoid namespace pollution, data types are prefixed with "CX" and
72 * functions are prefixed with "clang_".
73 *
74 * @{
75 */
76
77/**
78 * \brief An "index" that consists of a set of translation units that would
79 * typically be linked together into an executable or library.
80 */
81typedef void *CXIndex;
82
83/**
84 * \brief An opaque type representing target information for a given translation
85 * unit.
86 */
87typedef struct CXTargetInfoImpl *CXTargetInfo;
88
89/**
90 * \brief A single translation unit, which resides in an index.
91 */
92typedef struct CXTranslationUnitImpl *CXTranslationUnit;
93
94/**
95 * \brief Opaque pointer representing client data that will be passed through
96 * to various callbacks and visitors.
97 */
98typedef void *CXClientData;
99
100/**
101 * \brief Provides the contents of a file that has not yet been saved to disk.
102 *
103 * Each CXUnsavedFile instance provides the name of a file on the
104 * system along with the current contents of that file that have not
105 * yet been saved to disk.
106 */
107struct CXUnsavedFile {
108 /**
109 * \brief The file whose contents have not yet been saved.
110 *
111 * This file must already exist in the file system.
112 */
113 const char *Filename;
114
115 /**
116 * \brief A buffer containing the unsaved contents of this file.
117 */
118 const char *Contents;
119
120 /**
121 * \brief The length of the unsaved contents of this buffer.
122 */
123 unsigned long Length;
124};
125
126/**
127 * \brief Describes the availability of a particular entity, which indicates
128 * whether the use of this entity will result in a warning or error due to
129 * it being deprecated or unavailable.
130 */
131enum CXAvailabilityKind {
132 /**
133 * \brief The entity is available.
134 */
135 CXAvailability_Available,
136 /**
137 * \brief The entity is available, but has been deprecated (and its use is
138 * not recommended).
139 */
140 CXAvailability_Deprecated,
141 /**
142 * \brief The entity is not available; any use of it will be an error.
143 */
144 CXAvailability_NotAvailable,
145 /**
146 * \brief The entity is available, but not accessible; any use of it will be
147 * an error.
148 */
149 CXAvailability_NotAccessible
150};
151
152/**
153 * \brief Describes a version number of the form major.minor.subminor.
154 */
155typedef struct CXVersion {
156 /**
157 * \brief The major version number, e.g., the '10' in '10.7.3'. A negative
158 * value indicates that there is no version number at all.
159 */
160 int Major;
161 /**
162 * \brief The minor version number, e.g., the '7' in '10.7.3'. This value
163 * will be negative if no minor version number was provided, e.g., for
164 * version '10'.
165 */
166 int Minor;
167 /**
168 * \brief The subminor version number, e.g., the '3' in '10.7.3'. This value
169 * will be negative if no minor or subminor version number was provided,
170 * e.g., in version '10' or '10.7'.
171 */
172 int Subminor;
173} CXVersion;
174
175/**
176 * \brief Describes the exception specification of a cursor.
177 *
178 * A negative value indicates that the cursor is not a function declaration.
179 */
180enum CXCursor_ExceptionSpecificationKind {
181
182 /**
183 * \brief The cursor has no exception specification.
184 */
185 CXCursor_ExceptionSpecificationKind_None,
186
187 /**
188 * \brief The cursor has exception specification throw()
189 */
190 CXCursor_ExceptionSpecificationKind_DynamicNone,
191
192 /**
193 * \brief The cursor has exception specification throw(T1, T2)
194 */
195 CXCursor_ExceptionSpecificationKind_Dynamic,
196
197 /**
198 * \brief The cursor has exception specification throw(...).
199 */
200 CXCursor_ExceptionSpecificationKind_MSAny,
201
202 /**
203 * \brief The cursor has exception specification basic noexcept.
204 */
205 CXCursor_ExceptionSpecificationKind_BasicNoexcept,
206
207 /**
208 * \brief The cursor has exception specification computed noexcept.
209 */
210 CXCursor_ExceptionSpecificationKind_ComputedNoexcept,
211
212 /**
213 * \brief The exception specification has not yet been evaluated.
214 */
215 CXCursor_ExceptionSpecificationKind_Unevaluated,
216
217 /**
218 * \brief The exception specification has not yet been instantiated.
219 */
220 CXCursor_ExceptionSpecificationKind_Uninstantiated,
221
222 /**
223 * \brief The exception specification has not been parsed yet.
224 */
225 CXCursor_ExceptionSpecificationKind_Unparsed
226};
227
228/**
229 * \brief Provides a shared context for creating translation units.
230 *
231 * It provides two options:
232 *
233 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
234 * declarations (when loading any new translation units). A "local" declaration
235 * is one that belongs in the translation unit itself and not in a precompiled
236 * header that was used by the translation unit. If zero, all declarations
237 * will be enumerated.
238 *
239 * Here is an example:
240 *
241 * \code
242 * // excludeDeclsFromPCH = 1, displayDiagnostics=1
243 * Idx = clang_createIndex(1, 1);
244 *
245 * // IndexTest.pch was produced with the following command:
246 * // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
247 * TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
248 *
249 * // This will load all the symbols from 'IndexTest.pch'
250 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
251 * TranslationUnitVisitor, 0);
252 * clang_disposeTranslationUnit(TU);
253 *
254 * // This will load all the symbols from 'IndexTest.c', excluding symbols
255 * // from 'IndexTest.pch'.
256 * char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
257 * TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
258 * 0, 0);
259 * clang_visitChildren(clang_getTranslationUnitCursor(TU),
260 * TranslationUnitVisitor, 0);
261 * clang_disposeTranslationUnit(TU);
262 * \endcode
263 *
264 * This process of creating the 'pch', loading it separately, and using it (via
265 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
266 * (which gives the indexer the same performance benefit as the compiler).
267 */
268CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
269 int displayDiagnostics);
270
271/**
272 * \brief Destroy the given index.
273 *
274 * The index must not be destroyed until all of the translation units created
275 * within that index have been destroyed.
276 */
277CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
278
279typedef enum {
280 /**
281 * \brief Used to indicate that no special CXIndex options are needed.
282 */
283 CXGlobalOpt_None = 0x0,
284
285 /**
286 * \brief Used to indicate that threads that libclang creates for indexing
287 * purposes should use background priority.
288 *
289 * Affects #clang_indexSourceFile, #clang_indexTranslationUnit,
290 * #clang_parseTranslationUnit, #clang_saveTranslationUnit.
291 */
292 CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 0x1,
293
294 /**
295 * \brief Used to indicate that threads that libclang creates for editing
296 * purposes should use background priority.
297 *
298 * Affects #clang_reparseTranslationUnit, #clang_codeCompleteAt,
299 * #clang_annotateTokens
300 */
301 CXGlobalOpt_ThreadBackgroundPriorityForEditing = 0x2,
302
303 /**
304 * \brief Used to indicate that all threads that libclang creates should use
305 * background priority.
306 */
307 CXGlobalOpt_ThreadBackgroundPriorityForAll =
308 CXGlobalOpt_ThreadBackgroundPriorityForIndexing |
309 CXGlobalOpt_ThreadBackgroundPriorityForEditing
310
311} CXGlobalOptFlags;
312
313/**
314 * \brief Sets general options associated with a CXIndex.
315 *
316 * For example:
317 * \code
318 * CXIndex idx = ...;
319 * clang_CXIndex_setGlobalOptions(idx,
320 * clang_CXIndex_getGlobalOptions(idx) |
321 * CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
322 * \endcode
323 *
324 * \param options A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags.
325 */
326CINDEX_LINKAGE void clang_CXIndex_setGlobalOptions(CXIndex, unsigned options);
327
328/**
329 * \brief Gets the general options associated with a CXIndex.
330 *
331 * \returns A bitmask of options, a bitwise OR of CXGlobalOpt_XXX flags that
332 * are associated with the given CXIndex object.
333 */
334CINDEX_LINKAGE unsigned clang_CXIndex_getGlobalOptions(CXIndex);
335
336/**
337 * \brief Sets the invocation emission path option in a CXIndex.
338 *
339 * The invocation emission path specifies a path which will contain log
340 * files for certain libclang invocations. A null value (default) implies that
341 * libclang invocations are not logged..
342 */
343CINDEX_LINKAGE void
344clang_CXIndex_setInvocationEmissionPathOption(CXIndex, const char *Path);
345
346/**
347 * \defgroup CINDEX_FILES File manipulation routines
348 *
349 * @{
350 */
351
352/**
353 * \brief A particular source file that is part of a translation unit.
354 */
355typedef void *CXFile;
356
357/**
358 * \brief Retrieve the complete file and path name of the given file.
359 */
360CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
361
362/**
363 * \brief Retrieve the last modification time of the given file.
364 */
365CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
366
367/**
368 * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
369 * across an indexing session.
370 */
371typedef struct {
372 unsigned long long data[3];
373} CXFileUniqueID;
374
375/**
376 * \brief Retrieve the unique ID for the given \c file.
377 *
378 * \param file the file to get the ID for.
379 * \param outID stores the returned CXFileUniqueID.
380 * \returns If there was a failure getting the unique ID, returns non-zero,
381 * otherwise returns 0.
382*/
383CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
384
385/**
386 * \brief Determine whether the given header is guarded against
387 * multiple inclusions, either with the conventional
388 * \#ifndef/\#define/\#endif macro guards or with \#pragma once.
389 */
390CINDEX_LINKAGE unsigned
391clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
392
393/**
394 * \brief Retrieve a file handle within the given translation unit.
395 *
396 * \param tu the translation unit
397 *
398 * \param file_name the name of the file.
399 *
400 * \returns the file handle for the named file in the translation unit \p tu,
401 * or a NULL file handle if the file was not a part of this translation unit.
402 */
403CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
404 const char *file_name);
405
406/**
407 * \brief Retrieve the buffer associated with the given file.
408 *
409 * \param tu the translation unit
410 *
411 * \param file the file for which to retrieve the buffer.
412 *
413 * \param size [out] if non-NULL, will be set to the size of the buffer.
414 *
415 * \returns a pointer to the buffer in memory that holds the contents of
416 * \p file, or a NULL pointer when the file is not loaded.
417 */
418CINDEX_LINKAGE const char *clang_getFileContents(CXTranslationUnit tu,
419 CXFile file, size_t *size);
420
421/**
422 * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
423 * or they are both NULL.
424 */
425CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
426
427/**
428 * @}
429 */
430
431/**
432 * \defgroup CINDEX_LOCATIONS Physical source locations
433 *
434 * Clang represents physical source locations in its abstract syntax tree in
435 * great detail, with file, line, and column information for the majority of
436 * the tokens parsed in the source code. These data types and functions are
437 * used to represent source location information, either for a particular
438 * point in the program or for a range of points in the program, and extract
439 * specific location information from those data types.
440 *
441 * @{
442 */
443
444/**
445 * \brief Identifies a specific source location within a translation
446 * unit.
447 *
448 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
449 * to map a source location to a particular file, line, and column.
450 */
451typedef struct {
452 const void *ptr_data[2];
453 unsigned int_data;
454} CXSourceLocation;
455
456/**
457 * \brief Identifies a half-open character range in the source code.
458 *
459 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
460 * starting and end locations from a source range, respectively.
461 */
462typedef struct {
463 const void *ptr_data[2];
464 unsigned begin_int_data;
465 unsigned end_int_data;
466} CXSourceRange;
467
468/**
469 * \brief Retrieve a NULL (invalid) source location.
470 */
471CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
472
473/**
474 * \brief Determine whether two source locations, which must refer into
475 * the same translation unit, refer to exactly the same point in the source
476 * code.
477 *
478 * \returns non-zero if the source locations refer to the same location, zero
479 * if they refer to different locations.
480 */
481CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
482 CXSourceLocation loc2);
483
484/**
485 * \brief Retrieves the source location associated with a given file/line/column
486 * in a particular translation unit.
487 */
488CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
489 CXFile file,
490 unsigned line,
491 unsigned column);
492/**
493 * \brief Retrieves the source location associated with a given character offset
494 * in a particular translation unit.
495 */
496CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
497 CXFile file,
498 unsigned offset);
499
500/**
501 * \brief Returns non-zero if the given source location is in a system header.
502 */
503CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
504
505/**
506 * \brief Returns non-zero if the given source location is in the main file of
507 * the corresponding translation unit.
508 */
509CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
510
511/**
512 * \brief Retrieve a NULL (invalid) source range.
513 */
514CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
515
516/**
517 * \brief Retrieve a source range given the beginning and ending source
518 * locations.
519 */
520CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
521 CXSourceLocation end);
522
523/**
524 * \brief Determine whether two ranges are equivalent.
525 *
526 * \returns non-zero if the ranges are the same, zero if they differ.
527 */
528CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
529 CXSourceRange range2);
530
531/**
532 * \brief Returns non-zero if \p range is null.
533 */
534CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
535
536/**
537 * \brief Retrieve the file, line, column, and offset represented by
538 * the given source location.
539 *
540 * If the location refers into a macro expansion, retrieves the
541 * location of the macro expansion.
542 *
543 * \param location the location within a source file that will be decomposed
544 * into its parts.
545 *
546 * \param file [out] if non-NULL, will be set to the file to which the given
547 * source location points.
548 *
549 * \param line [out] if non-NULL, will be set to the line to which the given
550 * source location points.
551 *
552 * \param column [out] if non-NULL, will be set to the column to which the given
553 * source location points.
554 *
555 * \param offset [out] if non-NULL, will be set to the offset into the
556 * buffer to which the given source location points.
557 */
558CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
559 CXFile *file,
560 unsigned *line,
561 unsigned *column,
562 unsigned *offset);
563
564/**
565 * \brief Retrieve the file, line and column represented by the given source
566 * location, as specified in a # line directive.
567 *
568 * Example: given the following source code in a file somefile.c
569 *
570 * \code
571 * #123 "dummy.c" 1
572 *
573 * static int func(void)
574 * {
575 * return 0;
576 * }
577 * \endcode
578 *
579 * the location information returned by this function would be
580 *
581 * File: dummy.c Line: 124 Column: 12
582 *
583 * whereas clang_getExpansionLocation would have returned
584 *
585 * File: somefile.c Line: 3 Column: 12
586 *
587 * \param location the location within a source file that will be decomposed
588 * into its parts.
589 *
590 * \param filename [out] if non-NULL, will be set to the filename of the
591 * source location. Note that filenames returned will be for "virtual" files,
592 * which don't necessarily exist on the machine running clang - e.g. when
593 * parsing preprocessed output obtained from a different environment. If
594 * a non-NULL value is passed in, remember to dispose of the returned value
595 * using \c clang_disposeString() once you've finished with it. For an invalid
596 * source location, an empty string is returned.
597 *
598 * \param line [out] if non-NULL, will be set to the line number of the
599 * source location. For an invalid source location, zero is returned.
600 *
601 * \param column [out] if non-NULL, will be set to the column number of the
602 * source location. For an invalid source location, zero is returned.
603 */
604CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
605 CXString *filename,
606 unsigned *line,
607 unsigned *column);
608
609/**
610 * \brief Legacy API to retrieve the file, line, column, and offset represented
611 * by the given source location.
612 *
613 * This interface has been replaced by the newer interface
614 * #clang_getExpansionLocation(). See that interface's documentation for
615 * details.
616 */
617CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
618 CXFile *file,
619 unsigned *line,
620 unsigned *column,
621 unsigned *offset);
622
623/**
624 * \brief Retrieve the file, line, column, and offset represented by
625 * the given source location.
626 *
627 * If the location refers into a macro instantiation, return where the
628 * location was originally spelled in the source file.
629 *
630 * \param location the location within a source file that will be decomposed
631 * into its parts.
632 *
633 * \param file [out] if non-NULL, will be set to the file to which the given
634 * source location points.
635 *
636 * \param line [out] if non-NULL, will be set to the line to which the given
637 * source location points.
638 *
639 * \param column [out] if non-NULL, will be set to the column to which the given
640 * source location points.
641 *
642 * \param offset [out] if non-NULL, will be set to the offset into the
643 * buffer to which the given source location points.
644 */
645CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
646 CXFile *file,
647 unsigned *line,
648 unsigned *column,
649 unsigned *offset);
650
651/**
652 * \brief Retrieve the file, line, column, and offset represented by
653 * the given source location.
654 *
655 * If the location refers into a macro expansion, return where the macro was
656 * expanded or where the macro argument was written, if the location points at
657 * a macro argument.
658 *
659 * \param location the location within a source file that will be decomposed
660 * into its parts.
661 *
662 * \param file [out] if non-NULL, will be set to the file to which the given
663 * source location points.
664 *
665 * \param line [out] if non-NULL, will be set to the line to which the given
666 * source location points.
667 *
668 * \param column [out] if non-NULL, will be set to the column to which the given
669 * source location points.
670 *
671 * \param offset [out] if non-NULL, will be set to the offset into the
672 * buffer to which the given source location points.
673 */
674CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
675 CXFile *file,
676 unsigned *line,
677 unsigned *column,
678 unsigned *offset);
679
680/**
681 * \brief Retrieve a source location representing the first character within a
682 * source range.
683 */
684CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
685
686/**
687 * \brief Retrieve a source location representing the last character within a
688 * source range.
689 */
690CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
691
692/**
693 * \brief Identifies an array of ranges.
694 */
695typedef struct {
696 /** \brief The number of ranges in the \c ranges array. */
697 unsigned count;
698 /**
699 * \brief An array of \c CXSourceRanges.
700 */
701 CXSourceRange *ranges;
702} CXSourceRangeList;
703
704/**
705 * \brief Retrieve all ranges that were skipped by the preprocessor.
706 *
707 * The preprocessor will skip lines when they are surrounded by an
708 * if/ifdef/ifndef directive whose condition does not evaluate to true.
709 */
710CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
711 CXFile file);
712
713/**
714 * \brief Retrieve all ranges from all files that were skipped by the
715 * preprocessor.
716 *
717 * The preprocessor will skip lines when they are surrounded by an
718 * if/ifdef/ifndef directive whose condition does not evaluate to true.
719 */
720CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu);
721
722/**
723 * \brief Destroy the given \c CXSourceRangeList.
724 */
725CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
726
727/**
728 * @}
729 */
730
731/**
732 * \defgroup CINDEX_DIAG Diagnostic reporting
733 *
734 * @{
735 */
736
737/**
738 * \brief Describes the severity of a particular diagnostic.
739 */
740enum CXDiagnosticSeverity {
741 /**
742 * \brief A diagnostic that has been suppressed, e.g., by a command-line
743 * option.
744 */
745 CXDiagnostic_Ignored = 0,
746
747 /**
748 * \brief This diagnostic is a note that should be attached to the
749 * previous (non-note) diagnostic.
750 */
751 CXDiagnostic_Note = 1,
752
753 /**
754 * \brief This diagnostic indicates suspicious code that may not be
755 * wrong.
756 */
757 CXDiagnostic_Warning = 2,
758
759 /**
760 * \brief This diagnostic indicates that the code is ill-formed.
761 */
762 CXDiagnostic_Error = 3,
763
764 /**
765 * \brief This diagnostic indicates that the code is ill-formed such
766 * that future parser recovery is unlikely to produce useful
767 * results.
768 */
769 CXDiagnostic_Fatal = 4
770};
771
772/**
773 * \brief A single diagnostic, containing the diagnostic's severity,
774 * location, text, source ranges, and fix-it hints.
775 */
776typedef void *CXDiagnostic;
777
778/**
779 * \brief A group of CXDiagnostics.
780 */
781typedef void *CXDiagnosticSet;
782
783/**
784 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
785 */
786CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
787
788/**
789 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
790 *
791 * \param Diags the CXDiagnosticSet to query.
792 * \param Index the zero-based diagnostic number to retrieve.
793 *
794 * \returns the requested diagnostic. This diagnostic must be freed
795 * via a call to \c clang_disposeDiagnostic().
796 */
797CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
798 unsigned Index);
799
800/**
801 * \brief Describes the kind of error that occurred (if any) in a call to
802 * \c clang_loadDiagnostics.
803 */
804enum CXLoadDiag_Error {
805 /**
806 * \brief Indicates that no error occurred.
807 */
808 CXLoadDiag_None = 0,
809
810 /**
811 * \brief Indicates that an unknown error occurred while attempting to
812 * deserialize diagnostics.
813 */
814 CXLoadDiag_Unknown = 1,
815
816 /**
817 * \brief Indicates that the file containing the serialized diagnostics
818 * could not be opened.
819 */
820 CXLoadDiag_CannotLoad = 2,
821
822 /**
823 * \brief Indicates that the serialized diagnostics file is invalid or
824 * corrupt.
825 */
826 CXLoadDiag_InvalidFile = 3
827};
828
829/**
830 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
831 * file.
832 *
833 * \param file The name of the file to deserialize.
834 * \param error A pointer to a enum value recording if there was a problem
835 * deserializing the diagnostics.
836 * \param errorString A pointer to a CXString for recording the error string
837 * if the file was not successfully loaded.
838 *
839 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise. These
840 * diagnostics should be released using clang_disposeDiagnosticSet().
841 */
842CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
843 enum CXLoadDiag_Error *error,
844 CXString *errorString);
845
846/**
847 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
848 */
849CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
850
851/**
852 * \brief Retrieve the child diagnostics of a CXDiagnostic.
853 *
854 * This CXDiagnosticSet does not need to be released by
855 * clang_disposeDiagnosticSet.
856 */
857CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
858
859/**
860 * \brief Determine the number of diagnostics produced for the given
861 * translation unit.
862 */
863CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
864
865/**
866 * \brief Retrieve a diagnostic associated with the given translation unit.
867 *
868 * \param Unit the translation unit to query.
869 * \param Index the zero-based diagnostic number to retrieve.
870 *
871 * \returns the requested diagnostic. This diagnostic must be freed
872 * via a call to \c clang_disposeDiagnostic().
873 */
874CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
875 unsigned Index);
876
877/**
878 * \brief Retrieve the complete set of diagnostics associated with a
879 * translation unit.
880 *
881 * \param Unit the translation unit to query.
882 */
883CINDEX_LINKAGE CXDiagnosticSet
884 clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
885
886/**
887 * \brief Destroy a diagnostic.
888 */
889CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
890
891/**
892 * \brief Options to control the display of diagnostics.
893 *
894 * The values in this enum are meant to be combined to customize the
895 * behavior of \c clang_formatDiagnostic().
896 */
897enum CXDiagnosticDisplayOptions {
898 /**
899 * \brief Display the source-location information where the
900 * diagnostic was located.
901 *
902 * When set, diagnostics will be prefixed by the file, line, and
903 * (optionally) column to which the diagnostic refers. For example,
904 *
905 * \code
906 * test.c:28: warning: extra tokens at end of #endif directive
907 * \endcode
908 *
909 * This option corresponds to the clang flag \c -fshow-source-location.
910 */
911 CXDiagnostic_DisplaySourceLocation = 0x01,
912
913 /**
914 * \brief If displaying the source-location information of the
915 * diagnostic, also include the column number.
916 *
917 * This option corresponds to the clang flag \c -fshow-column.
918 */
919 CXDiagnostic_DisplayColumn = 0x02,
920
921 /**
922 * \brief If displaying the source-location information of the
923 * diagnostic, also include information about source ranges in a
924 * machine-parsable format.
925 *
926 * This option corresponds to the clang flag
927 * \c -fdiagnostics-print-source-range-info.
928 */
929 CXDiagnostic_DisplaySourceRanges = 0x04,
930
931 /**
932 * \brief Display the option name associated with this diagnostic, if any.
933 *
934 * The option name displayed (e.g., -Wconversion) will be placed in brackets
935 * after the diagnostic text. This option corresponds to the clang flag
936 * \c -fdiagnostics-show-option.
937 */
938 CXDiagnostic_DisplayOption = 0x08,
939
940 /**
941 * \brief Display the category number associated with this diagnostic, if any.
942 *
943 * The category number is displayed within brackets after the diagnostic text.
944 * This option corresponds to the clang flag
945 * \c -fdiagnostics-show-category=id.
946 */
947 CXDiagnostic_DisplayCategoryId = 0x10,
948
949 /**
950 * \brief Display the category name associated with this diagnostic, if any.
951 *
952 * The category name is displayed within brackets after the diagnostic text.
953 * This option corresponds to the clang flag
954 * \c -fdiagnostics-show-category=name.
955 */
956 CXDiagnostic_DisplayCategoryName = 0x20
957};
958
959/**
960 * \brief Format the given diagnostic in a manner that is suitable for display.
961 *
962 * This routine will format the given diagnostic to a string, rendering
963 * the diagnostic according to the various options given. The
964 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
965 * options that most closely mimics the behavior of the clang compiler.
966 *
967 * \param Diagnostic The diagnostic to print.
968 *
969 * \param Options A set of options that control the diagnostic display,
970 * created by combining \c CXDiagnosticDisplayOptions values.
971 *
972 * \returns A new string containing for formatted diagnostic.
973 */
974CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
975 unsigned Options);
976
977/**
978 * \brief Retrieve the set of display options most similar to the
979 * default behavior of the clang compiler.
980 *
981 * \returns A set of display options suitable for use with \c
982 * clang_formatDiagnostic().
983 */
984CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
985
986/**
987 * \brief Determine the severity of the given diagnostic.
988 */
989CINDEX_LINKAGE enum CXDiagnosticSeverity
990clang_getDiagnosticSeverity(CXDiagnostic);
991
992/**
993 * \brief Retrieve the source location of the given diagnostic.
994 *
995 * This location is where Clang would print the caret ('^') when
996 * displaying the diagnostic on the command line.
997 */
998CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
999
1000/**
1001 * \brief Retrieve the text of the given diagnostic.
1002 */
1003CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
1004
1005/**
1006 * \brief Retrieve the name of the command-line option that enabled this
1007 * diagnostic.
1008 *
1009 * \param Diag The diagnostic to be queried.
1010 *
1011 * \param Disable If non-NULL, will be set to the option that disables this
1012 * diagnostic (if any).
1013 *
1014 * \returns A string that contains the command-line option used to enable this
1015 * warning, such as "-Wconversion" or "-pedantic".
1016 */
1017CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
1018 CXString *Disable);
1019
1020/**
1021 * \brief Retrieve the category number for this diagnostic.
1022 *
1023 * Diagnostics can be categorized into groups along with other, related
1024 * diagnostics (e.g., diagnostics under the same warning flag). This routine
1025 * retrieves the category number for the given diagnostic.
1026 *
1027 * \returns The number of the category that contains this diagnostic, or zero
1028 * if this diagnostic is uncategorized.
1029 */
1030CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
1031
1032/**
1033 * \brief Retrieve the name of a particular diagnostic category. This
1034 * is now deprecated. Use clang_getDiagnosticCategoryText()
1035 * instead.
1036 *
1037 * \param Category A diagnostic category number, as returned by
1038 * \c clang_getDiagnosticCategory().
1039 *
1040 * \returns The name of the given diagnostic category.
1041 */
1042CINDEX_DEPRECATED CINDEX_LINKAGE
1043CXString clang_getDiagnosticCategoryName(unsigned Category);
1044
1045/**
1046 * \brief Retrieve the diagnostic category text for a given diagnostic.
1047 *
1048 * \returns The text of the given diagnostic category.
1049 */
1050CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
1051
1052/**
1053 * \brief Determine the number of source ranges associated with the given
1054 * diagnostic.
1055 */
1056CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
1057
1058/**
1059 * \brief Retrieve a source range associated with the diagnostic.
1060 *
1061 * A diagnostic's source ranges highlight important elements in the source
1062 * code. On the command line, Clang displays source ranges by
1063 * underlining them with '~' characters.
1064 *
1065 * \param Diagnostic the diagnostic whose range is being extracted.
1066 *
1067 * \param Range the zero-based index specifying which range to
1068 *
1069 * \returns the requested source range.
1070 */
1071CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
1072 unsigned Range);
1073
1074/**
1075 * \brief Determine the number of fix-it hints associated with the
1076 * given diagnostic.
1077 */
1078CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
1079
1080/**
1081 * \brief Retrieve the replacement information for a given fix-it.
1082 *
1083 * Fix-its are described in terms of a source range whose contents
1084 * should be replaced by a string. This approach generalizes over
1085 * three kinds of operations: removal of source code (the range covers
1086 * the code to be removed and the replacement string is empty),
1087 * replacement of source code (the range covers the code to be
1088 * replaced and the replacement string provides the new code), and
1089 * insertion (both the start and end of the range point at the
1090 * insertion location, and the replacement string provides the text to
1091 * insert).
1092 *
1093 * \param Diagnostic The diagnostic whose fix-its are being queried.
1094 *
1095 * \param FixIt The zero-based index of the fix-it.
1096 *
1097 * \param ReplacementRange The source range whose contents will be
1098 * replaced with the returned replacement string. Note that source
1099 * ranges are half-open ranges [a, b), so the source code should be
1100 * replaced from a and up to (but not including) b.
1101 *
1102 * \returns A string containing text that should be replace the source
1103 * code indicated by the \c ReplacementRange.
1104 */
1105CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
1106 unsigned FixIt,
1107 CXSourceRange *ReplacementRange);
1108
1109/**
1110 * @}
1111 */
1112
1113/**
1114 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
1115 *
1116 * The routines in this group provide the ability to create and destroy
1117 * translation units from files, either by parsing the contents of the files or
1118 * by reading in a serialized representation of a translation unit.
1119 *
1120 * @{
1121 */
1122
1123/**
1124 * \brief Get the original translation unit source file name.
1125 */
1126CINDEX_LINKAGE CXString
1127clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
1128
1129/**
1130 * \brief Return the CXTranslationUnit for a given source file and the provided
1131 * command line arguments one would pass to the compiler.
1132 *
1133 * Note: The 'source_filename' argument is optional. If the caller provides a
1134 * NULL pointer, the name of the source file is expected to reside in the
1135 * specified command line arguments.
1136 *
1137 * Note: When encountered in 'clang_command_line_args', the following options
1138 * are ignored:
1139 *
1140 * '-c'
1141 * '-emit-ast'
1142 * '-fsyntax-only'
1143 * '-o \<output file>' (both '-o' and '\<output file>' are ignored)
1144 *
1145 * \param CIdx The index object with which the translation unit will be
1146 * associated.
1147 *
1148 * \param source_filename The name of the source file to load, or NULL if the
1149 * source file is included in \p clang_command_line_args.
1150 *
1151 * \param num_clang_command_line_args The number of command-line arguments in
1152 * \p clang_command_line_args.
1153 *
1154 * \param clang_command_line_args The command-line arguments that would be
1155 * passed to the \c clang executable if it were being invoked out-of-process.
1156 * These command-line options will be parsed and will affect how the translation
1157 * unit is parsed. Note that the following options are ignored: '-c',
1158 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
1159 *
1160 * \param num_unsaved_files the number of unsaved file entries in \p
1161 * unsaved_files.
1162 *
1163 * \param unsaved_files the files that have not yet been saved to disk
1164 * but may be required for code completion, including the contents of
1165 * those files. The contents and name of these files (as specified by
1166 * CXUnsavedFile) are copied when necessary, so the client only needs to
1167 * guarantee their validity until the call to this function returns.
1168 */
1169CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1170 CXIndex CIdx,
1171 const char *source_filename,
1172 int num_clang_command_line_args,
1173 const char * const *clang_command_line_args,
1174 unsigned num_unsaved_files,
1175 struct CXUnsavedFile *unsaved_files);
1176
1177/**
1178 * \brief Same as \c clang_createTranslationUnit2, but returns
1179 * the \c CXTranslationUnit instead of an error code. In case of an error this
1180 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1181 * error codes.
1182 */
1183CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
1184 CXIndex CIdx,
1185 const char *ast_filename);
1186
1187/**
1188 * \brief Create a translation unit from an AST file (\c -emit-ast).
1189 *
1190 * \param[out] out_TU A non-NULL pointer to store the created
1191 * \c CXTranslationUnit.
1192 *
1193 * \returns Zero on success, otherwise returns an error code.
1194 */
1195CINDEX_LINKAGE enum CXErrorCode clang_createTranslationUnit2(
1196 CXIndex CIdx,
1197 const char *ast_filename,
1198 CXTranslationUnit *out_TU);
1199
1200/**
1201 * \brief Flags that control the creation of translation units.
1202 *
1203 * The enumerators in this enumeration type are meant to be bitwise
1204 * ORed together to specify which options should be used when
1205 * constructing the translation unit.
1206 */
1207enum CXTranslationUnit_Flags {
1208 /**
1209 * \brief Used to indicate that no special translation-unit options are
1210 * needed.
1211 */
1212 CXTranslationUnit_None = 0x0,
1213
1214 /**
1215 * \brief Used to indicate that the parser should construct a "detailed"
1216 * preprocessing record, including all macro definitions and instantiations.
1217 *
1218 * Constructing a detailed preprocessing record requires more memory
1219 * and time to parse, since the information contained in the record
1220 * is usually not retained. However, it can be useful for
1221 * applications that require more detailed information about the
1222 * behavior of the preprocessor.
1223 */
1224 CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
1225
1226 /**
1227 * \brief Used to indicate that the translation unit is incomplete.
1228 *
1229 * When a translation unit is considered "incomplete", semantic
1230 * analysis that is typically performed at the end of the
1231 * translation unit will be suppressed. For example, this suppresses
1232 * the completion of tentative declarations in C and of
1233 * instantiation of implicitly-instantiation function templates in
1234 * C++. This option is typically used when parsing a header with the
1235 * intent of producing a precompiled header.
1236 */
1237 CXTranslationUnit_Incomplete = 0x02,
1238
1239 /**
1240 * \brief Used to indicate that the translation unit should be built with an
1241 * implicit precompiled header for the preamble.
1242 *
1243 * An implicit precompiled header is used as an optimization when a
1244 * particular translation unit is likely to be reparsed many times
1245 * when the sources aren't changing that often. In this case, an
1246 * implicit precompiled header will be built containing all of the
1247 * initial includes at the top of the main file (what we refer to as
1248 * the "preamble" of the file). In subsequent parses, if the
1249 * preamble or the files in it have not changed, \c
1250 * clang_reparseTranslationUnit() will re-use the implicit
1251 * precompiled header to improve parsing performance.
1252 */
1253 CXTranslationUnit_PrecompiledPreamble = 0x04,
1254
1255 /**
1256 * \brief Used to indicate that the translation unit should cache some
1257 * code-completion results with each reparse of the source file.
1258 *
1259 * Caching of code-completion results is a performance optimization that
1260 * introduces some overhead to reparsing but improves the performance of
1261 * code-completion operations.
1262 */
1263 CXTranslationUnit_CacheCompletionResults = 0x08,
1264
1265 /**
1266 * \brief Used to indicate that the translation unit will be serialized with
1267 * \c clang_saveTranslationUnit.
1268 *
1269 * This option is typically used when parsing a header with the intent of
1270 * producing a precompiled header.
1271 */
1272 CXTranslationUnit_ForSerialization = 0x10,
1273
1274 /**
1275 * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
1276 *
1277 * Note: this is a *temporary* option that is available only while
1278 * we are testing C++ precompiled preamble support. It is deprecated.
1279 */
1280 CXTranslationUnit_CXXChainedPCH = 0x20,
1281
1282 /**
1283 * \brief Used to indicate that function/method bodies should be skipped while
1284 * parsing.
1285 *
1286 * This option can be used to search for declarations/definitions while
1287 * ignoring the usages.
1288 */
1289 CXTranslationUnit_SkipFunctionBodies = 0x40,
1290
1291 /**
1292 * \brief Used to indicate that brief documentation comments should be
1293 * included into the set of code completions returned from this translation
1294 * unit.
1295 */
1296 CXTranslationUnit_IncludeBriefCommentsInCodeCompletion = 0x80,
1297
1298 /**
1299 * \brief Used to indicate that the precompiled preamble should be created on
1300 * the first parse. Otherwise it will be created on the first reparse. This
1301 * trades runtime on the first parse (serializing the preamble takes time) for
1302 * reduced runtime on the second parse (can now reuse the preamble).
1303 */
1304 CXTranslationUnit_CreatePreambleOnFirstParse = 0x100,
1305
1306 /**
1307 * \brief Do not stop processing when fatal errors are encountered.
1308 *
1309 * When fatal errors are encountered while parsing a translation unit,
1310 * semantic analysis is typically stopped early when compiling code. A common
1311 * source for fatal errors are unresolvable include files. For the
1312 * purposes of an IDE, this is undesirable behavior and as much information
1313 * as possible should be reported. Use this flag to enable this behavior.
1314 */
1315 CXTranslationUnit_KeepGoing = 0x200,
1316
1317 /**
1318 * \brief Sets the preprocessor in a mode for parsing a single file only.
1319 */
1320 CXTranslationUnit_SingleFileParse = 0x400
1321};
1322
1323/**
1324 * \brief Returns the set of flags that is suitable for parsing a translation
1325 * unit that is being edited.
1326 *
1327 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1328 * to indicate that the translation unit is likely to be reparsed many times,
1329 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1330 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1331 * set contains an unspecified set of optimizations (e.g., the precompiled
1332 * preamble) geared toward improving the performance of these routines. The
1333 * set of optimizations enabled may change from one version to the next.
1334 */
1335CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
1336
1337/**
1338 * \brief Same as \c clang_parseTranslationUnit2, but returns
1339 * the \c CXTranslationUnit instead of an error code. In case of an error this
1340 * routine returns a \c NULL \c CXTranslationUnit, without further detailed
1341 * error codes.
1342 */
1343CINDEX_LINKAGE CXTranslationUnit
1344clang_parseTranslationUnit(CXIndex CIdx,
1345 const char *source_filename,
1346 const char *const *command_line_args,
1347 int num_command_line_args,
1348 struct CXUnsavedFile *unsaved_files,
1349 unsigned num_unsaved_files,
1350 unsigned options);
1351
1352/**
1353 * \brief Parse the given source file and the translation unit corresponding
1354 * to that file.
1355 *
1356 * This routine is the main entry point for the Clang C API, providing the
1357 * ability to parse a source file into a translation unit that can then be
1358 * queried by other functions in the API. This routine accepts a set of
1359 * command-line arguments so that the compilation can be configured in the same
1360 * way that the compiler is configured on the command line.
1361 *
1362 * \param CIdx The index object with which the translation unit will be
1363 * associated.
1364 *
1365 * \param source_filename The name of the source file to load, or NULL if the
1366 * source file is included in \c command_line_args.
1367 *
1368 * \param command_line_args The command-line arguments that would be
1369 * passed to the \c clang executable if it were being invoked out-of-process.
1370 * These command-line options will be parsed and will affect how the translation
1371 * unit is parsed. Note that the following options are ignored: '-c',
1372 * '-emit-ast', '-fsyntax-only' (which is the default), and '-o \<output file>'.
1373 *
1374 * \param num_command_line_args The number of command-line arguments in
1375 * \c command_line_args.
1376 *
1377 * \param unsaved_files the files that have not yet been saved to disk
1378 * but may be required for parsing, including the contents of
1379 * those files. The contents and name of these files (as specified by
1380 * CXUnsavedFile) are copied when necessary, so the client only needs to
1381 * guarantee their validity until the call to this function returns.
1382 *
1383 * \param num_unsaved_files the number of unsaved file entries in \p
1384 * unsaved_files.
1385 *
1386 * \param options A bitmask of options that affects how the translation unit
1387 * is managed but not its compilation. This should be a bitwise OR of the
1388 * CXTranslationUnit_XXX flags.
1389 *
1390 * \param[out] out_TU A non-NULL pointer to store the created
1391 * \c CXTranslationUnit, describing the parsed code and containing any
1392 * diagnostics produced by the compiler.
1393 *
1394 * \returns Zero on success, otherwise returns an error code.
1395 */
1396CINDEX_LINKAGE enum CXErrorCode
1397clang_parseTranslationUnit2(CXIndex CIdx,
1398 const char *source_filename,
1399 const char *const *command_line_args,
1400 int num_command_line_args,
1401 struct CXUnsavedFile *unsaved_files,
1402 unsigned num_unsaved_files,
1403 unsigned options,
1404 CXTranslationUnit *out_TU);
1405
1406/**
1407 * \brief Same as clang_parseTranslationUnit2 but requires a full command line
1408 * for \c command_line_args including argv[0]. This is useful if the standard
1409 * library paths are relative to the binary.
1410 */
1411CINDEX_LINKAGE enum CXErrorCode clang_parseTranslationUnit2FullArgv(
1412 CXIndex CIdx, const char *source_filename,
1413 const char *const *command_line_args, int num_command_line_args,
1414 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
1415 unsigned options, CXTranslationUnit *out_TU);
1416
1417/**
1418 * \brief Flags that control how translation units are saved.
1419 *
1420 * The enumerators in this enumeration type are meant to be bitwise
1421 * ORed together to specify which options should be used when
1422 * saving the translation unit.
1423 */
1424enum CXSaveTranslationUnit_Flags {
1425 /**
1426 * \brief Used to indicate that no special saving options are needed.
1427 */
1428 CXSaveTranslationUnit_None = 0x0
1429};
1430
1431/**
1432 * \brief Returns the set of flags that is suitable for saving a translation
1433 * unit.
1434 *
1435 * The set of flags returned provide options for
1436 * \c clang_saveTranslationUnit() by default. The returned flag
1437 * set contains an unspecified set of options that save translation units with
1438 * the most commonly-requested data.
1439 */
1440CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1441
1442/**
1443 * \brief Describes the kind of error that occurred (if any) in a call to
1444 * \c clang_saveTranslationUnit().
1445 */
1446enum CXSaveError {
1447 /**
1448 * \brief Indicates that no error occurred while saving a translation unit.
1449 */
1450 CXSaveError_None = 0,
1451
1452 /**
1453 * \brief Indicates that an unknown error occurred while attempting to save
1454 * the file.
1455 *
1456 * This error typically indicates that file I/O failed when attempting to
1457 * write the file.
1458 */
1459 CXSaveError_Unknown = 1,
1460
1461 /**
1462 * \brief Indicates that errors during translation prevented this attempt
1463 * to save the translation unit.
1464 *
1465 * Errors that prevent the translation unit from being saved can be
1466 * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1467 */
1468 CXSaveError_TranslationErrors = 2,
1469
1470 /**
1471 * \brief Indicates that the translation unit to be saved was somehow
1472 * invalid (e.g., NULL).
1473 */
1474 CXSaveError_InvalidTU = 3
1475};
1476
1477/**
1478 * \brief Saves a translation unit into a serialized representation of
1479 * that translation unit on disk.
1480 *
1481 * Any translation unit that was parsed without error can be saved
1482 * into a file. The translation unit can then be deserialized into a
1483 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1484 * if it is an incomplete translation unit that corresponds to a
1485 * header, used as a precompiled header when parsing other translation
1486 * units.
1487 *
1488 * \param TU The translation unit to save.
1489 *
1490 * \param FileName The file to which the translation unit will be saved.
1491 *
1492 * \param options A bitmask of options that affects how the translation unit
1493 * is saved. This should be a bitwise OR of the
1494 * CXSaveTranslationUnit_XXX flags.
1495 *
1496 * \returns A value that will match one of the enumerators of the CXSaveError
1497 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1498 * saved successfully, while a non-zero value indicates that a problem occurred.
1499 */
1500CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
1501 const char *FileName,
1502 unsigned options);
1503
1504/**
1505 * \brief Suspend a translation unit in order to free memory associated with it.
1506 *
1507 * A suspended translation unit uses significantly less memory but on the other
1508 * side does not support any other calls than \c clang_reparseTranslationUnit
1509 * to resume it or \c clang_disposeTranslationUnit to dispose it completely.
1510 */
1511CINDEX_LINKAGE unsigned clang_suspendTranslationUnit(CXTranslationUnit);
1512
1513/**
1514 * \brief Destroy the specified CXTranslationUnit object.
1515 */
1516CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
1517
1518/**
1519 * \brief Flags that control the reparsing of translation units.
1520 *
1521 * The enumerators in this enumeration type are meant to be bitwise
1522 * ORed together to specify which options should be used when
1523 * reparsing the translation unit.
1524 */
1525enum CXReparse_Flags {
1526 /**
1527 * \brief Used to indicate that no special reparsing options are needed.
1528 */
1529 CXReparse_None = 0x0
1530};
1531
1532/**
1533 * \brief Returns the set of flags that is suitable for reparsing a translation
1534 * unit.
1535 *
1536 * The set of flags returned provide options for
1537 * \c clang_reparseTranslationUnit() by default. The returned flag
1538 * set contains an unspecified set of optimizations geared toward common uses
1539 * of reparsing. The set of optimizations enabled may change from one version
1540 * to the next.
1541 */
1542CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1543
1544/**
1545 * \brief Reparse the source files that produced this translation unit.
1546 *
1547 * This routine can be used to re-parse the source files that originally
1548 * created the given translation unit, for example because those source files
1549 * have changed (either on disk or as passed via \p unsaved_files). The
1550 * source code will be reparsed with the same command-line options as it
1551 * was originally parsed.
1552 *
1553 * Reparsing a translation unit invalidates all cursors and source locations
1554 * that refer into that translation unit. This makes reparsing a translation
1555 * unit semantically equivalent to destroying the translation unit and then
1556 * creating a new translation unit with the same command-line arguments.
1557 * However, it may be more efficient to reparse a translation
1558 * unit using this routine.
1559 *
1560 * \param TU The translation unit whose contents will be re-parsed. The
1561 * translation unit must originally have been built with
1562 * \c clang_createTranslationUnitFromSourceFile().
1563 *
1564 * \param num_unsaved_files The number of unsaved file entries in \p
1565 * unsaved_files.
1566 *
1567 * \param unsaved_files The files that have not yet been saved to disk
1568 * but may be required for parsing, including the contents of
1569 * those files. The contents and name of these files (as specified by
1570 * CXUnsavedFile) are copied when necessary, so the client only needs to
1571 * guarantee their validity until the call to this function returns.
1572 *
1573 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1574 * The function \c clang_defaultReparseOptions() produces a default set of
1575 * options recommended for most uses, based on the translation unit.
1576 *
1577 * \returns 0 if the sources could be reparsed. A non-zero error code will be
1578 * returned if reparsing was impossible, such that the translation unit is
1579 * invalid. In such cases, the only valid call for \c TU is
1580 * \c clang_disposeTranslationUnit(TU). The error codes returned by this
1581 * routine are described by the \c CXErrorCode enum.
1582 */
1583CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1584 unsigned num_unsaved_files,
1585 struct CXUnsavedFile *unsaved_files,
1586 unsigned options);
1587
1588/**
1589 * \brief Categorizes how memory is being used by a translation unit.
1590 */
1591enum CXTUResourceUsageKind {
1592 CXTUResourceUsage_AST = 1,
1593 CXTUResourceUsage_Identifiers = 2,
1594 CXTUResourceUsage_Selectors = 3,
1595 CXTUResourceUsage_GlobalCompletionResults = 4,
1596 CXTUResourceUsage_SourceManagerContentCache = 5,
1597 CXTUResourceUsage_AST_SideTables = 6,
1598 CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
1599 CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1600 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1601 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
1602 CXTUResourceUsage_Preprocessor = 11,
1603 CXTUResourceUsage_PreprocessingRecord = 12,
1604 CXTUResourceUsage_SourceManager_DataStructures = 13,
1605 CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
1606 CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1607 CXTUResourceUsage_MEMORY_IN_BYTES_END =
1608 CXTUResourceUsage_Preprocessor_HeaderSearch,
1609
1610 CXTUResourceUsage_First = CXTUResourceUsage_AST,
1611 CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
1612};
1613
1614/**
1615 * \brief Returns the human-readable null-terminated C string that represents
1616 * the name of the memory category. This string should never be freed.
1617 */
1618CINDEX_LINKAGE
1619const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
1620
1621typedef struct CXTUResourceUsageEntry {
1622 /* \brief The memory usage category. */
1623 enum CXTUResourceUsageKind kind;
1624 /* \brief Amount of resources used.
1625 The units will depend on the resource kind. */
1626 unsigned long amount;
1627} CXTUResourceUsageEntry;
1628
1629/**
1630 * \brief The memory usage of a CXTranslationUnit, broken into categories.
1631 */
1632typedef struct CXTUResourceUsage {
1633 /* \brief Private data member, used for queries. */
1634 void *data;
1635
1636 /* \brief The number of entries in the 'entries' array. */
1637 unsigned numEntries;
1638
1639 /* \brief An array of key-value pairs, representing the breakdown of memory
1640 usage. */
1641 CXTUResourceUsageEntry *entries;
1642
1643} CXTUResourceUsage;
1644
1645/**
1646 * \brief Return the memory usage of a translation unit. This object
1647 * should be released with clang_disposeCXTUResourceUsage().
1648 */
1649CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
1650
1651CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
1652
1653/**
1654 * \brief Get target information for this translation unit.
1655 *
1656 * The CXTargetInfo object cannot outlive the CXTranslationUnit object.
1657 */
1658CINDEX_LINKAGE CXTargetInfo
1659clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit);
1660
1661/**
1662 * \brief Destroy the CXTargetInfo object.
1663 */
1664CINDEX_LINKAGE void
1665clang_TargetInfo_dispose(CXTargetInfo Info);
1666
1667/**
1668 * \brief Get the normalized target triple as a string.
1669 *
1670 * Returns the empty string in case of any error.
1671 */
1672CINDEX_LINKAGE CXString
1673clang_TargetInfo_getTriple(CXTargetInfo Info);
1674
1675/**
1676 * \brief Get the pointer width of the target in bits.
1677 *
1678 * Returns -1 in case of error.
1679 */
1680CINDEX_LINKAGE int
1681clang_TargetInfo_getPointerWidth(CXTargetInfo Info);
1682
1683/**
1684 * @}
1685 */
1686
1687/**
1688 * \brief Describes the kind of entity that a cursor refers to.
1689 */
1690enum CXCursorKind {
1691 /* Declarations */
1692 /**
1693 * \brief A declaration whose specific kind is not exposed via this
1694 * interface.
1695 *
1696 * Unexposed declarations have the same operations as any other kind
1697 * of declaration; one can extract their location information,
1698 * spelling, find their definitions, etc. However, the specific kind
1699 * of the declaration is not reported.
1700 */
1701 CXCursor_UnexposedDecl = 1,
1702 /** \brief A C or C++ struct. */
1703 CXCursor_StructDecl = 2,
1704 /** \brief A C or C++ union. */
1705 CXCursor_UnionDecl = 3,
1706 /** \brief A C++ class. */
1707 CXCursor_ClassDecl = 4,
1708 /** \brief An enumeration. */
1709 CXCursor_EnumDecl = 5,
1710 /**
1711 * \brief A field (in C) or non-static data member (in C++) in a
1712 * struct, union, or C++ class.
1713 */
1714 CXCursor_FieldDecl = 6,
1715 /** \brief An enumerator constant. */
1716 CXCursor_EnumConstantDecl = 7,
1717 /** \brief A function. */
1718 CXCursor_FunctionDecl = 8,
1719 /** \brief A variable. */
1720 CXCursor_VarDecl = 9,
1721 /** \brief A function or method parameter. */
1722 CXCursor_ParmDecl = 10,
1723 /** \brief An Objective-C \@interface. */
1724 CXCursor_ObjCInterfaceDecl = 11,
1725 /** \brief An Objective-C \@interface for a category. */
1726 CXCursor_ObjCCategoryDecl = 12,
1727 /** \brief An Objective-C \@protocol declaration. */
1728 CXCursor_ObjCProtocolDecl = 13,
1729 /** \brief An Objective-C \@property declaration. */
1730 CXCursor_ObjCPropertyDecl = 14,
1731 /** \brief An Objective-C instance variable. */
1732 CXCursor_ObjCIvarDecl = 15,
1733 /** \brief An Objective-C instance method. */
1734 CXCursor_ObjCInstanceMethodDecl = 16,
1735 /** \brief An Objective-C class method. */
1736 CXCursor_ObjCClassMethodDecl = 17,
1737 /** \brief An Objective-C \@implementation. */
1738 CXCursor_ObjCImplementationDecl = 18,
1739 /** \brief An Objective-C \@implementation for a category. */
1740 CXCursor_ObjCCategoryImplDecl = 19,
1741 /** \brief A typedef. */
1742 CXCursor_TypedefDecl = 20,
1743 /** \brief A C++ class method. */
1744 CXCursor_CXXMethod = 21,
1745 /** \brief A C++ namespace. */
1746 CXCursor_Namespace = 22,
1747 /** \brief A linkage specification, e.g. 'extern "C"'. */
1748 CXCursor_LinkageSpec = 23,
1749 /** \brief A C++ constructor. */
1750 CXCursor_Constructor = 24,
1751 /** \brief A C++ destructor. */
1752 CXCursor_Destructor = 25,
1753 /** \brief A C++ conversion function. */
1754 CXCursor_ConversionFunction = 26,
1755 /** \brief A C++ template type parameter. */
1756 CXCursor_TemplateTypeParameter = 27,
1757 /** \brief A C++ non-type template parameter. */
1758 CXCursor_NonTypeTemplateParameter = 28,
1759 /** \brief A C++ template template parameter. */
1760 CXCursor_TemplateTemplateParameter = 29,
1761 /** \brief A C++ function template. */
1762 CXCursor_FunctionTemplate = 30,
1763 /** \brief A C++ class template. */
1764 CXCursor_ClassTemplate = 31,
1765 /** \brief A C++ class template partial specialization. */
1766 CXCursor_ClassTemplatePartialSpecialization = 32,
1767 /** \brief A C++ namespace alias declaration. */
1768 CXCursor_NamespaceAlias = 33,
1769 /** \brief A C++ using directive. */
1770 CXCursor_UsingDirective = 34,
1771 /** \brief A C++ using declaration. */
1772 CXCursor_UsingDeclaration = 35,
1773 /** \brief A C++ alias declaration */
1774 CXCursor_TypeAliasDecl = 36,
1775 /** \brief An Objective-C \@synthesize definition. */
1776 CXCursor_ObjCSynthesizeDecl = 37,
1777 /** \brief An Objective-C \@dynamic definition. */
1778 CXCursor_ObjCDynamicDecl = 38,
1779 /** \brief An access specifier. */
1780 CXCursor_CXXAccessSpecifier = 39,
1781
1782 CXCursor_FirstDecl = CXCursor_UnexposedDecl,
1783 CXCursor_LastDecl = CXCursor_CXXAccessSpecifier,
1784
1785 /* References */
1786 CXCursor_FirstRef = 40, /* Decl references */
1787 CXCursor_ObjCSuperClassRef = 40,
1788 CXCursor_ObjCProtocolRef = 41,
1789 CXCursor_ObjCClassRef = 42,
1790 /**
1791 * \brief A reference to a type declaration.
1792 *
1793 * A type reference occurs anywhere where a type is named but not
1794 * declared. For example, given:
1795 *
1796 * \code
1797 * typedef unsigned size_type;
1798 * size_type size;
1799 * \endcode
1800 *
1801 * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1802 * while the type of the variable "size" is referenced. The cursor
1803 * referenced by the type of size is the typedef for size_type.
1804 */
1805 CXCursor_TypeRef = 43,
1806 CXCursor_CXXBaseSpecifier = 44,
1807 /**
1808 * \brief A reference to a class template, function template, template
1809 * template parameter, or class template partial specialization.
1810 */
1811 CXCursor_TemplateRef = 45,
1812 /**
1813 * \brief A reference to a namespace or namespace alias.
1814 */
1815 CXCursor_NamespaceRef = 46,
1816 /**
1817 * \brief A reference to a member of a struct, union, or class that occurs in
1818 * some non-expression context, e.g., a designated initializer.
1819 */
1820 CXCursor_MemberRef = 47,
1821 /**
1822 * \brief A reference to a labeled statement.
1823 *
1824 * This cursor kind is used to describe the jump to "start_over" in the
1825 * goto statement in the following example:
1826 *
1827 * \code
1828 * start_over:
1829 * ++counter;
1830 *
1831 * goto start_over;
1832 * \endcode
1833 *
1834 * A label reference cursor refers to a label statement.
1835 */
1836 CXCursor_LabelRef = 48,
1837
1838 /**
1839 * \brief A reference to a set of overloaded functions or function templates
1840 * that has not yet been resolved to a specific function or function template.
1841 *
1842 * An overloaded declaration reference cursor occurs in C++ templates where
1843 * a dependent name refers to a function. For example:
1844 *
1845 * \code
1846 * template<typename T> void swap(T&, T&);
1847 *
1848 * struct X { ... };
1849 * void swap(X&, X&);
1850 *
1851 * template<typename T>
1852 * void reverse(T* first, T* last) {
1853 * while (first < last - 1) {
1854 * swap(*first, *--last);
1855 * ++first;
1856 * }
1857 * }
1858 *
1859 * struct Y { };
1860 * void swap(Y&, Y&);
1861 * \endcode
1862 *
1863 * Here, the identifier "swap" is associated with an overloaded declaration
1864 * reference. In the template definition, "swap" refers to either of the two
1865 * "swap" functions declared above, so both results will be available. At
1866 * instantiation time, "swap" may also refer to other functions found via
1867 * argument-dependent lookup (e.g., the "swap" function at the end of the
1868 * example).
1869 *
1870 * The functions \c clang_getNumOverloadedDecls() and
1871 * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1872 * referenced by this cursor.
1873 */
1874 CXCursor_OverloadedDeclRef = 49,
1875
1876 /**
1877 * \brief A reference to a variable that occurs in some non-expression
1878 * context, e.g., a C++ lambda capture list.
1879 */
1880 CXCursor_VariableRef = 50,
1881
1882 CXCursor_LastRef = CXCursor_VariableRef,
1883
1884 /* Error conditions */
1885 CXCursor_FirstInvalid = 70,
1886 CXCursor_InvalidFile = 70,
1887 CXCursor_NoDeclFound = 71,
1888 CXCursor_NotImplemented = 72,
1889 CXCursor_InvalidCode = 73,
1890 CXCursor_LastInvalid = CXCursor_InvalidCode,
1891
1892 /* Expressions */
1893 CXCursor_FirstExpr = 100,
1894
1895 /**
1896 * \brief An expression whose specific kind is not exposed via this
1897 * interface.
1898 *
1899 * Unexposed expressions have the same operations as any other kind
1900 * of expression; one can extract their location information,
1901 * spelling, children, etc. However, the specific kind of the
1902 * expression is not reported.
1903 */
1904 CXCursor_UnexposedExpr = 100,
1905
1906 /**
1907 * \brief An expression that refers to some value declaration, such
1908 * as a function, variable, or enumerator.
1909 */
1910 CXCursor_DeclRefExpr = 101,
1911
1912 /**
1913 * \brief An expression that refers to a member of a struct, union,
1914 * class, Objective-C class, etc.
1915 */
1916 CXCursor_MemberRefExpr = 102,
1917
1918 /** \brief An expression that calls a function. */
1919 CXCursor_CallExpr = 103,
1920
1921 /** \brief An expression that sends a message to an Objective-C
1922 object or class. */
1923 CXCursor_ObjCMessageExpr = 104,
1924
1925 /** \brief An expression that represents a block literal. */
1926 CXCursor_BlockExpr = 105,
1927
1928 /** \brief An integer literal.
1929 */
1930 CXCursor_IntegerLiteral = 106,
1931
1932 /** \brief A floating point number literal.
1933 */
1934 CXCursor_FloatingLiteral = 107,
1935
1936 /** \brief An imaginary number literal.
1937 */
1938 CXCursor_ImaginaryLiteral = 108,
1939
1940 /** \brief A string literal.
1941 */
1942 CXCursor_StringLiteral = 109,
1943
1944 /** \brief A character literal.
1945 */
1946 CXCursor_CharacterLiteral = 110,
1947
1948 /** \brief A parenthesized expression, e.g. "(1)".
1949 *
1950 * This AST node is only formed if full location information is requested.
1951 */
1952 CXCursor_ParenExpr = 111,
1953
1954 /** \brief This represents the unary-expression's (except sizeof and
1955 * alignof).
1956 */
1957 CXCursor_UnaryOperator = 112,
1958
1959 /** \brief [C99 6.5.2.1] Array Subscripting.
1960 */
1961 CXCursor_ArraySubscriptExpr = 113,
1962
1963 /** \brief A builtin binary operation expression such as "x + y" or
1964 * "x <= y".
1965 */
1966 CXCursor_BinaryOperator = 114,
1967
1968 /** \brief Compound assignment such as "+=".
1969 */
1970 CXCursor_CompoundAssignOperator = 115,
1971
1972 /** \brief The ?: ternary operator.
1973 */
1974 CXCursor_ConditionalOperator = 116,
1975
1976 /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1977 * (C++ [expr.cast]), which uses the syntax (Type)expr.
1978 *
1979 * For example: (int)f.
1980 */
1981 CXCursor_CStyleCastExpr = 117,
1982
1983 /** \brief [C99 6.5.2.5]
1984 */
1985 CXCursor_CompoundLiteralExpr = 118,
1986
1987 /** \brief Describes an C or C++ initializer list.
1988 */
1989 CXCursor_InitListExpr = 119,
1990
1991 /** \brief The GNU address of label extension, representing &&label.
1992 */
1993 CXCursor_AddrLabelExpr = 120,
1994
1995 /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1996 */
1997 CXCursor_StmtExpr = 121,
1998
1999 /** \brief Represents a C11 generic selection.
2000 */
2001 CXCursor_GenericSelectionExpr = 122,
2002
2003 /** \brief Implements the GNU __null extension, which is a name for a null
2004 * pointer constant that has integral type (e.g., int or long) and is the same
2005 * size and alignment as a pointer.
2006 *
2007 * The __null extension is typically only used by system headers, which define
2008 * NULL as __null in C++ rather than using 0 (which is an integer that may not
2009 * match the size of a pointer).
2010 */
2011 CXCursor_GNUNullExpr = 123,
2012
2013 /** \brief C++'s static_cast<> expression.
2014 */
2015 CXCursor_CXXStaticCastExpr = 124,
2016
2017 /** \brief C++'s dynamic_cast<> expression.
2018 */
2019 CXCursor_CXXDynamicCastExpr = 125,
2020
2021 /** \brief C++'s reinterpret_cast<> expression.
2022 */
2023 CXCursor_CXXReinterpretCastExpr = 126,
2024
2025 /** \brief C++'s const_cast<> expression.
2026 */
2027 CXCursor_CXXConstCastExpr = 127,
2028
2029 /** \brief Represents an explicit C++ type conversion that uses "functional"
2030 * notion (C++ [expr.type.conv]).
2031 *
2032 * Example:
2033 * \code
2034 * x = int(0.5);
2035 * \endcode
2036 */
2037 CXCursor_CXXFunctionalCastExpr = 128,
2038
2039 /** \brief A C++ typeid expression (C++ [expr.typeid]).
2040 */
2041 CXCursor_CXXTypeidExpr = 129,
2042
2043 /** \brief [C++ 2.13.5] C++ Boolean Literal.
2044 */
2045 CXCursor_CXXBoolLiteralExpr = 130,
2046
2047 /** \brief [C++0x 2.14.7] C++ Pointer Literal.
2048 */
2049 CXCursor_CXXNullPtrLiteralExpr = 131,
2050
2051 /** \brief Represents the "this" expression in C++
2052 */
2053 CXCursor_CXXThisExpr = 132,
2054
2055 /** \brief [C++ 15] C++ Throw Expression.
2056 *
2057 * This handles 'throw' and 'throw' assignment-expression. When
2058 * assignment-expression isn't present, Op will be null.
2059 */
2060 CXCursor_CXXThrowExpr = 133,
2061
2062 /** \brief A new expression for memory allocation and constructor calls, e.g:
2063 * "new CXXNewExpr(foo)".
2064 */
2065 CXCursor_CXXNewExpr = 134,
2066
2067 /** \brief A delete expression for memory deallocation and destructor calls,
2068 * e.g. "delete[] pArray".
2069 */
2070 CXCursor_CXXDeleteExpr = 135,
2071
2072 /** \brief A unary expression. (noexcept, sizeof, or other traits)
2073 */
2074 CXCursor_UnaryExpr = 136,
2075
2076 /** \brief An Objective-C string literal i.e. @"foo".
2077 */
2078 CXCursor_ObjCStringLiteral = 137,
2079
2080 /** \brief An Objective-C \@encode expression.
2081 */
2082 CXCursor_ObjCEncodeExpr = 138,
2083
2084 /** \brief An Objective-C \@selector expression.
2085 */
2086 CXCursor_ObjCSelectorExpr = 139,
2087
2088 /** \brief An Objective-C \@protocol expression.
2089 */
2090 CXCursor_ObjCProtocolExpr = 140,
2091
2092 /** \brief An Objective-C "bridged" cast expression, which casts between
2093 * Objective-C pointers and C pointers, transferring ownership in the process.
2094 *
2095 * \code
2096 * NSString *str = (__bridge_transfer NSString *)CFCreateString();
2097 * \endcode
2098 */
2099 CXCursor_ObjCBridgedCastExpr = 141,
2100
2101 /** \brief Represents a C++0x pack expansion that produces a sequence of
2102 * expressions.
2103 *
2104 * A pack expansion expression contains a pattern (which itself is an
2105 * expression) followed by an ellipsis. For example:
2106 *
2107 * \code
2108 * template<typename F, typename ...Types>
2109 * void forward(F f, Types &&...args) {
2110 * f(static_cast<Types&&>(args)...);
2111 * }
2112 * \endcode
2113 */
2114 CXCursor_PackExpansionExpr = 142,
2115
2116 /** \brief Represents an expression that computes the length of a parameter
2117 * pack.
2118 *
2119 * \code
2120 * template<typename ...Types>
2121 * struct count {
2122 * static const unsigned value = sizeof...(Types);
2123 * };
2124 * \endcode
2125 */
2126 CXCursor_SizeOfPackExpr = 143,
2127
2128 /* \brief Represents a C++ lambda expression that produces a local function
2129 * object.
2130 *
2131 * \code
2132 * void abssort(float *x, unsigned N) {
2133 * std::sort(x, x + N,
2134 * [](float a, float b) {
2135 * return std::abs(a) < std::abs(b);
2136 * });
2137 * }
2138 * \endcode
2139 */
2140 CXCursor_LambdaExpr = 144,
2141
2142 /** \brief Objective-c Boolean Literal.
2143 */
2144 CXCursor_ObjCBoolLiteralExpr = 145,
2145
2146 /** \brief Represents the "self" expression in an Objective-C method.
2147 */
2148 CXCursor_ObjCSelfExpr = 146,
2149
2150 /** \brief OpenMP 4.0 [2.4, Array Section].
2151 */
2152 CXCursor_OMPArraySectionExpr = 147,
2153
2154 /** \brief Represents an @available(...) check.
2155 */
2156 CXCursor_ObjCAvailabilityCheckExpr = 148,
2157
2158 CXCursor_LastExpr = CXCursor_ObjCAvailabilityCheckExpr,
2159
2160 /* Statements */
2161 CXCursor_FirstStmt = 200,
2162 /**
2163 * \brief A statement whose specific kind is not exposed via this
2164 * interface.
2165 *
2166 * Unexposed statements have the same operations as any other kind of
2167 * statement; one can extract their location information, spelling,
2168 * children, etc. However, the specific kind of the statement is not
2169 * reported.
2170 */
2171 CXCursor_UnexposedStmt = 200,
2172
2173 /** \brief A labelled statement in a function.
2174 *
2175 * This cursor kind is used to describe the "start_over:" label statement in
2176 * the following example:
2177 *
2178 * \code
2179 * start_over:
2180 * ++counter;
2181 * \endcode
2182 *
2183 */
2184 CXCursor_LabelStmt = 201,
2185
2186 /** \brief A group of statements like { stmt stmt }.
2187 *
2188 * This cursor kind is used to describe compound statements, e.g. function
2189 * bodies.
2190 */
2191 CXCursor_CompoundStmt = 202,
2192
2193 /** \brief A case statement.
2194 */
2195 CXCursor_CaseStmt = 203,
2196
2197 /** \brief A default statement.
2198 */
2199 CXCursor_DefaultStmt = 204,
2200
2201 /** \brief An if statement
2202 */
2203 CXCursor_IfStmt = 205,
2204
2205 /** \brief A switch statement.
2206 */
2207 CXCursor_SwitchStmt = 206,
2208
2209 /** \brief A while statement.
2210 */
2211 CXCursor_WhileStmt = 207,
2212
2213 /** \brief A do statement.
2214 */
2215 CXCursor_DoStmt = 208,
2216
2217 /** \brief A for statement.
2218 */
2219 CXCursor_ForStmt = 209,
2220
2221 /** \brief A goto statement.
2222 */
2223 CXCursor_GotoStmt = 210,
2224
2225 /** \brief An indirect goto statement.
2226 */
2227 CXCursor_IndirectGotoStmt = 211,
2228
2229 /** \brief A continue statement.
2230 */
2231 CXCursor_ContinueStmt = 212,
2232
2233 /** \brief A break statement.
2234 */
2235 CXCursor_BreakStmt = 213,
2236
2237 /** \brief A return statement.
2238 */
2239 CXCursor_ReturnStmt = 214,
2240
2241 /** \brief A GCC inline assembly statement extension.
2242 */
2243 CXCursor_GCCAsmStmt = 215,
2244 CXCursor_AsmStmt = CXCursor_GCCAsmStmt,
2245
2246 /** \brief Objective-C's overall \@try-\@catch-\@finally statement.
2247 */
2248 CXCursor_ObjCAtTryStmt = 216,
2249
2250 /** \brief Objective-C's \@catch statement.
2251 */
2252 CXCursor_ObjCAtCatchStmt = 217,
2253
2254 /** \brief Objective-C's \@finally statement.
2255 */
2256 CXCursor_ObjCAtFinallyStmt = 218,
2257
2258 /** \brief Objective-C's \@throw statement.
2259 */
2260 CXCursor_ObjCAtThrowStmt = 219,
2261
2262 /** \brief Objective-C's \@synchronized statement.
2263 */
2264 CXCursor_ObjCAtSynchronizedStmt = 220,
2265
2266 /** \brief Objective-C's autorelease pool statement.
2267 */
2268 CXCursor_ObjCAutoreleasePoolStmt = 221,
2269
2270 /** \brief Objective-C's collection statement.
2271 */
2272 CXCursor_ObjCForCollectionStmt = 222,
2273
2274 /** \brief C++'s catch statement.
2275 */
2276 CXCursor_CXXCatchStmt = 223,
2277
2278 /** \brief C++'s try statement.
2279 */
2280 CXCursor_CXXTryStmt = 224,
2281
2282 /** \brief C++'s for (* : *) statement.
2283 */
2284 CXCursor_CXXForRangeStmt = 225,
2285
2286 /** \brief Windows Structured Exception Handling's try statement.
2287 */
2288 CXCursor_SEHTryStmt = 226,
2289
2290 /** \brief Windows Structured Exception Handling's except statement.
2291 */
2292 CXCursor_SEHExceptStmt = 227,
2293
2294 /** \brief Windows Structured Exception Handling's finally statement.
2295 */
2296 CXCursor_SEHFinallyStmt = 228,
2297
2298 /** \brief A MS inline assembly statement extension.
2299 */
2300 CXCursor_MSAsmStmt = 229,
2301
2302 /** \brief The null statement ";": C99 6.8.3p3.
2303 *
2304 * This cursor kind is used to describe the null statement.
2305 */
2306 CXCursor_NullStmt = 230,
2307
2308 /** \brief Adaptor class for mixing declarations with statements and
2309 * expressions.
2310 */
2311 CXCursor_DeclStmt = 231,
2312
2313 /** \brief OpenMP parallel directive.
2314 */
2315 CXCursor_OMPParallelDirective = 232,
2316
2317 /** \brief OpenMP SIMD directive.
2318 */
2319 CXCursor_OMPSimdDirective = 233,
2320
2321 /** \brief OpenMP for directive.
2322 */
2323 CXCursor_OMPForDirective = 234,
2324
2325 /** \brief OpenMP sections directive.
2326 */
2327 CXCursor_OMPSectionsDirective = 235,
2328
2329 /** \brief OpenMP section directive.
2330 */
2331 CXCursor_OMPSectionDirective = 236,
2332
2333 /** \brief OpenMP single directive.
2334 */
2335 CXCursor_OMPSingleDirective = 237,
2336
2337 /** \brief OpenMP parallel for directive.
2338 */
2339 CXCursor_OMPParallelForDirective = 238,
2340
2341 /** \brief OpenMP parallel sections directive.
2342 */
2343 CXCursor_OMPParallelSectionsDirective = 239,
2344
2345 /** \brief OpenMP task directive.
2346 */
2347 CXCursor_OMPTaskDirective = 240,
2348
2349 /** \brief OpenMP master directive.
2350 */
2351 CXCursor_OMPMasterDirective = 241,
2352
2353 /** \brief OpenMP critical directive.
2354 */
2355 CXCursor_OMPCriticalDirective = 242,
2356
2357 /** \brief OpenMP taskyield directive.
2358 */
2359 CXCursor_OMPTaskyieldDirective = 243,
2360
2361 /** \brief OpenMP barrier directive.
2362 */
2363 CXCursor_OMPBarrierDirective = 244,
2364
2365 /** \brief OpenMP taskwait directive.
2366 */
2367 CXCursor_OMPTaskwaitDirective = 245,
2368
2369 /** \brief OpenMP flush directive.
2370 */
2371 CXCursor_OMPFlushDirective = 246,
2372
2373 /** \brief Windows Structured Exception Handling's leave statement.
2374 */
2375 CXCursor_SEHLeaveStmt = 247,
2376
2377 /** \brief OpenMP ordered directive.
2378 */
2379 CXCursor_OMPOrderedDirective = 248,
2380
2381 /** \brief OpenMP atomic directive.
2382 */
2383 CXCursor_OMPAtomicDirective = 249,
2384
2385 /** \brief OpenMP for SIMD directive.
2386 */
2387 CXCursor_OMPForSimdDirective = 250,
2388
2389 /** \brief OpenMP parallel for SIMD directive.
2390 */
2391 CXCursor_OMPParallelForSimdDirective = 251,
2392
2393 /** \brief OpenMP target directive.
2394 */
2395 CXCursor_OMPTargetDirective = 252,
2396
2397 /** \brief OpenMP teams directive.
2398 */
2399 CXCursor_OMPTeamsDirective = 253,
2400
2401 /** \brief OpenMP taskgroup directive.
2402 */
2403 CXCursor_OMPTaskgroupDirective = 254,
2404
2405 /** \brief OpenMP cancellation point directive.
2406 */
2407 CXCursor_OMPCancellationPointDirective = 255,
2408
2409 /** \brief OpenMP cancel directive.
2410 */
2411 CXCursor_OMPCancelDirective = 256,
2412
2413 /** \brief OpenMP target data directive.
2414 */
2415 CXCursor_OMPTargetDataDirective = 257,
2416
2417 /** \brief OpenMP taskloop directive.
2418 */
2419 CXCursor_OMPTaskLoopDirective = 258,
2420
2421 /** \brief OpenMP taskloop simd directive.
2422 */
2423 CXCursor_OMPTaskLoopSimdDirective = 259,
2424
2425 /** \brief OpenMP distribute directive.
2426 */
2427 CXCursor_OMPDistributeDirective = 260,
2428
2429 /** \brief OpenMP target enter data directive.
2430 */
2431 CXCursor_OMPTargetEnterDataDirective = 261,
2432
2433 /** \brief OpenMP target exit data directive.
2434 */
2435 CXCursor_OMPTargetExitDataDirective = 262,
2436
2437 /** \brief OpenMP target parallel directive.
2438 */
2439 CXCursor_OMPTargetParallelDirective = 263,
2440
2441 /** \brief OpenMP target parallel for directive.
2442 */
2443 CXCursor_OMPTargetParallelForDirective = 264,
2444
2445 /** \brief OpenMP target update directive.
2446 */
2447 CXCursor_OMPTargetUpdateDirective = 265,
2448
2449 /** \brief OpenMP distribute parallel for directive.
2450 */
2451 CXCursor_OMPDistributeParallelForDirective = 266,
2452
2453 /** \brief OpenMP distribute parallel for simd directive.
2454 */
2455 CXCursor_OMPDistributeParallelForSimdDirective = 267,
2456
2457 /** \brief OpenMP distribute simd directive.
2458 */
2459 CXCursor_OMPDistributeSimdDirective = 268,
2460
2461 /** \brief OpenMP target parallel for simd directive.
2462 */
2463 CXCursor_OMPTargetParallelForSimdDirective = 269,
2464
2465 /** \brief OpenMP target simd directive.
2466 */
2467 CXCursor_OMPTargetSimdDirective = 270,
2468
2469 /** \brief OpenMP teams distribute directive.
2470 */
2471 CXCursor_OMPTeamsDistributeDirective = 271,
2472
2473 /** \brief OpenMP teams distribute simd directive.
2474 */
2475 CXCursor_OMPTeamsDistributeSimdDirective = 272,
2476
2477 /** \brief OpenMP teams distribute parallel for simd directive.
2478 */
2479 CXCursor_OMPTeamsDistributeParallelForSimdDirective = 273,
2480
2481 /** \brief OpenMP teams distribute parallel for directive.
2482 */
2483 CXCursor_OMPTeamsDistributeParallelForDirective = 274,
2484
2485 /** \brief OpenMP target teams directive.
2486 */
2487 CXCursor_OMPTargetTeamsDirective = 275,
2488
2489 /** \brief OpenMP target teams distribute directive.
2490 */
2491 CXCursor_OMPTargetTeamsDistributeDirective = 276,
2492
2493 /** \brief OpenMP target teams distribute parallel for directive.
2494 */
2495 CXCursor_OMPTargetTeamsDistributeParallelForDirective = 277,
2496
2497 /** \brief OpenMP target teams distribute parallel for simd directive.
2498 */
2499 CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective = 278,
2500
2501 /** \brief OpenMP target teams distribute simd directive.
2502 */
2503 CXCursor_OMPTargetTeamsDistributeSimdDirective = 279,
2504
2505 CXCursor_LastStmt = CXCursor_OMPTargetTeamsDistributeSimdDirective,
2506
2507 /**
2508 * \brief Cursor that represents the translation unit itself.
2509 *
2510 * The translation unit cursor exists primarily to act as the root
2511 * cursor for traversing the contents of a translation unit.
2512 */
2513 CXCursor_TranslationUnit = 300,
2514
2515 /* Attributes */
2516 CXCursor_FirstAttr = 400,
2517 /**
2518 * \brief An attribute whose specific kind is not exposed via this
2519 * interface.
2520 */
2521 CXCursor_UnexposedAttr = 400,
2522
2523 CXCursor_IBActionAttr = 401,
2524 CXCursor_IBOutletAttr = 402,
2525 CXCursor_IBOutletCollectionAttr = 403,
2526 CXCursor_CXXFinalAttr = 404,
2527 CXCursor_CXXOverrideAttr = 405,
2528 CXCursor_AnnotateAttr = 406,
2529 CXCursor_AsmLabelAttr = 407,
2530 CXCursor_PackedAttr = 408,
2531 CXCursor_PureAttr = 409,
2532 CXCursor_ConstAttr = 410,
2533 CXCursor_NoDuplicateAttr = 411,
2534 CXCursor_CUDAConstantAttr = 412,
2535 CXCursor_CUDADeviceAttr = 413,
2536 CXCursor_CUDAGlobalAttr = 414,
2537 CXCursor_CUDAHostAttr = 415,
2538 CXCursor_CUDASharedAttr = 416,
2539 CXCursor_VisibilityAttr = 417,
2540 CXCursor_DLLExport = 418,
2541 CXCursor_DLLImport = 419,
2542 CXCursor_LastAttr = CXCursor_DLLImport,
2543
2544 /* Preprocessing */
2545 CXCursor_PreprocessingDirective = 500,
2546 CXCursor_MacroDefinition = 501,
2547 CXCursor_MacroExpansion = 502,
2548 CXCursor_MacroInstantiation = CXCursor_MacroExpansion,
2549 CXCursor_InclusionDirective = 503,
2550 CXCursor_FirstPreprocessing = CXCursor_PreprocessingDirective,
2551 CXCursor_LastPreprocessing = CXCursor_InclusionDirective,
2552
2553 /* Extra Declarations */
2554 /**
2555 * \brief A module import declaration.
2556 */
2557 CXCursor_ModuleImportDecl = 600,
2558 CXCursor_TypeAliasTemplateDecl = 601,
2559 /**
2560 * \brief A static_assert or _Static_assert node
2561 */
2562 CXCursor_StaticAssert = 602,
2563 /**
2564 * \brief a friend declaration.
2565 */
2566 CXCursor_FriendDecl = 603,
2567 CXCursor_FirstExtraDecl = CXCursor_ModuleImportDecl,
2568 CXCursor_LastExtraDecl = CXCursor_FriendDecl,
2569
2570 /**
2571 * \brief A code completion overload candidate.
2572 */
2573 CXCursor_OverloadCandidate = 700
2574};
2575
2576/**
2577 * \brief A cursor representing some element in the abstract syntax tree for
2578 * a translation unit.
2579 *
2580 * The cursor abstraction unifies the different kinds of entities in a
2581 * program--declaration, statements, expressions, references to declarations,
2582 * etc.--under a single "cursor" abstraction with a common set of operations.
2583 * Common operation for a cursor include: getting the physical location in
2584 * a source file where the cursor points, getting the name associated with a
2585 * cursor, and retrieving cursors for any child nodes of a particular cursor.
2586 *
2587 * Cursors can be produced in two specific ways.
2588 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
2589 * from which one can use clang_visitChildren() to explore the rest of the
2590 * translation unit. clang_getCursor() maps from a physical source location
2591 * to the entity that resides at that location, allowing one to map from the
2592 * source code into the AST.
2593 */
2594typedef struct {
2595 enum CXCursorKind kind;
2596 int xdata;
2597 const void *data[3];
2598} CXCursor;
2599
2600/**
2601 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
2602 *
2603 * @{
2604 */
2605
2606/**
2607 * \brief Retrieve the NULL cursor, which represents no entity.
2608 */
2609CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
2610
2611/**
2612 * \brief Retrieve the cursor that represents the given translation unit.
2613 *
2614 * The translation unit cursor can be used to start traversing the
2615 * various declarations within the given translation unit.
2616 */
2617CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
2618
2619/**
2620 * \brief Determine whether two cursors are equivalent.
2621 */
2622CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
2623
2624/**
2625 * \brief Returns non-zero if \p cursor is null.
2626 */
2627CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor cursor);
2628
2629/**
2630 * \brief Compute a hash value for the given cursor.
2631 */
2632CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
2633
2634/**
2635 * \brief Retrieve the kind of the given cursor.
2636 */
2637CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2638
2639/**
2640 * \brief Determine whether the given cursor kind represents a declaration.
2641 */
2642CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2643
2644/**
2645 * \brief Determine whether the given declaration is invalid.
2646 *
2647 * A declaration is invalid if it could not be parsed successfully.
2648 *
2649 * \returns non-zero if the cursor represents a declaration and it is
2650 * invalid, otherwise NULL.
2651 */
2652CINDEX_LINKAGE unsigned clang_isInvalidDeclaration(CXCursor);
2653
2654/**
2655 * \brief Determine whether the given cursor kind represents a simple
2656 * reference.
2657 *
2658 * Note that other kinds of cursors (such as expressions) can also refer to
2659 * other cursors. Use clang_getCursorReferenced() to determine whether a
2660 * particular cursor refers to another entity.
2661 */
2662CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2663
2664/**
2665 * \brief Determine whether the given cursor kind represents an expression.
2666 */
2667CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2668
2669/**
2670 * \brief Determine whether the given cursor kind represents a statement.
2671 */
2672CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2673
2674/**
2675 * \brief Determine whether the given cursor kind represents an attribute.
2676 */
2677CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2678
2679/**
2680 * \brief Determine whether the given cursor has any attributes.
2681 */
2682CINDEX_LINKAGE unsigned clang_Cursor_hasAttrs(CXCursor C);
2683
2684/**
2685 * \brief Determine whether the given cursor kind represents an invalid
2686 * cursor.
2687 */
2688CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2689
2690/**
2691 * \brief Determine whether the given cursor kind represents a translation
2692 * unit.
2693 */
2694CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
2695
2696/***
2697 * \brief Determine whether the given cursor represents a preprocessing
2698 * element, such as a preprocessor directive or macro instantiation.
2699 */
2700CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2701
2702/***
2703 * \brief Determine whether the given cursor represents a currently
2704 * unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2705 */
2706CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2707
2708/**
2709 * \brief Describe the linkage of the entity referred to by a cursor.
2710 */
2711enum CXLinkageKind {
2712 /** \brief This value indicates that no linkage information is available
2713 * for a provided CXCursor. */
2714 CXLinkage_Invalid,
2715 /**
2716 * \brief This is the linkage for variables, parameters, and so on that
2717 * have automatic storage. This covers normal (non-extern) local variables.
2718 */
2719 CXLinkage_NoLinkage,
2720 /** \brief This is the linkage for static variables and static functions. */
2721 CXLinkage_Internal,
2722 /** \brief This is the linkage for entities with external linkage that live
2723 * in C++ anonymous namespaces.*/
2724 CXLinkage_UniqueExternal,
2725 /** \brief This is the linkage for entities with true, external linkage. */
2726 CXLinkage_External
2727};
2728
2729/**
2730 * \brief Determine the linkage of the entity referred to by a given cursor.
2731 */
2732CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2733
2734enum CXVisibilityKind {
2735 /** \brief This value indicates that no visibility information is available
2736 * for a provided CXCursor. */
2737 CXVisibility_Invalid,
2738
2739 /** \brief Symbol not seen by the linker. */
2740 CXVisibility_Hidden,
2741 /** \brief Symbol seen by the linker but resolves to a symbol inside this object. */
2742 CXVisibility_Protected,
2743 /** \brief Symbol seen by the linker and acts like a normal symbol. */
2744 CXVisibility_Default
2745};
2746
2747/**
2748 * \brief Describe the visibility of the entity referred to by a cursor.
2749 *
2750 * This returns the default visibility if not explicitly specified by
2751 * a visibility attribute. The default visibility may be changed by
2752 * commandline arguments.
2753 *
2754 * \param cursor The cursor to query.
2755 *
2756 * \returns The visibility of the cursor.
2757 */
2758CINDEX_LINKAGE enum CXVisibilityKind clang_getCursorVisibility(CXCursor cursor);
2759
2760/**
2761 * \brief Determine the availability of the entity that this cursor refers to,
2762 * taking the current target platform into account.
2763 *
2764 * \param cursor The cursor to query.
2765 *
2766 * \returns The availability of the cursor.
2767 */
2768CINDEX_LINKAGE enum CXAvailabilityKind
2769clang_getCursorAvailability(CXCursor cursor);
2770
2771/**
2772 * Describes the availability of a given entity on a particular platform, e.g.,
2773 * a particular class might only be available on Mac OS 10.7 or newer.
2774 */
2775typedef struct CXPlatformAvailability {
2776 /**
2777 * \brief A string that describes the platform for which this structure
2778 * provides availability information.
2779 *
2780 * Possible values are "ios" or "macos".
2781 */
2782 CXString Platform;
2783 /**
2784 * \brief The version number in which this entity was introduced.
2785 */
2786 CXVersion Introduced;
2787 /**
2788 * \brief The version number in which this entity was deprecated (but is
2789 * still available).
2790 */
2791 CXVersion Deprecated;
2792 /**
2793 * \brief The version number in which this entity was obsoleted, and therefore
2794 * is no longer available.
2795 */
2796 CXVersion Obsoleted;
2797 /**
2798 * \brief Whether the entity is unconditionally unavailable on this platform.
2799 */
2800 int Unavailable;
2801 /**
2802 * \brief An optional message to provide to a user of this API, e.g., to
2803 * suggest replacement APIs.
2804 */
2805 CXString Message;
2806} CXPlatformAvailability;
2807
2808/**
2809 * \brief Determine the availability of the entity that this cursor refers to
2810 * on any platforms for which availability information is known.
2811 *
2812 * \param cursor The cursor to query.
2813 *
2814 * \param always_deprecated If non-NULL, will be set to indicate whether the
2815 * entity is deprecated on all platforms.
2816 *
2817 * \param deprecated_message If non-NULL, will be set to the message text
2818 * provided along with the unconditional deprecation of this entity. The client
2819 * is responsible for deallocating this string.
2820 *
2821 * \param always_unavailable If non-NULL, will be set to indicate whether the
2822 * entity is unavailable on all platforms.
2823 *
2824 * \param unavailable_message If non-NULL, will be set to the message text
2825 * provided along with the unconditional unavailability of this entity. The
2826 * client is responsible for deallocating this string.
2827 *
2828 * \param availability If non-NULL, an array of CXPlatformAvailability instances
2829 * that will be populated with platform availability information, up to either
2830 * the number of platforms for which availability information is available (as
2831 * returned by this function) or \c availability_size, whichever is smaller.
2832 *
2833 * \param availability_size The number of elements available in the
2834 * \c availability array.
2835 *
2836 * \returns The number of platforms (N) for which availability information is
2837 * available (which is unrelated to \c availability_size).
2838 *
2839 * Note that the client is responsible for calling
2840 * \c clang_disposeCXPlatformAvailability to free each of the
2841 * platform-availability structures returned. There are
2842 * \c min(N, availability_size) such structures.
2843 */
2844CINDEX_LINKAGE int
2845clang_getCursorPlatformAvailability(CXCursor cursor,
2846 int *always_deprecated,
2847 CXString *deprecated_message,
2848 int *always_unavailable,
2849 CXString *unavailable_message,
2850 CXPlatformAvailability *availability,
2851 int availability_size);
2852
2853/**
2854 * \brief Free the memory associated with a \c CXPlatformAvailability structure.
2855 */
2856CINDEX_LINKAGE void
2857clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability);
2858
2859/**
2860 * \brief Describe the "language" of the entity referred to by a cursor.
2861 */
2862enum CXLanguageKind {
2863 CXLanguage_Invalid = 0,
2864 CXLanguage_C,
2865 CXLanguage_ObjC,
2866 CXLanguage_CPlusPlus
2867};
2868
2869/**
2870 * \brief Determine the "language" of the entity referred to by a given cursor.
2871 */
2872CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2873
2874/**
2875 * \brief Describe the "thread-local storage (TLS) kind" of the declaration
2876 * referred to by a cursor.
2877 */
2878enum CXTLSKind {
2879 CXTLS_None = 0,
2880 CXTLS_Dynamic,
2881 CXTLS_Static
2882};
2883
2884/**
2885 * \brief Determine the "thread-local storage (TLS) kind" of the declaration
2886 * referred to by a cursor.
2887 */
2888CINDEX_LINKAGE enum CXTLSKind clang_getCursorTLSKind(CXCursor cursor);
2889
2890/**
2891 * \brief Returns the translation unit that a cursor originated from.
2892 */
2893CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2894
2895/**
2896 * \brief A fast container representing a set of CXCursors.
2897 */
2898typedef struct CXCursorSetImpl *CXCursorSet;
2899
2900/**
2901 * \brief Creates an empty CXCursorSet.
2902 */
2903CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet(void);
2904
2905/**
2906 * \brief Disposes a CXCursorSet and releases its associated memory.
2907 */
2908CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2909
2910/**
2911 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2912 *
2913 * \returns non-zero if the set contains the specified cursor.
2914*/
2915CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2916 CXCursor cursor);
2917
2918/**
2919 * \brief Inserts a CXCursor into a CXCursorSet.
2920 *
2921 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2922*/
2923CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2924 CXCursor cursor);
2925
2926/**
2927 * \brief Determine the semantic parent of the given cursor.
2928 *
2929 * The semantic parent of a cursor is the cursor that semantically contains
2930 * the given \p cursor. For many declarations, the lexical and semantic parents
2931 * are equivalent (the lexical parent is returned by
2932 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2933 * definitions are provided out-of-line. For example:
2934 *
2935 * \code
2936 * class C {
2937 * void f();
2938 * };
2939 *
2940 * void C::f() { }
2941 * \endcode
2942 *
2943 * In the out-of-line definition of \c C::f, the semantic parent is
2944 * the class \c C, of which this function is a member. The lexical parent is
2945 * the place where the declaration actually occurs in the source code; in this
2946 * case, the definition occurs in the translation unit. In general, the
2947 * lexical parent for a given entity can change without affecting the semantics
2948 * of the program, and the lexical parent of different declarations of the
2949 * same entity may be different. Changing the semantic parent of a declaration,
2950 * on the other hand, can have a major impact on semantics, and redeclarations
2951 * of a particular entity should all have the same semantic context.
2952 *
2953 * In the example above, both declarations of \c C::f have \c C as their
2954 * semantic context, while the lexical context of the first \c C::f is \c C
2955 * and the lexical context of the second \c C::f is the translation unit.
2956 *
2957 * For global declarations, the semantic parent is the translation unit.
2958 */
2959CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2960
2961/**
2962 * \brief Determine the lexical parent of the given cursor.
2963 *
2964 * The lexical parent of a cursor is the cursor in which the given \p cursor
2965 * was actually written. For many declarations, the lexical and semantic parents
2966 * are equivalent (the semantic parent is returned by
2967 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2968 * definitions are provided out-of-line. For example:
2969 *
2970 * \code
2971 * class C {
2972 * void f();
2973 * };
2974 *
2975 * void C::f() { }
2976 * \endcode
2977 *
2978 * In the out-of-line definition of \c C::f, the semantic parent is
2979 * the class \c C, of which this function is a member. The lexical parent is
2980 * the place where the declaration actually occurs in the source code; in this
2981 * case, the definition occurs in the translation unit. In general, the
2982 * lexical parent for a given entity can change without affecting the semantics
2983 * of the program, and the lexical parent of different declarations of the
2984 * same entity may be different. Changing the semantic parent of a declaration,
2985 * on the other hand, can have a major impact on semantics, and redeclarations
2986 * of a particular entity should all have the same semantic context.
2987 *
2988 * In the example above, both declarations of \c C::f have \c C as their
2989 * semantic context, while the lexical context of the first \c C::f is \c C
2990 * and the lexical context of the second \c C::f is the translation unit.
2991 *
2992 * For declarations written in the global scope, the lexical parent is
2993 * the translation unit.
2994 */
2995CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
2996
2997/**
2998 * \brief Determine the set of methods that are overridden by the given
2999 * method.
3000 *
3001 * In both Objective-C and C++, a method (aka virtual member function,
3002 * in C++) can override a virtual method in a base class. For
3003 * Objective-C, a method is said to override any method in the class's
3004 * base class, its protocols, or its categories' protocols, that has the same
3005 * selector and is of the same kind (class or instance).
3006 * If no such method exists, the search continues to the class's superclass,
3007 * its protocols, and its categories, and so on. A method from an Objective-C
3008 * implementation is considered to override the same methods as its
3009 * corresponding method in the interface.
3010 *
3011 * For C++, a virtual member function overrides any virtual member
3012 * function with the same signature that occurs in its base
3013 * classes. With multiple inheritance, a virtual member function can
3014 * override several virtual member functions coming from different
3015 * base classes.
3016 *
3017 * In all cases, this function determines the immediate overridden
3018 * method, rather than all of the overridden methods. For example, if
3019 * a method is originally declared in a class A, then overridden in B
3020 * (which in inherits from A) and also in C (which inherited from B),
3021 * then the only overridden method returned from this function when
3022 * invoked on C's method will be B's method. The client may then
3023 * invoke this function again, given the previously-found overridden
3024 * methods, to map out the complete method-override set.
3025 *
3026 * \param cursor A cursor representing an Objective-C or C++
3027 * method. This routine will compute the set of methods that this
3028 * method overrides.
3029 *
3030 * \param overridden A pointer whose pointee will be replaced with a
3031 * pointer to an array of cursors, representing the set of overridden
3032 * methods. If there are no overridden methods, the pointee will be
3033 * set to NULL. The pointee must be freed via a call to
3034 * \c clang_disposeOverriddenCursors().
3035 *
3036 * \param num_overridden A pointer to the number of overridden
3037 * functions, will be set to the number of overridden functions in the
3038 * array pointed to by \p overridden.
3039 */
3040CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
3041 CXCursor **overridden,
3042 unsigned *num_overridden);
3043
3044/**
3045 * \brief Free the set of overridden cursors returned by \c
3046 * clang_getOverriddenCursors().
3047 */
3048CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
3049
3050/**
3051 * \brief Retrieve the file that is included by the given inclusion directive
3052 * cursor.
3053 */
3054CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
3055
3056/**
3057 * @}
3058 */
3059
3060/**
3061 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
3062 *
3063 * Cursors represent a location within the Abstract Syntax Tree (AST). These
3064 * routines help map between cursors and the physical locations where the
3065 * described entities occur in the source code. The mapping is provided in
3066 * both directions, so one can map from source code to the AST and back.
3067 *
3068 * @{
3069 */
3070
3071/**
3072 * \brief Map a source location to the cursor that describes the entity at that
3073 * location in the source code.
3074 *
3075 * clang_getCursor() maps an arbitrary source location within a translation
3076 * unit down to the most specific cursor that describes the entity at that
3077 * location. For example, given an expression \c x + y, invoking
3078 * clang_getCursor() with a source location pointing to "x" will return the
3079 * cursor for "x"; similarly for "y". If the cursor points anywhere between
3080 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
3081 * will return a cursor referring to the "+" expression.
3082 *
3083 * \returns a cursor representing the entity at the given source location, or
3084 * a NULL cursor if no such entity can be found.
3085 */
3086CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
3087
3088/**
3089 * \brief Retrieve the physical location of the source constructor referenced
3090 * by the given cursor.
3091 *
3092 * The location of a declaration is typically the location of the name of that
3093 * declaration, where the name of that declaration would occur if it is
3094 * unnamed, or some keyword that introduces that particular declaration.
3095 * The location of a reference is where that reference occurs within the
3096 * source code.
3097 */
3098CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
3099
3100/**
3101 * \brief Retrieve the physical extent of the source construct referenced by
3102 * the given cursor.
3103 *
3104 * The extent of a cursor starts with the file/line/column pointing at the
3105 * first character within the source construct that the cursor refers to and
3106 * ends with the last character within that source construct. For a
3107 * declaration, the extent covers the declaration itself. For a reference,
3108 * the extent covers the location of the reference (e.g., where the referenced
3109 * entity was actually used).
3110 */
3111CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
3112
3113/**
3114 * @}
3115 */
3116
3117/**
3118 * \defgroup CINDEX_TYPES Type information for CXCursors
3119 *
3120 * @{
3121 */
3122
3123/**
3124 * \brief Describes the kind of type
3125 */
3126enum CXTypeKind {
3127 /**
3128 * \brief Represents an invalid type (e.g., where no type is available).
3129 */
3130 CXType_Invalid = 0,
3131
3132 /**
3133 * \brief A type whose specific kind is not exposed via this
3134 * interface.
3135 */
3136 CXType_Unexposed = 1,
3137
3138 /* Builtin types */
3139 CXType_Void = 2,
3140 CXType_Bool = 3,
3141 CXType_Char_U = 4,
3142 CXType_UChar = 5,
3143 CXType_Char16 = 6,
3144 CXType_Char32 = 7,
3145 CXType_UShort = 8,
3146 CXType_UInt = 9,
3147 CXType_ULong = 10,
3148 CXType_ULongLong = 11,
3149 CXType_UInt128 = 12,
3150 CXType_Char_S = 13,
3151 CXType_SChar = 14,
3152 CXType_WChar = 15,
3153 CXType_Short = 16,
3154 CXType_Int = 17,
3155 CXType_Long = 18,
3156 CXType_LongLong = 19,
3157 CXType_Int128 = 20,
3158 CXType_Float = 21,
3159 CXType_Double = 22,
3160 CXType_LongDouble = 23,
3161 CXType_NullPtr = 24,
3162 CXType_Overload = 25,
3163 CXType_Dependent = 26,
3164 CXType_ObjCId = 27,
3165 CXType_ObjCClass = 28,
3166 CXType_ObjCSel = 29,
3167 CXType_Float128 = 30,
3168 CXType_Half = 31,
3169 CXType_Float16 = 32,
3170 CXType_FirstBuiltin = CXType_Void,
3171 CXType_LastBuiltin = CXType_Float16,
3172
3173 CXType_Complex = 100,
3174 CXType_Pointer = 101,
3175 CXType_BlockPointer = 102,
3176 CXType_LValueReference = 103,
3177 CXType_RValueReference = 104,
3178 CXType_Record = 105,
3179 CXType_Enum = 106,
3180 CXType_Typedef = 107,
3181 CXType_ObjCInterface = 108,
3182 CXType_ObjCObjectPointer = 109,
3183 CXType_FunctionNoProto = 110,
3184 CXType_FunctionProto = 111,
3185 CXType_ConstantArray = 112,
3186 CXType_Vector = 113,
3187 CXType_IncompleteArray = 114,
3188 CXType_VariableArray = 115,
3189 CXType_DependentSizedArray = 116,
3190 CXType_MemberPointer = 117,
3191 CXType_Auto = 118,
3192
3193 /**
3194 * \brief Represents a type that was referred to using an elaborated type keyword.
3195 *
3196 * E.g., struct S, or via a qualified name, e.g., N::M::type, or both.
3197 */
3198 CXType_Elaborated = 119,
3199
3200 /* OpenCL PipeType. */
3201 CXType_Pipe = 120,
3202
3203 /* OpenCL builtin types. */
3204 CXType_OCLImage1dRO = 121,
3205 CXType_OCLImage1dArrayRO = 122,
3206 CXType_OCLImage1dBufferRO = 123,
3207 CXType_OCLImage2dRO = 124,
3208 CXType_OCLImage2dArrayRO = 125,
3209 CXType_OCLImage2dDepthRO = 126,
3210 CXType_OCLImage2dArrayDepthRO = 127,
3211 CXType_OCLImage2dMSAARO = 128,
3212 CXType_OCLImage2dArrayMSAARO = 129,
3213 CXType_OCLImage2dMSAADepthRO = 130,
3214 CXType_OCLImage2dArrayMSAADepthRO = 131,
3215 CXType_OCLImage3dRO = 132,
3216 CXType_OCLImage1dWO = 133,
3217 CXType_OCLImage1dArrayWO = 134,
3218 CXType_OCLImage1dBufferWO = 135,
3219 CXType_OCLImage2dWO = 136,
3220 CXType_OCLImage2dArrayWO = 137,
3221 CXType_OCLImage2dDepthWO = 138,
3222 CXType_OCLImage2dArrayDepthWO = 139,
3223 CXType_OCLImage2dMSAAWO = 140,
3224 CXType_OCLImage2dArrayMSAAWO = 141,
3225 CXType_OCLImage2dMSAADepthWO = 142,
3226 CXType_OCLImage2dArrayMSAADepthWO = 143,
3227 CXType_OCLImage3dWO = 144,
3228 CXType_OCLImage1dRW = 145,
3229 CXType_OCLImage1dArrayRW = 146,
3230 CXType_OCLImage1dBufferRW = 147,
3231 CXType_OCLImage2dRW = 148,
3232 CXType_OCLImage2dArrayRW = 149,
3233 CXType_OCLImage2dDepthRW = 150,
3234 CXType_OCLImage2dArrayDepthRW = 151,
3235 CXType_OCLImage2dMSAARW = 152,
3236 CXType_OCLImage2dArrayMSAARW = 153,
3237 CXType_OCLImage2dMSAADepthRW = 154,
3238 CXType_OCLImage2dArrayMSAADepthRW = 155,
3239 CXType_OCLImage3dRW = 156,
3240 CXType_OCLSampler = 157,
3241 CXType_OCLEvent = 158,
3242 CXType_OCLQueue = 159,
3243 CXType_OCLReserveID = 160
3244};
3245
3246/**
3247 * \brief Describes the calling convention of a function type
3248 */
3249enum CXCallingConv {
3250 CXCallingConv_Default = 0,
3251 CXCallingConv_C = 1,
3252 CXCallingConv_X86StdCall = 2,
3253 CXCallingConv_X86FastCall = 3,
3254 CXCallingConv_X86ThisCall = 4,
3255 CXCallingConv_X86Pascal = 5,
3256 CXCallingConv_AAPCS = 6,
3257 CXCallingConv_AAPCS_VFP = 7,
3258 CXCallingConv_X86RegCall = 8,
3259 CXCallingConv_IntelOclBicc = 9,
3260 CXCallingConv_Win64 = 10,
3261 /* Alias for compatibility with older versions of API. */
3262 CXCallingConv_X86_64Win64 = CXCallingConv_Win64,
3263 CXCallingConv_X86_64SysV = 11,
3264 CXCallingConv_X86VectorCall = 12,
3265 CXCallingConv_Swift = 13,
3266 CXCallingConv_PreserveMost = 14,
3267 CXCallingConv_PreserveAll = 15,
3268
3269 CXCallingConv_Invalid = 100,
3270 CXCallingConv_Unexposed = 200
3271};
3272
3273/**
3274 * \brief The type of an element in the abstract syntax tree.
3275 *
3276 */
3277typedef struct {
3278 enum CXTypeKind kind;
3279 void *data[2];
3280} CXType;
3281
3282/**
3283 * \brief Retrieve the type of a CXCursor (if any).
3284 */
3285CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
3286
3287/**
3288 * \brief Pretty-print the underlying type using the rules of the
3289 * language of the translation unit from which it came.
3290 *
3291 * If the type is invalid, an empty string is returned.
3292 */
3293CINDEX_LINKAGE CXString clang_getTypeSpelling(CXType CT);
3294
3295/**
3296 * \brief Retrieve the underlying type of a typedef declaration.
3297 *
3298 * If the cursor does not reference a typedef declaration, an invalid type is
3299 * returned.
3300 */
3301CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
3302
3303/**
3304 * \brief Retrieve the integer type of an enum declaration.
3305 *
3306 * If the cursor does not reference an enum declaration, an invalid type is
3307 * returned.
3308 */
3309CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
3310
3311/**
3312 * \brief Retrieve the integer value of an enum constant declaration as a signed
3313 * long long.
3314 *
3315 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
3316 * Since this is also potentially a valid constant value, the kind of the cursor
3317 * must be verified before calling this function.
3318 */
3319CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
3320
3321/**
3322 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
3323 * long long.
3324 *
3325 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
3326 * Since this is also potentially a valid constant value, the kind of the cursor
3327 * must be verified before calling this function.
3328 */
3329CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
3330
3331/**
3332 * \brief Retrieve the bit width of a bit field declaration as an integer.
3333 *
3334 * If a cursor that is not a bit field declaration is passed in, -1 is returned.
3335 */
3336CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
3337
3338/**
3339 * \brief Retrieve the number of non-variadic arguments associated with a given
3340 * cursor.
3341 *
3342 * The number of arguments can be determined for calls as well as for
3343 * declarations of functions or methods. For other cursors -1 is returned.
3344 */
3345CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
3346
3347/**
3348 * \brief Retrieve the argument cursor of a function or method.
3349 *
3350 * The argument cursor can be determined for calls as well as for declarations
3351 * of functions or methods. For other cursors and for invalid indices, an
3352 * invalid cursor is returned.
3353 */
3354CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
3355
3356/**
3357 * \brief Describes the kind of a template argument.
3358 *
3359 * See the definition of llvm::clang::TemplateArgument::ArgKind for full
3360 * element descriptions.
3361 */
3362enum CXTemplateArgumentKind {
3363 CXTemplateArgumentKind_Null,
3364 CXTemplateArgumentKind_Type,
3365 CXTemplateArgumentKind_Declaration,
3366 CXTemplateArgumentKind_NullPtr,
3367 CXTemplateArgumentKind_Integral,
3368 CXTemplateArgumentKind_Template,
3369 CXTemplateArgumentKind_TemplateExpansion,
3370 CXTemplateArgumentKind_Expression,
3371 CXTemplateArgumentKind_Pack,
3372 /* Indicates an error case, preventing the kind from being deduced. */
3373 CXTemplateArgumentKind_Invalid
3374};
3375
3376/**
3377 *\brief Returns the number of template args of a function decl representing a
3378 * template specialization.
3379 *
3380 * If the argument cursor cannot be converted into a template function
3381 * declaration, -1 is returned.
3382 *
3383 * For example, for the following declaration and specialization:
3384 * template <typename T, int kInt, bool kBool>
3385 * void foo() { ... }
3386 *
3387 * template <>
3388 * void foo<float, -7, true>();
3389 *
3390 * The value 3 would be returned from this call.
3391 */
3392CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C);
3393
3394/**
3395 * \brief Retrieve the kind of the I'th template argument of the CXCursor C.
3396 *
3397 * If the argument CXCursor does not represent a FunctionDecl, an invalid
3398 * template argument kind is returned.
3399 *
3400 * For example, for the following declaration and specialization:
3401 * template <typename T, int kInt, bool kBool>
3402 * void foo() { ... }
3403 *
3404 * template <>
3405 * void foo<float, -7, true>();
3406 *
3407 * For I = 0, 1, and 2, Type, Integral, and Integral will be returned,
3408 * respectively.
3409 */
3410CINDEX_LINKAGE enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(
3411 CXCursor C, unsigned I);
3412
3413/**
3414 * \brief Retrieve a CXType representing the type of a TemplateArgument of a
3415 * function decl representing a template specialization.
3416 *
3417 * If the argument CXCursor does not represent a FunctionDecl whose I'th
3418 * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
3419 * is returned.
3420 *
3421 * For example, for the following declaration and specialization:
3422 * template <typename T, int kInt, bool kBool>
3423 * void foo() { ... }
3424 *
3425 * template <>
3426 * void foo<float, -7, true>();
3427 *
3428 * If called with I = 0, "float", will be returned.
3429 * Invalid types will be returned for I == 1 or 2.
3430 */
3431CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentType(CXCursor C,
3432 unsigned I);
3433
3434/**
3435 * \brief Retrieve the value of an Integral TemplateArgument (of a function
3436 * decl representing a template specialization) as a signed long long.
3437 *
3438 * It is undefined to call this function on a CXCursor that does not represent a
3439 * FunctionDecl or whose I'th template argument is not an integral value.
3440 *
3441 * For example, for the following declaration and specialization:
3442 * template <typename T, int kInt, bool kBool>
3443 * void foo() { ... }
3444 *
3445 * template <>
3446 * void foo<float, -7, true>();
3447 *
3448 * If called with I = 1 or 2, -7 or true will be returned, respectively.
3449 * For I == 0, this function's behavior is undefined.
3450 */
3451CINDEX_LINKAGE long long clang_Cursor_getTemplateArgumentValue(CXCursor C,
3452 unsigned I);
3453
3454/**
3455 * \brief Retrieve the value of an Integral TemplateArgument (of a function
3456 * decl representing a template specialization) as an unsigned long long.
3457 *
3458 * It is undefined to call this function on a CXCursor that does not represent a
3459 * FunctionDecl or whose I'th template argument is not an integral value.
3460 *
3461 * For example, for the following declaration and specialization:
3462 * template <typename T, int kInt, bool kBool>
3463 * void foo() { ... }
3464 *
3465 * template <>
3466 * void foo<float, 2147483649, true>();
3467 *
3468 * If called with I = 1 or 2, 2147483649 or true will be returned, respectively.
3469 * For I == 0, this function's behavior is undefined.
3470 */
3471CINDEX_LINKAGE unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(
3472 CXCursor C, unsigned I);
3473
3474/**
3475 * \brief Determine whether two CXTypes represent the same type.
3476 *
3477 * \returns non-zero if the CXTypes represent the same type and
3478 * zero otherwise.
3479 */
3480CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
3481
3482/**
3483 * \brief Return the canonical type for a CXType.
3484 *
3485 * Clang's type system explicitly models typedefs and all the ways
3486 * a specific type can be represented. The canonical type is the underlying
3487 * type with all the "sugar" removed. For example, if 'T' is a typedef
3488 * for 'int', the canonical type for 'T' would be 'int'.
3489 */
3490CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
3491
3492/**
3493 * \brief Determine whether a CXType has the "const" qualifier set,
3494 * without looking through typedefs that may have added "const" at a
3495 * different level.
3496 */
3497CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
3498
3499/**
3500 * \brief Determine whether a CXCursor that is a macro, is
3501 * function like.
3502 */
3503CINDEX_LINKAGE unsigned clang_Cursor_isMacroFunctionLike(CXCursor C);
3504
3505/**
3506 * \brief Determine whether a CXCursor that is a macro, is a
3507 * builtin one.
3508 */
3509CINDEX_LINKAGE unsigned clang_Cursor_isMacroBuiltin(CXCursor C);
3510
3511/**
3512 * \brief Determine whether a CXCursor that is a function declaration, is an
3513 * inline declaration.
3514 */
3515CINDEX_LINKAGE unsigned clang_Cursor_isFunctionInlined(CXCursor C);
3516
3517/**
3518 * \brief Determine whether a CXType has the "volatile" qualifier set,
3519 * without looking through typedefs that may have added "volatile" at
3520 * a different level.
3521 */
3522CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
3523
3524/**
3525 * \brief Determine whether a CXType has the "restrict" qualifier set,
3526 * without looking through typedefs that may have added "restrict" at a
3527 * different level.
3528 */
3529CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
3530
3531/**
3532 * \brief Returns the address space of the given type.
3533 */
3534CINDEX_LINKAGE unsigned clang_getAddressSpace(CXType T);
3535
3536/**
3537 * \brief Returns the typedef name of the given type.
3538 */
3539CINDEX_LINKAGE CXString clang_getTypedefName(CXType CT);
3540
3541/**
3542 * \brief For pointer types, returns the type of the pointee.
3543 */
3544CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
3545
3546/**
3547 * \brief Return the cursor for the declaration of the given type.
3548 */
3549CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
3550
3551/**
3552 * Returns the Objective-C type encoding for the specified declaration.
3553 */
3554CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
3555
3556/**
3557 * Returns the Objective-C type encoding for the specified CXType.
3558 */
3559CINDEX_LINKAGE CXString clang_Type_getObjCEncoding(CXType type);
3560
3561/**
3562 * \brief Retrieve the spelling of a given CXTypeKind.
3563 */
3564CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
3565
3566/**
3567 * \brief Retrieve the calling convention associated with a function type.
3568 *
3569 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
3570 */
3571CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
3572
3573/**
3574 * \brief Retrieve the return type associated with a function type.
3575 *
3576 * If a non-function type is passed in, an invalid type is returned.
3577 */
3578CINDEX_LINKAGE CXType clang_getResultType(CXType T);
3579
3580/**
3581 * \brief Retrieve the exception specification type associated with a function type.
3582 *
3583 * If a non-function type is passed in, an error code of -1 is returned.
3584 */
3585CINDEX_LINKAGE int clang_getExceptionSpecificationType(CXType T);
3586
3587/**
3588 * \brief Retrieve the number of non-variadic parameters associated with a
3589 * function type.
3590 *
3591 * If a non-function type is passed in, -1 is returned.
3592 */
3593CINDEX_LINKAGE int clang_getNumArgTypes(CXType T);
3594
3595/**
3596 * \brief Retrieve the type of a parameter of a function type.
3597 *
3598 * If a non-function type is passed in or the function does not have enough
3599 * parameters, an invalid type is returned.
3600 */
3601CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
3602
3603/**
3604 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
3605 */
3606CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
3607
3608/**
3609 * \brief Retrieve the return type associated with a given cursor.
3610 *
3611 * This only returns a valid type if the cursor refers to a function or method.
3612 */
3613CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
3614
3615/**
3616 * \brief Retrieve the exception specification type associated with a given cursor.
3617 *
3618 * This only returns a valid result if the cursor refers to a function or method.
3619 */
3620CINDEX_LINKAGE int clang_getCursorExceptionSpecificationType(CXCursor C);
3621
3622/**
3623 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
3624 * otherwise.
3625 */
3626CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
3627
3628/**
3629 * \brief Return the element type of an array, complex, or vector type.
3630 *
3631 * If a type is passed in that is not an array, complex, or vector type,
3632 * an invalid type is returned.
3633 */
3634CINDEX_LINKAGE CXType clang_getElementType(CXType T);
3635
3636/**
3637 * \brief Return the number of elements of an array or vector type.
3638 *
3639 * If a type is passed in that is not an array or vector type,
3640 * -1 is returned.
3641 */
3642CINDEX_LINKAGE long long clang_getNumElements(CXType T);
3643
3644/**
3645 * \brief Return the element type of an array type.
3646 *
3647 * If a non-array type is passed in, an invalid type is returned.
3648 */
3649CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
3650
3651/**
3652 * \brief Return the array size of a constant array.
3653 *
3654 * If a non-array type is passed in, -1 is returned.
3655 */
3656CINDEX_LINKAGE long long clang_getArraySize(CXType T);
3657
3658/**
3659 * \brief Retrieve the type named by the qualified-id.
3660 *
3661 * If a non-elaborated type is passed in, an invalid type is returned.
3662 */
3663CINDEX_LINKAGE CXType clang_Type_getNamedType(CXType T);
3664
3665/**
3666 * \brief Determine if a typedef is 'transparent' tag.
3667 *
3668 * A typedef is considered 'transparent' if it shares a name and spelling
3669 * location with its underlying tag type, as is the case with the NS_ENUM macro.
3670 *
3671 * \returns non-zero if transparent and zero otherwise.
3672 */
3673CINDEX_LINKAGE unsigned clang_Type_isTransparentTagTypedef(CXType T);
3674
3675/**
3676 * \brief List the possible error codes for \c clang_Type_getSizeOf,
3677 * \c clang_Type_getAlignOf, \c clang_Type_getOffsetOf and
3678 * \c clang_Cursor_getOffsetOf.
3679 *
3680 * A value of this enumeration type can be returned if the target type is not
3681 * a valid argument to sizeof, alignof or offsetof.
3682 */
3683enum CXTypeLayoutError {
3684 /**
3685 * \brief Type is of kind CXType_Invalid.
3686 */
3687 CXTypeLayoutError_Invalid = -1,
3688 /**
3689 * \brief The type is an incomplete Type.
3690 */
3691 CXTypeLayoutError_Incomplete = -2,
3692 /**
3693 * \brief The type is a dependent Type.
3694 */
3695 CXTypeLayoutError_Dependent = -3,
3696 /**
3697 * \brief The type is not a constant size type.
3698 */
3699 CXTypeLayoutError_NotConstantSize = -4,
3700 /**
3701 * \brief The Field name is not valid for this record.
3702 */
3703 CXTypeLayoutError_InvalidFieldName = -5
3704};
3705
3706/**
3707 * \brief Return the alignment of a type in bytes as per C++[expr.alignof]
3708 * standard.
3709 *
3710 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3711 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3712 * is returned.
3713 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3714 * returned.
3715 * If the type declaration is not a constant size type,
3716 * CXTypeLayoutError_NotConstantSize is returned.
3717 */
3718CINDEX_LINKAGE long long clang_Type_getAlignOf(CXType T);
3719
3720/**
3721 * \brief Return the class type of an member pointer type.
3722 *
3723 * If a non-member-pointer type is passed in, an invalid type is returned.
3724 */
3725CINDEX_LINKAGE CXType clang_Type_getClassType(CXType T);
3726
3727/**
3728 * \brief Return the size of a type in bytes as per C++[expr.sizeof] standard.
3729 *
3730 * If the type declaration is invalid, CXTypeLayoutError_Invalid is returned.
3731 * If the type declaration is an incomplete type, CXTypeLayoutError_Incomplete
3732 * is returned.
3733 * If the type declaration is a dependent type, CXTypeLayoutError_Dependent is
3734 * returned.
3735 */
3736CINDEX_LINKAGE long long clang_Type_getSizeOf(CXType T);
3737
3738/**
3739 * \brief Return the offset of a field named S in a record of type T in bits
3740 * as it would be returned by __offsetof__ as per C++11[18.2p4]
3741 *
3742 * If the cursor is not a record field declaration, CXTypeLayoutError_Invalid
3743 * is returned.
3744 * If the field's type declaration is an incomplete type,
3745 * CXTypeLayoutError_Incomplete is returned.
3746 * If the field's type declaration is a dependent type,
3747 * CXTypeLayoutError_Dependent is returned.
3748 * If the field's name S is not found,
3749 * CXTypeLayoutError_InvalidFieldName is returned.
3750 */
3751CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
3752
3753/**
3754 * \brief Return the offset of the field represented by the Cursor.
3755 *
3756 * If the cursor is not a field declaration, -1 is returned.
3757 * If the cursor semantic parent is not a record field declaration,
3758 * CXTypeLayoutError_Invalid is returned.
3759 * If the field's type declaration is an incomplete type,
3760 * CXTypeLayoutError_Incomplete is returned.
3761 * If the field's type declaration is a dependent type,
3762 * CXTypeLayoutError_Dependent is returned.
3763 * If the field's name S is not found,
3764 * CXTypeLayoutError_InvalidFieldName is returned.
3765 */
3766CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
3767
3768/**
3769 * \brief Determine whether the given cursor represents an anonymous record
3770 * declaration.
3771 */
3772CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
3773
3774enum CXRefQualifierKind {
3775 /** \brief No ref-qualifier was provided. */
3776 CXRefQualifier_None = 0,
3777 /** \brief An lvalue ref-qualifier was provided (\c &). */
3778 CXRefQualifier_LValue,
3779 /** \brief An rvalue ref-qualifier was provided (\c &&). */
3780 CXRefQualifier_RValue
3781};
3782
3783/**
3784 * \brief Returns the number of template arguments for given template
3785 * specialization, or -1 if type \c T is not a template specialization.
3786 */
3787CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T);
3788
3789/**
3790 * \brief Returns the type template argument of a template class specialization
3791 * at given index.
3792 *
3793 * This function only returns template type arguments and does not handle
3794 * template template arguments or variadic packs.
3795 */
3796CINDEX_LINKAGE CXType clang_Type_getTemplateArgumentAsType(CXType T, unsigned i);
3797
3798/**
3799 * \brief Retrieve the ref-qualifier kind of a function or method.
3800 *
3801 * The ref-qualifier is returned for C++ functions or methods. For other types
3802 * or non-C++ declarations, CXRefQualifier_None is returned.
3803 */
3804CINDEX_LINKAGE enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T);
3805
3806/**
3807 * \brief Returns non-zero if the cursor specifies a Record member that is a
3808 * bitfield.
3809 */
3810CINDEX_LINKAGE unsigned clang_Cursor_isBitField(CXCursor C);
3811
3812/**
3813 * \brief Returns 1 if the base class specified by the cursor with kind
3814 * CX_CXXBaseSpecifier is virtual.
3815 */
3816CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
3817
3818/**
3819 * \brief Represents the C++ access control level to a base class for a
3820 * cursor with kind CX_CXXBaseSpecifier.
3821 */
3822enum CX_CXXAccessSpecifier {
3823 CX_CXXInvalidAccessSpecifier,
3824 CX_CXXPublic,
3825 CX_CXXProtected,
3826 CX_CXXPrivate
3827};
3828
3829/**
3830 * \brief Returns the access control level for the referenced object.
3831 *
3832 * If the cursor refers to a C++ declaration, its access control level within its
3833 * parent scope is returned. Otherwise, if the cursor refers to a base specifier or
3834 * access specifier, the specifier itself is returned.
3835 */
3836CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
3837
3838/**
3839 * \brief Represents the storage classes as declared in the source. CX_SC_Invalid
3840 * was added for the case that the passed cursor in not a declaration.
3841 */
3842enum CX_StorageClass {
3843 CX_SC_Invalid,
3844 CX_SC_None,
3845 CX_SC_Extern,
3846 CX_SC_Static,
3847 CX_SC_PrivateExtern,
3848 CX_SC_OpenCLWorkGroupLocal,
3849 CX_SC_Auto,
3850 CX_SC_Register
3851};
3852
3853/**
3854 * \brief Returns the storage class for a function or variable declaration.
3855 *
3856 * If the passed in Cursor is not a function or variable declaration,
3857 * CX_SC_Invalid is returned else the storage class.
3858 */
3859CINDEX_LINKAGE enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor);
3860
3861/**
3862 * \brief Determine the number of overloaded declarations referenced by a
3863 * \c CXCursor_OverloadedDeclRef cursor.
3864 *
3865 * \param cursor The cursor whose overloaded declarations are being queried.
3866 *
3867 * \returns The number of overloaded declarations referenced by \c cursor. If it
3868 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
3869 */
3870CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
3871
3872/**
3873 * \brief Retrieve a cursor for one of the overloaded declarations referenced
3874 * by a \c CXCursor_OverloadedDeclRef cursor.
3875 *
3876 * \param cursor The cursor whose overloaded declarations are being queried.
3877 *
3878 * \param index The zero-based index into the set of overloaded declarations in
3879 * the cursor.
3880 *
3881 * \returns A cursor representing the declaration referenced by the given
3882 * \c cursor at the specified \c index. If the cursor does not have an
3883 * associated set of overloaded declarations, or if the index is out of bounds,
3884 * returns \c clang_getNullCursor();
3885 */
3886CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
3887 unsigned index);
3888
3889/**
3890 * @}
3891 */
3892
3893/**
3894 * \defgroup CINDEX_ATTRIBUTES Information for attributes
3895 *
3896 * @{
3897 */
3898
3899/**
3900 * \brief For cursors representing an iboutletcollection attribute,
3901 * this function returns the collection element type.
3902 *
3903 */
3904CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
3905
3906/**
3907 * @}
3908 */
3909
3910/**
3911 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
3912 *
3913 * These routines provide the ability to traverse the abstract syntax tree
3914 * using cursors.
3915 *
3916 * @{
3917 */
3918
3919/**
3920 * \brief Describes how the traversal of the children of a particular
3921 * cursor should proceed after visiting a particular child cursor.
3922 *
3923 * A value of this enumeration type should be returned by each
3924 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
3925 */
3926enum CXChildVisitResult {
3927 /**
3928 * \brief Terminates the cursor traversal.
3929 */
3930 CXChildVisit_Break,
3931 /**
3932 * \brief Continues the cursor traversal with the next sibling of
3933 * the cursor just visited, without visiting its children.
3934 */
3935 CXChildVisit_Continue,
3936 /**
3937 * \brief Recursively traverse the children of this cursor, using
3938 * the same visitor and client data.
3939 */
3940 CXChildVisit_Recurse
3941};
3942
3943/**
3944 * \brief Visitor invoked for each cursor found by a traversal.
3945 *
3946 * This visitor function will be invoked for each cursor found by
3947 * clang_visitCursorChildren(). Its first argument is the cursor being
3948 * visited, its second argument is the parent visitor for that cursor,
3949 * and its third argument is the client data provided to
3950 * clang_visitCursorChildren().
3951 *
3952 * The visitor should return one of the \c CXChildVisitResult values
3953 * to direct clang_visitCursorChildren().
3954 */
3955typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
3956 CXCursor parent,
3957 CXClientData client_data);
3958
3959/**
3960 * \brief Visit the children of a particular cursor.
3961 *
3962 * This function visits all the direct children of the given cursor,
3963 * invoking the given \p visitor function with the cursors of each
3964 * visited child. The traversal may be recursive, if the visitor returns
3965 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
3966 * the visitor returns \c CXChildVisit_Break.
3967 *
3968 * \param parent the cursor whose child may be visited. All kinds of
3969 * cursors can be visited, including invalid cursors (which, by
3970 * definition, have no children).
3971 *
3972 * \param visitor the visitor function that will be invoked for each
3973 * child of \p parent.
3974 *
3975 * \param client_data pointer data supplied by the client, which will
3976 * be passed to the visitor each time it is invoked.
3977 *
3978 * \returns a non-zero value if the traversal was terminated
3979 * prematurely by the visitor returning \c CXChildVisit_Break.
3980 */
3981CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
3982 CXCursorVisitor visitor,
3983 CXClientData client_data);
3984#ifdef __has_feature
3985# if __has_feature(blocks)
3986/**
3987 * \brief Visitor invoked for each cursor found by a traversal.
3988 *
3989 * This visitor block will be invoked for each cursor found by
3990 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
3991 * visited, its second argument is the parent visitor for that cursor.
3992 *
3993 * The visitor should return one of the \c CXChildVisitResult values
3994 * to direct clang_visitChildrenWithBlock().
3995 */
3996typedef enum CXChildVisitResult
3997 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
3998
3999/**
4000 * Visits the children of a cursor using the specified block. Behaves
4001 * identically to clang_visitChildren() in all other respects.
4002 */
4003CINDEX_LINKAGE unsigned clang_visitChildrenWithBlock(CXCursor parent,
4004 CXCursorVisitorBlock block);
4005# endif
4006#endif
4007
4008/**
4009 * @}
4010 */
4011
4012/**
4013 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
4014 *
4015 * These routines provide the ability to determine references within and
4016 * across translation units, by providing the names of the entities referenced
4017 * by cursors, follow reference cursors to the declarations they reference,
4018 * and associate declarations with their definitions.
4019 *
4020 * @{
4021 */
4022
4023/**
4024 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
4025 * by the given cursor.
4026 *
4027 * A Unified Symbol Resolution (USR) is a string that identifies a particular
4028 * entity (function, class, variable, etc.) within a program. USRs can be
4029 * compared across translation units to determine, e.g., when references in
4030 * one translation refer to an entity defined in another translation unit.
4031 */
4032CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
4033
4034/**
4035 * \brief Construct a USR for a specified Objective-C class.
4036 */
4037CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
4038
4039/**
4040 * \brief Construct a USR for a specified Objective-C category.
4041 */
4042CINDEX_LINKAGE CXString
4043 clang_constructUSR_ObjCCategory(const char *class_name,
4044 const char *category_name);
4045
4046/**
4047 * \brief Construct a USR for a specified Objective-C protocol.
4048 */
4049CINDEX_LINKAGE CXString
4050 clang_constructUSR_ObjCProtocol(const char *protocol_name);
4051
4052/**
4053 * \brief Construct a USR for a specified Objective-C instance variable and
4054 * the USR for its containing class.
4055 */
4056CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
4057 CXString classUSR);
4058
4059/**
4060 * \brief Construct a USR for a specified Objective-C method and
4061 * the USR for its containing class.
4062 */
4063CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
4064 unsigned isInstanceMethod,
4065 CXString classUSR);
4066
4067/**
4068 * \brief Construct a USR for a specified Objective-C property and the USR
4069 * for its containing class.
4070 */
4071CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
4072 CXString classUSR);
4073
4074/**
4075 * \brief Retrieve a name for the entity referenced by this cursor.
4076 */
4077CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
4078
4079/**
4080 * \brief Retrieve a range for a piece that forms the cursors spelling name.
4081 * Most of the times there is only one range for the complete spelling but for
4082 * Objective-C methods and Objective-C message expressions, there are multiple
4083 * pieces for each selector identifier.
4084 *
4085 * \param pieceIndex the index of the spelling name piece. If this is greater
4086 * than the actual number of pieces, it will return a NULL (invalid) range.
4087 *
4088 * \param options Reserved.
4089 */
4090CINDEX_LINKAGE CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor,
4091 unsigned pieceIndex,
4092 unsigned options);
4093
4094/**
4095 * \brief Opaque pointer representing a policy that controls pretty printing
4096 * for \c clang_getCursorPrettyPrinted.
4097 */
4098typedef void *CXPrintingPolicy;
4099
4100/**
4101 * \brief Properties for the printing policy.
4102 *
4103 * See \c clang::PrintingPolicy for more information.
4104 */
4105enum CXPrintingPolicyProperty {
4106 CXPrintingPolicy_Indentation,
4107 CXPrintingPolicy_SuppressSpecifiers,
4108 CXPrintingPolicy_SuppressTagKeyword,
4109 CXPrintingPolicy_IncludeTagDefinition,
4110 CXPrintingPolicy_SuppressScope,
4111 CXPrintingPolicy_SuppressUnwrittenScope,
4112 CXPrintingPolicy_SuppressInitializers,
4113 CXPrintingPolicy_ConstantArraySizeAsWritten,
4114 CXPrintingPolicy_AnonymousTagLocations,
4115 CXPrintingPolicy_SuppressStrongLifetime,
4116 CXPrintingPolicy_SuppressLifetimeQualifiers,
4117 CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors,
4118 CXPrintingPolicy_Bool,
4119 CXPrintingPolicy_Restrict,
4120 CXPrintingPolicy_Alignof,
4121 CXPrintingPolicy_UnderscoreAlignof,
4122 CXPrintingPolicy_UseVoidForZeroParams,
4123 CXPrintingPolicy_TerseOutput,
4124 CXPrintingPolicy_PolishForDeclaration,
4125 CXPrintingPolicy_Half,
4126 CXPrintingPolicy_MSWChar,
4127 CXPrintingPolicy_IncludeNewlines,
4128 CXPrintingPolicy_MSVCFormatting,
4129 CXPrintingPolicy_ConstantsAsWritten,
4130 CXPrintingPolicy_SuppressImplicitBase,
4131 CXPrintingPolicy_FullyQualifiedName,
4132
4133 CXPrintingPolicy_LastProperty = CXPrintingPolicy_FullyQualifiedName
4134};
4135
4136/**
4137 * \brief Get a property value for the given printing policy.
4138 */
4139CINDEX_LINKAGE unsigned
4140clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy,
4141 enum CXPrintingPolicyProperty Property);
4142
4143/**
4144 * \brief Set a property value for the given printing policy.
4145 */
4146CINDEX_LINKAGE void clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy,
4147 enum CXPrintingPolicyProperty Property,
4148 unsigned Value);
4149
4150/**
4151 * \brief Retrieve the default policy for the cursor.
4152 *
4153 * The policy should be released after use with \c
4154 * clang_PrintingPolicy_dispose.
4155 */
4156CINDEX_LINKAGE CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor);
4157
4158/**
4159 * \brief Release a printing policy.
4160 */
4161CINDEX_LINKAGE void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);
4162
4163/**
4164 * \brief Pretty print declarations.
4165 *
4166 * \param Cursor The cursor representing a declaration.
4167 *
4168 * \param Policy The policy to control the entities being printed. If
4169 * NULL, a default policy is used.
4170 *
4171 * \returns The pretty printed declaration or the empty string for
4172 * other cursors.
4173 */
4174CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor,
4175 CXPrintingPolicy Policy);
4176
4177/**
4178 * \brief Retrieve the display name for the entity referenced by this cursor.
4179 *
4180 * The display name contains extra information that helps identify the cursor,
4181 * such as the parameters of a function or template or the arguments of a
4182 * class template specialization.
4183 */
4184CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
4185
4186/** \brief For a cursor that is a reference, retrieve a cursor representing the
4187 * entity that it references.
4188 *
4189 * Reference cursors refer to other entities in the AST. For example, an
4190 * Objective-C superclass reference cursor refers to an Objective-C class.
4191 * This function produces the cursor for the Objective-C class from the
4192 * cursor for the superclass reference. If the input cursor is a declaration or
4193 * definition, it returns that declaration or definition unchanged.
4194 * Otherwise, returns the NULL cursor.
4195 */
4196CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
4197
4198/**
4199 * \brief For a cursor that is either a reference to or a declaration
4200 * of some entity, retrieve a cursor that describes the definition of
4201 * that entity.
4202 *
4203 * Some entities can be declared multiple times within a translation
4204 * unit, but only one of those declarations can also be a
4205 * definition. For example, given:
4206 *
4207 * \code
4208 * int f(int, int);
4209 * int g(int x, int y) { return f(x, y); }
4210 * int f(int a, int b) { return a + b; }
4211 * int f(int, int);
4212 * \endcode
4213 *
4214 * there are three declarations of the function "f", but only the
4215 * second one is a definition. The clang_getCursorDefinition()
4216 * function will take any cursor pointing to a declaration of "f"
4217 * (the first or fourth lines of the example) or a cursor referenced
4218 * that uses "f" (the call to "f' inside "g") and will return a
4219 * declaration cursor pointing to the definition (the second "f"
4220 * declaration).
4221 *
4222 * If given a cursor for which there is no corresponding definition,
4223 * e.g., because there is no definition of that entity within this
4224 * translation unit, returns a NULL cursor.
4225 */
4226CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
4227
4228/**
4229 * \brief Determine whether the declaration pointed to by this cursor
4230 * is also a definition of that entity.
4231 */
4232CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
4233
4234/**
4235 * \brief Retrieve the canonical cursor corresponding to the given cursor.
4236 *
4237 * In the C family of languages, many kinds of entities can be declared several
4238 * times within a single translation unit. For example, a structure type can
4239 * be forward-declared (possibly multiple times) and later defined:
4240 *
4241 * \code
4242 * struct X;
4243 * struct X;
4244 * struct X {
4245 * int member;
4246 * };
4247 * \endcode
4248 *
4249 * The declarations and the definition of \c X are represented by three
4250 * different cursors, all of which are declarations of the same underlying
4251 * entity. One of these cursor is considered the "canonical" cursor, which
4252 * is effectively the representative for the underlying entity. One can
4253 * determine if two cursors are declarations of the same underlying entity by
4254 * comparing their canonical cursors.
4255 *
4256 * \returns The canonical cursor for the entity referred to by the given cursor.
4257 */
4258CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
4259
4260/**
4261 * \brief If the cursor points to a selector identifier in an Objective-C
4262 * method or message expression, this returns the selector index.
4263 *
4264 * After getting a cursor with #clang_getCursor, this can be called to
4265 * determine if the location points to a selector identifier.
4266 *
4267 * \returns The selector index if the cursor is an Objective-C method or message
4268 * expression and the cursor is pointing to a selector identifier, or -1
4269 * otherwise.
4270 */
4271CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
4272
4273/**
4274 * \brief Given a cursor pointing to a C++ method call or an Objective-C
4275 * message, returns non-zero if the method/message is "dynamic", meaning:
4276 *
4277 * For a C++ method: the call is virtual.
4278 * For an Objective-C message: the receiver is an object instance, not 'super'
4279 * or a specific class.
4280 *
4281 * If the method/message is "static" or the cursor does not point to a
4282 * method/message, it will return zero.
4283 */
4284CINDEX_LINKAGE int clang_Cursor_isDynamicCall(CXCursor C);
4285
4286/**
4287 * \brief Given a cursor pointing to an Objective-C message or property
4288 * reference, or C++ method call, returns the CXType of the receiver.
4289 */
4290CINDEX_LINKAGE CXType clang_Cursor_getReceiverType(CXCursor C);
4291
4292/**
4293 * \brief Property attributes for a \c CXCursor_ObjCPropertyDecl.
4294 */
4295typedef enum {
4296 CXObjCPropertyAttr_noattr = 0x00,
4297 CXObjCPropertyAttr_readonly = 0x01,
4298 CXObjCPropertyAttr_getter = 0x02,
4299 CXObjCPropertyAttr_assign = 0x04,
4300 CXObjCPropertyAttr_readwrite = 0x08,
4301 CXObjCPropertyAttr_retain = 0x10,
4302 CXObjCPropertyAttr_copy = 0x20,
4303 CXObjCPropertyAttr_nonatomic = 0x40,
4304 CXObjCPropertyAttr_setter = 0x80,
4305 CXObjCPropertyAttr_atomic = 0x100,
4306 CXObjCPropertyAttr_weak = 0x200,
4307 CXObjCPropertyAttr_strong = 0x400,
4308 CXObjCPropertyAttr_unsafe_unretained = 0x800,
4309 CXObjCPropertyAttr_class = 0x1000
4310} CXObjCPropertyAttrKind;
4311
4312/**
4313 * \brief Given a cursor that represents a property declaration, return the
4314 * associated property attributes. The bits are formed from
4315 * \c CXObjCPropertyAttrKind.
4316 *
4317 * \param reserved Reserved for future use, pass 0.
4318 */
4319CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
4320 unsigned reserved);
4321
4322/**
4323 * \brief 'Qualifiers' written next to the return and parameter types in
4324 * Objective-C method declarations.
4325 */
4326typedef enum {
4327 CXObjCDeclQualifier_None = 0x0,
4328 CXObjCDeclQualifier_In = 0x1,
4329 CXObjCDeclQualifier_Inout = 0x2,
4330 CXObjCDeclQualifier_Out = 0x4,
4331 CXObjCDeclQualifier_Bycopy = 0x8,
4332 CXObjCDeclQualifier_Byref = 0x10,
4333 CXObjCDeclQualifier_Oneway = 0x20
4334} CXObjCDeclQualifierKind;
4335
4336/**
4337 * \brief Given a cursor that represents an Objective-C method or parameter
4338 * declaration, return the associated Objective-C qualifiers for the return
4339 * type or the parameter respectively. The bits are formed from
4340 * CXObjCDeclQualifierKind.
4341 */
4342CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
4343
4344/**
4345 * \brief Given a cursor that represents an Objective-C method or property
4346 * declaration, return non-zero if the declaration was affected by "\@optional".
4347 * Returns zero if the cursor is not such a declaration or it is "\@required".
4348 */
4349CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
4350
4351/**
4352 * \brief Returns non-zero if the given cursor is a variadic function or method.
4353 */
4354CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
4355
4356/**
4357 * \brief Returns non-zero if the given cursor points to a symbol marked with
4358 * external_source_symbol attribute.
4359 *
4360 * \param language If non-NULL, and the attribute is present, will be set to
4361 * the 'language' string from the attribute.
4362 *
4363 * \param definedIn If non-NULL, and the attribute is present, will be set to
4364 * the 'definedIn' string from the attribute.
4365 *
4366 * \param isGenerated If non-NULL, and the attribute is present, will be set to
4367 * non-zero if the 'generated_declaration' is set in the attribute.
4368 */
4369CINDEX_LINKAGE unsigned clang_Cursor_isExternalSymbol(CXCursor C,
4370 CXString *language, CXString *definedIn,
4371 unsigned *isGenerated);
4372
4373/**
4374 * \brief Given a cursor that represents a declaration, return the associated
4375 * comment's source range. The range may include multiple consecutive comments
4376 * with whitespace in between.
4377 */
4378CINDEX_LINKAGE CXSourceRange clang_Cursor_getCommentRange(CXCursor C);
4379
4380/**
4381 * \brief Given a cursor that represents a declaration, return the associated
4382 * comment text, including comment markers.
4383 */
4384CINDEX_LINKAGE CXString clang_Cursor_getRawCommentText(CXCursor C);
4385
4386/**
4387 * \brief Given a cursor that represents a documentable entity (e.g.,
4388 * declaration), return the associated \\brief paragraph; otherwise return the
4389 * first paragraph.
4390 */
4391CINDEX_LINKAGE CXString clang_Cursor_getBriefCommentText(CXCursor C);
4392
4393/**
4394 * @}
4395 */
4396
4397/** \defgroup CINDEX_MANGLE Name Mangling API Functions
4398 *
4399 * @{
4400 */
4401
4402/**
4403 * \brief Retrieve the CXString representing the mangled name of the cursor.
4404 */
4405CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor);
4406
4407/**
4408 * \brief Retrieve the CXStrings representing the mangled symbols of the C++
4409 * constructor or destructor at the cursor.
4410 */
4411CINDEX_LINKAGE CXStringSet *clang_Cursor_getCXXManglings(CXCursor);
4412
4413/**
4414 * \brief Retrieve the CXStrings representing the mangled symbols of the ObjC
4415 * class interface or implementation at the cursor.
4416 */
4417CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
4418
4419/**
4420 * @}
4421 */
4422
4423/**
4424 * \defgroup CINDEX_MODULE Module introspection
4425 *
4426 * The functions in this group provide access to information about modules.
4427 *
4428 * @{
4429 */
4430
4431typedef void *CXModule;
4432
4433/**
4434 * \brief Given a CXCursor_ModuleImportDecl cursor, return the associated module.
4435 */
4436CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
4437
4438/**
4439 * \brief Given a CXFile header file, return the module that contains it, if one
4440 * exists.
4441 */
4442CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile);
4443
4444/**
4445 * \param Module a module object.
4446 *
4447 * \returns the module file where the provided module object came from.
4448 */
4449CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
4450
4451/**
4452 * \param Module a module object.
4453 *
4454 * \returns the parent of a sub-module or NULL if the given module is top-level,
4455 * e.g. for 'std.vector' it will return the 'std' module.
4456 */
4457CINDEX_LINKAGE CXModule clang_Module_getParent(CXModule Module);
4458
4459/**
4460 * \param Module a module object.
4461 *
4462 * \returns the name of the module, e.g. for the 'std.vector' sub-module it
4463 * will return "vector".
4464 */
4465CINDEX_LINKAGE CXString clang_Module_getName(CXModule Module);
4466
4467/**
4468 * \param Module a module object.
4469 *
4470 * \returns the full name of the module, e.g. "std.vector".
4471 */
4472CINDEX_LINKAGE CXString clang_Module_getFullName(CXModule Module);
4473
4474/**
4475 * \param Module a module object.
4476 *
4477 * \returns non-zero if the module is a system one.
4478 */
4479CINDEX_LINKAGE int clang_Module_isSystem(CXModule Module);
4480
4481/**
4482 * \param Module a module object.
4483 *
4484 * \returns the number of top level headers associated with this module.
4485 */
4486CINDEX_LINKAGE unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit,
4487 CXModule Module);
4488
4489/**
4490 * \param Module a module object.
4491 *
4492 * \param Index top level header index (zero-based).
4493 *
4494 * \returns the specified top level header associated with the module.
4495 */
4496CINDEX_LINKAGE
4497CXFile clang_Module_getTopLevelHeader(CXTranslationUnit,
4498 CXModule Module, unsigned Index);
4499
4500/**
4501 * @}
4502 */
4503
4504/**
4505 * \defgroup CINDEX_CPP C++ AST introspection
4506 *
4507 * The routines in this group provide access information in the ASTs specific
4508 * to C++ language features.
4509 *
4510 * @{
4511 */
4512
4513/**
4514 * \brief Determine if a C++ constructor is a converting constructor.
4515 */
4516CINDEX_LINKAGE unsigned clang_CXXConstructor_isConvertingConstructor(CXCursor C);
4517
4518/**
4519 * \brief Determine if a C++ constructor is a copy constructor.
4520 */
4521CINDEX_LINKAGE unsigned clang_CXXConstructor_isCopyConstructor(CXCursor C);
4522
4523/**
4524 * \brief Determine if a C++ constructor is the default constructor.
4525 */
4526CINDEX_LINKAGE unsigned clang_CXXConstructor_isDefaultConstructor(CXCursor C);
4527
4528/**
4529 * \brief Determine if a C++ constructor is a move constructor.
4530 */
4531CINDEX_LINKAGE unsigned clang_CXXConstructor_isMoveConstructor(CXCursor C);
4532
4533/**
4534 * \brief Determine if a C++ field is declared 'mutable'.
4535 */
4536CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C);
4537
4538/**
4539 * \brief Determine if a C++ method is declared '= default'.
4540 */
4541CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
4542
4543/**
4544 * \brief Determine if a C++ member function or member function template is
4545 * pure virtual.
4546 */
4547CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
4548
4549/**
4550 * \brief Determine if a C++ member function or member function template is
4551 * declared 'static'.
4552 */
4553CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
4554
4555/**
4556 * \brief Determine if a C++ member function or member function template is
4557 * explicitly declared 'virtual' or if it overrides a virtual method from
4558 * one of the base classes.
4559 */
4560CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
4561
4562/**
4563 * \brief Determine if a C++ record is abstract, i.e. whether a class or struct
4564 * has a pure virtual member function.
4565 */
4566CINDEX_LINKAGE unsigned clang_CXXRecord_isAbstract(CXCursor C);
4567
4568/**
4569 * \brief Determine if an enum declaration refers to a scoped enum.
4570 */
4571CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
4572
4573/**
4574 * \brief Determine if a C++ member function or member function template is
4575 * declared 'const'.
4576 */
4577CINDEX_LINKAGE unsigned clang_CXXMethod_isConst(CXCursor C);
4578
4579/**
4580 * \brief Given a cursor that represents a template, determine
4581 * the cursor kind of the specializations would be generated by instantiating
4582 * the template.
4583 *
4584 * This routine can be used to determine what flavor of function template,
4585 * class template, or class template partial specialization is stored in the
4586 * cursor. For example, it can describe whether a class template cursor is
4587 * declared with "struct", "class" or "union".
4588 *
4589 * \param C The cursor to query. This cursor should represent a template
4590 * declaration.
4591 *
4592 * \returns The cursor kind of the specializations that would be generated
4593 * by instantiating the template \p C. If \p C is not a template, returns
4594 * \c CXCursor_NoDeclFound.
4595 */
4596CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
4597
4598/**
4599 * \brief Given a cursor that may represent a specialization or instantiation
4600 * of a template, retrieve the cursor that represents the template that it
4601 * specializes or from which it was instantiated.
4602 *
4603 * This routine determines the template involved both for explicit
4604 * specializations of templates and for implicit instantiations of the template,
4605 * both of which are referred to as "specializations". For a class template
4606 * specialization (e.g., \c std::vector<bool>), this routine will return
4607 * either the primary template (\c std::vector) or, if the specialization was
4608 * instantiated from a class template partial specialization, the class template
4609 * partial specialization. For a class template partial specialization and a
4610 * function template specialization (including instantiations), this
4611 * this routine will return the specialized template.
4612 *
4613 * For members of a class template (e.g., member functions, member classes, or
4614 * static data members), returns the specialized or instantiated member.
4615 * Although not strictly "templates" in the C++ language, members of class
4616 * templates have the same notions of specializations and instantiations that
4617 * templates do, so this routine treats them similarly.
4618 *
4619 * \param C A cursor that may be a specialization of a template or a member
4620 * of a template.
4621 *
4622 * \returns If the given cursor is a specialization or instantiation of a
4623 * template or a member thereof, the template or member that it specializes or
4624 * from which it was instantiated. Otherwise, returns a NULL cursor.
4625 */
4626CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
4627
4628/**
4629 * \brief Given a cursor that references something else, return the source range
4630 * covering that reference.
4631 *
4632 * \param C A cursor pointing to a member reference, a declaration reference, or
4633 * an operator call.
4634 * \param NameFlags A bitset with three independent flags:
4635 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
4636 * CXNameRange_WantSinglePiece.
4637 * \param PieceIndex For contiguous names or when passing the flag
4638 * CXNameRange_WantSinglePiece, only one piece with index 0 is
4639 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
4640 * non-contiguous names, this index can be used to retrieve the individual
4641 * pieces of the name. See also CXNameRange_WantSinglePiece.
4642 *
4643 * \returns The piece of the name pointed to by the given cursor. If there is no
4644 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
4645 */
4646CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
4647 unsigned NameFlags,
4648 unsigned PieceIndex);
4649
4650enum CXNameRefFlags {
4651 /**
4652 * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
4653 * range.
4654 */
4655 CXNameRange_WantQualifier = 0x1,
4656
4657 /**
4658 * \brief Include the explicit template arguments, e.g. \<int> in x.f<int>,
4659 * in the range.
4660 */
4661 CXNameRange_WantTemplateArgs = 0x2,
4662
4663 /**
4664 * \brief If the name is non-contiguous, return the full spanning range.
4665 *
4666 * Non-contiguous names occur in Objective-C when a selector with two or more
4667 * parameters is used, or in C++ when using an operator:
4668 * \code
4669 * [object doSomething:here withValue:there]; // Objective-C
4670 * return some_vector[1]; // C++
4671 * \endcode
4672 */
4673 CXNameRange_WantSinglePiece = 0x4
4674};
4675
4676/**
4677 * @}
4678 */
4679
4680/**
4681 * \defgroup CINDEX_LEX Token extraction and manipulation
4682 *
4683 * The routines in this group provide access to the tokens within a
4684 * translation unit, along with a semantic mapping of those tokens to
4685 * their corresponding cursors.
4686 *
4687 * @{
4688 */
4689
4690/**
4691 * \brief Describes a kind of token.
4692 */
4693typedef enum CXTokenKind {
4694 /**
4695 * \brief A token that contains some kind of punctuation.
4696 */
4697 CXToken_Punctuation,
4698
4699 /**
4700 * \brief A language keyword.
4701 */
4702 CXToken_Keyword,
4703
4704 /**
4705 * \brief An identifier (that is not a keyword).
4706 */
4707 CXToken_Identifier,
4708
4709 /**
4710 * \brief A numeric, string, or character literal.
4711 */
4712 CXToken_Literal,
4713
4714 /**
4715 * \brief A comment.
4716 */
4717 CXToken_Comment
4718} CXTokenKind;
4719
4720/**
4721 * \brief Describes a single preprocessing token.
4722 */
4723typedef struct {
4724 unsigned int_data[4];
4725 void *ptr_data;
4726} CXToken;
4727
4728/**
4729 * \brief Determine the kind of the given token.
4730 */
4731CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
4732
4733/**
4734 * \brief Determine the spelling of the given token.
4735 *
4736 * The spelling of a token is the textual representation of that token, e.g.,
4737 * the text of an identifier or keyword.
4738 */
4739CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
4740
4741/**
4742 * \brief Retrieve the source location of the given token.
4743 */
4744CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
4745 CXToken);
4746
4747/**
4748 * \brief Retrieve a source range that covers the given token.
4749 */
4750CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
4751
4752/**
4753 * \brief Tokenize the source code described by the given range into raw
4754 * lexical tokens.
4755 *
4756 * \param TU the translation unit whose text is being tokenized.
4757 *
4758 * \param Range the source range in which text should be tokenized. All of the
4759 * tokens produced by tokenization will fall within this source range,
4760 *
4761 * \param Tokens this pointer will be set to point to the array of tokens
4762 * that occur within the given source range. The returned pointer must be
4763 * freed with clang_disposeTokens() before the translation unit is destroyed.
4764 *
4765 * \param NumTokens will be set to the number of tokens in the \c *Tokens
4766 * array.
4767 *
4768 */
4769CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
4770 CXToken **Tokens, unsigned *NumTokens);
4771
4772/**
4773 * \brief Annotate the given set of tokens by providing cursors for each token
4774 * that can be mapped to a specific entity within the abstract syntax tree.
4775 *
4776 * This token-annotation routine is equivalent to invoking
4777 * clang_getCursor() for the source locations of each of the
4778 * tokens. The cursors provided are filtered, so that only those
4779 * cursors that have a direct correspondence to the token are
4780 * accepted. For example, given a function call \c f(x),
4781 * clang_getCursor() would provide the following cursors:
4782 *
4783 * * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
4784 * * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
4785 * * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
4786 *
4787 * Only the first and last of these cursors will occur within the
4788 * annotate, since the tokens "f" and "x' directly refer to a function
4789 * and a variable, respectively, but the parentheses are just a small
4790 * part of the full syntax of the function call expression, which is
4791 * not provided as an annotation.
4792 *
4793 * \param TU the translation unit that owns the given tokens.
4794 *
4795 * \param Tokens the set of tokens to annotate.
4796 *
4797 * \param NumTokens the number of tokens in \p Tokens.
4798 *
4799 * \param Cursors an array of \p NumTokens cursors, whose contents will be
4800 * replaced with the cursors corresponding to each token.
4801 */
4802CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
4803 CXToken *Tokens, unsigned NumTokens,
4804 CXCursor *Cursors);
4805
4806/**
4807 * \brief Free the given set of tokens.
4808 */
4809CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
4810 CXToken *Tokens, unsigned NumTokens);
4811
4812/**
4813 * @}
4814 */
4815
4816/**
4817 * \defgroup CINDEX_DEBUG Debugging facilities
4818 *
4819 * These routines are used for testing and debugging, only, and should not
4820 * be relied upon.
4821 *
4822 * @{
4823 */
4824
4825/* for debug/testing */
4826CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
4827CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
4828 const char **startBuf,
4829 const char **endBuf,
4830 unsigned *startLine,
4831 unsigned *startColumn,
4832 unsigned *endLine,
4833 unsigned *endColumn);
4834CINDEX_LINKAGE void clang_enableStackTraces(void);
4835CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
4836 unsigned stack_size);
4837
4838/**
4839 * @}
4840 */
4841
4842/**
4843 * \defgroup CINDEX_CODE_COMPLET Code completion
4844 *
4845 * Code completion involves taking an (incomplete) source file, along with
4846 * knowledge of where the user is actively editing that file, and suggesting
4847 * syntactically- and semantically-valid constructs that the user might want to
4848 * use at that particular point in the source code. These data structures and
4849 * routines provide support for code completion.
4850 *
4851 * @{
4852 */
4853
4854/**
4855 * \brief A semantic string that describes a code-completion result.
4856 *
4857 * A semantic string that describes the formatting of a code-completion
4858 * result as a single "template" of text that should be inserted into the
4859 * source buffer when a particular code-completion result is selected.
4860 * Each semantic string is made up of some number of "chunks", each of which
4861 * contains some text along with a description of what that text means, e.g.,
4862 * the name of the entity being referenced, whether the text chunk is part of
4863 * the template, or whether it is a "placeholder" that the user should replace
4864 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
4865 * description of the different kinds of chunks.
4866 */
4867typedef void *CXCompletionString;
4868
4869/**
4870 * \brief A single result of code completion.
4871 */
4872typedef struct {
4873 /**
4874 * \brief The kind of entity that this completion refers to.
4875 *
4876 * The cursor kind will be a macro, keyword, or a declaration (one of the
4877 * *Decl cursor kinds), describing the entity that the completion is
4878 * referring to.
4879 *
4880 * \todo In the future, we would like to provide a full cursor, to allow
4881 * the client to extract additional information from declaration.
4882 */
4883 enum CXCursorKind CursorKind;
4884
4885 /**
4886 * \brief The code-completion string that describes how to insert this
4887 * code-completion result into the editing buffer.
4888 */
4889 CXCompletionString CompletionString;
4890} CXCompletionResult;
4891
4892/**
4893 * \brief Describes a single piece of text within a code-completion string.
4894 *
4895 * Each "chunk" within a code-completion string (\c CXCompletionString) is
4896 * either a piece of text with a specific "kind" that describes how that text
4897 * should be interpreted by the client or is another completion string.
4898 */
4899enum CXCompletionChunkKind {
4900 /**
4901 * \brief A code-completion string that describes "optional" text that
4902 * could be a part of the template (but is not required).
4903 *
4904 * The Optional chunk is the only kind of chunk that has a code-completion
4905 * string for its representation, which is accessible via
4906 * \c clang_getCompletionChunkCompletionString(). The code-completion string
4907 * describes an additional part of the template that is completely optional.
4908 * For example, optional chunks can be used to describe the placeholders for
4909 * arguments that match up with defaulted function parameters, e.g. given:
4910 *
4911 * \code
4912 * void f(int x, float y = 3.14, double z = 2.71828);
4913 * \endcode
4914 *
4915 * The code-completion string for this function would contain:
4916 * - a TypedText chunk for "f".
4917 * - a LeftParen chunk for "(".
4918 * - a Placeholder chunk for "int x"
4919 * - an Optional chunk containing the remaining defaulted arguments, e.g.,
4920 * - a Comma chunk for ","
4921 * - a Placeholder chunk for "float y"
4922 * - an Optional chunk containing the last defaulted argument:
4923 * - a Comma chunk for ","
4924 * - a Placeholder chunk for "double z"
4925 * - a RightParen chunk for ")"
4926 *
4927 * There are many ways to handle Optional chunks. Two simple approaches are:
4928 * - Completely ignore optional chunks, in which case the template for the
4929 * function "f" would only include the first parameter ("int x").
4930 * - Fully expand all optional chunks, in which case the template for the
4931 * function "f" would have all of the parameters.
4932 */
4933 CXCompletionChunk_Optional,
4934 /**
4935 * \brief Text that a user would be expected to type to get this
4936 * code-completion result.
4937 *
4938 * There will be exactly one "typed text" chunk in a semantic string, which
4939 * will typically provide the spelling of a keyword or the name of a
4940 * declaration that could be used at the current code point. Clients are
4941 * expected to filter the code-completion results based on the text in this
4942 * chunk.
4943 */
4944 CXCompletionChunk_TypedText,
4945 /**
4946 * \brief Text that should be inserted as part of a code-completion result.
4947 *
4948 * A "text" chunk represents text that is part of the template to be
4949 * inserted into user code should this particular code-completion result
4950 * be selected.
4951 */
4952 CXCompletionChunk_Text,
4953 /**
4954 * \brief Placeholder text that should be replaced by the user.
4955 *
4956 * A "placeholder" chunk marks a place where the user should insert text
4957 * into the code-completion template. For example, placeholders might mark
4958 * the function parameters for a function declaration, to indicate that the
4959 * user should provide arguments for each of those parameters. The actual
4960 * text in a placeholder is a suggestion for the text to display before
4961 * the user replaces the placeholder with real code.
4962 */
4963 CXCompletionChunk_Placeholder,
4964 /**
4965 * \brief Informative text that should be displayed but never inserted as
4966 * part of the template.
4967 *
4968 * An "informative" chunk contains annotations that can be displayed to
4969 * help the user decide whether a particular code-completion result is the
4970 * right option, but which is not part of the actual template to be inserted
4971 * by code completion.
4972 */
4973 CXCompletionChunk_Informative,
4974 /**
4975 * \brief Text that describes the current parameter when code-completion is
4976 * referring to function call, message send, or template specialization.
4977 *
4978 * A "current parameter" chunk occurs when code-completion is providing
4979 * information about a parameter corresponding to the argument at the
4980 * code-completion point. For example, given a function
4981 *
4982 * \code
4983 * int add(int x, int y);
4984 * \endcode
4985 *
4986 * and the source code \c add(, where the code-completion point is after the
4987 * "(", the code-completion string will contain a "current parameter" chunk
4988 * for "int x", indicating that the current argument will initialize that
4989 * parameter. After typing further, to \c add(17, (where the code-completion
4990 * point is after the ","), the code-completion string will contain a
4991 * "current paremeter" chunk to "int y".
4992 */
4993 CXCompletionChunk_CurrentParameter,
4994 /**
4995 * \brief A left parenthesis ('('), used to initiate a function call or
4996 * signal the beginning of a function parameter list.
4997 */
4998 CXCompletionChunk_LeftParen,
4999 /**
5000 * \brief A right parenthesis (')'), used to finish a function call or
5001 * signal the end of a function parameter list.
5002 */
5003 CXCompletionChunk_RightParen,
5004 /**
5005 * \brief A left bracket ('[').
5006 */
5007 CXCompletionChunk_LeftBracket,
5008 /**
5009 * \brief A right bracket (']').
5010 */
5011 CXCompletionChunk_RightBracket,
5012 /**
5013 * \brief A left brace ('{').
5014 */
5015 CXCompletionChunk_LeftBrace,
5016 /**
5017 * \brief A right brace ('}').
5018 */
5019 CXCompletionChunk_RightBrace,
5020 /**
5021 * \brief A left angle bracket ('<').
5022 */
5023 CXCompletionChunk_LeftAngle,
5024 /**
5025 * \brief A right angle bracket ('>').
5026 */
5027 CXCompletionChunk_RightAngle,
5028 /**
5029 * \brief A comma separator (',').
5030 */
5031 CXCompletionChunk_Comma,
5032 /**
5033 * \brief Text that specifies the result type of a given result.
5034 *
5035 * This special kind of informative chunk is not meant to be inserted into
5036 * the text buffer. Rather, it is meant to illustrate the type that an
5037 * expression using the given completion string would have.
5038 */
5039 CXCompletionChunk_ResultType,
5040 /**
5041 * \brief A colon (':').
5042 */
5043 CXCompletionChunk_Colon,
5044 /**
5045 * \brief A semicolon (';').
5046 */
5047 CXCompletionChunk_SemiColon,
5048 /**
5049 * \brief An '=' sign.
5050 */
5051 CXCompletionChunk_Equal,
5052 /**
5053 * Horizontal space (' ').
5054 */
5055 CXCompletionChunk_HorizontalSpace,
5056 /**
5057 * Vertical space ('\\n'), after which it is generally a good idea to
5058 * perform indentation.
5059 */
5060 CXCompletionChunk_VerticalSpace
5061};
5062
5063/**
5064 * \brief Determine the kind of a particular chunk within a completion string.
5065 *
5066 * \param completion_string the completion string to query.
5067 *
5068 * \param chunk_number the 0-based index of the chunk in the completion string.
5069 *
5070 * \returns the kind of the chunk at the index \c chunk_number.
5071 */
5072CINDEX_LINKAGE enum CXCompletionChunkKind
5073clang_getCompletionChunkKind(CXCompletionString completion_string,
5074 unsigned chunk_number);
5075
5076/**
5077 * \brief Retrieve the text associated with a particular chunk within a
5078 * completion string.
5079 *
5080 * \param completion_string the completion string to query.
5081 *
5082 * \param chunk_number the 0-based index of the chunk in the completion string.
5083 *
5084 * \returns the text associated with the chunk at index \c chunk_number.
5085 */
5086CINDEX_LINKAGE CXString
5087clang_getCompletionChunkText(CXCompletionString completion_string,
5088 unsigned chunk_number);
5089
5090/**
5091 * \brief Retrieve the completion string associated with a particular chunk
5092 * within a completion string.
5093 *
5094 * \param completion_string the completion string to query.
5095 *
5096 * \param chunk_number the 0-based index of the chunk in the completion string.
5097 *
5098 * \returns the completion string associated with the chunk at index
5099 * \c chunk_number.
5100 */
5101CINDEX_LINKAGE CXCompletionString
5102clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
5103 unsigned chunk_number);
5104
5105/**
5106 * \brief Retrieve the number of chunks in the given code-completion string.
5107 */
5108CINDEX_LINKAGE unsigned
5109clang_getNumCompletionChunks(CXCompletionString completion_string);
5110
5111/**
5112 * \brief Determine the priority of this code completion.
5113 *
5114 * The priority of a code completion indicates how likely it is that this
5115 * particular completion is the completion that the user will select. The
5116 * priority is selected by various internal heuristics.
5117 *
5118 * \param completion_string The completion string to query.
5119 *
5120 * \returns The priority of this completion string. Smaller values indicate
5121 * higher-priority (more likely) completions.
5122 */
5123CINDEX_LINKAGE unsigned
5124clang_getCompletionPriority(CXCompletionString completion_string);
5125
5126/**
5127 * \brief Determine the availability of the entity that this code-completion
5128 * string refers to.
5129 *
5130 * \param completion_string The completion string to query.
5131 *
5132 * \returns The availability of the completion string.
5133 */
5134CINDEX_LINKAGE enum CXAvailabilityKind
5135clang_getCompletionAvailability(CXCompletionString completion_string);
5136
5137/**
5138 * \brief Retrieve the number of annotations associated with the given
5139 * completion string.
5140 *
5141 * \param completion_string the completion string to query.
5142 *
5143 * \returns the number of annotations associated with the given completion
5144 * string.
5145 */
5146CINDEX_LINKAGE unsigned
5147clang_getCompletionNumAnnotations(CXCompletionString completion_string);
5148
5149/**
5150 * \brief Retrieve the annotation associated with the given completion string.
5151 *
5152 * \param completion_string the completion string to query.
5153 *
5154 * \param annotation_number the 0-based index of the annotation of the
5155 * completion string.
5156 *
5157 * \returns annotation string associated with the completion at index
5158 * \c annotation_number, or a NULL string if that annotation is not available.
5159 */
5160CINDEX_LINKAGE CXString
5161clang_getCompletionAnnotation(CXCompletionString completion_string,
5162 unsigned annotation_number);
5163
5164/**
5165 * \brief Retrieve the parent context of the given completion string.
5166 *
5167 * The parent context of a completion string is the semantic parent of
5168 * the declaration (if any) that the code completion represents. For example,
5169 * a code completion for an Objective-C method would have the method's class
5170 * or protocol as its context.
5171 *
5172 * \param completion_string The code completion string whose parent is
5173 * being queried.
5174 *
5175 * \param kind DEPRECATED: always set to CXCursor_NotImplemented if non-NULL.
5176 *
5177 * \returns The name of the completion parent, e.g., "NSObject" if
5178 * the completion string represents a method in the NSObject class.
5179 */
5180CINDEX_LINKAGE CXString
5181clang_getCompletionParent(CXCompletionString completion_string,
5182 enum CXCursorKind *kind);
5183
5184/**
5185 * \brief Retrieve the brief documentation comment attached to the declaration
5186 * that corresponds to the given completion string.
5187 */
5188CINDEX_LINKAGE CXString
5189clang_getCompletionBriefComment(CXCompletionString completion_string);
5190
5191/**
5192 * \brief Retrieve a completion string for an arbitrary declaration or macro
5193 * definition cursor.
5194 *
5195 * \param cursor The cursor to query.
5196 *
5197 * \returns A non-context-sensitive completion string for declaration and macro
5198 * definition cursors, or NULL for other kinds of cursors.
5199 */
5200CINDEX_LINKAGE CXCompletionString
5201clang_getCursorCompletionString(CXCursor cursor);
5202
5203/**
5204 * \brief Contains the results of code-completion.
5205 *
5206 * This data structure contains the results of code completion, as
5207 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
5208 * \c clang_disposeCodeCompleteResults.
5209 */
5210typedef struct {
5211 /**
5212 * \brief The code-completion results.
5213 */
5214 CXCompletionResult *Results;
5215
5216 /**
5217 * \brief The number of code-completion results stored in the
5218 * \c Results array.
5219 */
5220 unsigned NumResults;
5221} CXCodeCompleteResults;
5222
5223/**
5224 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
5225 * modify its behavior.
5226 *
5227 * The enumerators in this enumeration can be bitwise-OR'd together to
5228 * provide multiple options to \c clang_codeCompleteAt().
5229 */
5230enum CXCodeComplete_Flags {
5231 /**
5232 * \brief Whether to include macros within the set of code
5233 * completions returned.
5234 */
5235 CXCodeComplete_IncludeMacros = 0x01,
5236
5237 /**
5238 * \brief Whether to include code patterns for language constructs
5239 * within the set of code completions, e.g., for loops.
5240 */
5241 CXCodeComplete_IncludeCodePatterns = 0x02,
5242
5243 /**
5244 * \brief Whether to include brief documentation within the set of code
5245 * completions returned.
5246 */
5247 CXCodeComplete_IncludeBriefComments = 0x04,
5248
5249 /**
5250 * Whether to speed up completion by omitting top- or namespace-level entities
5251 * defined in the preamble. There's no guarantee any particular entity is
5252 * omitted. This may be useful if the headers are indexed externally.
5253 */
5254 CXCodeComplete_SkipPreamble = 0x08
5255};
5256
5257/**
5258 * \brief Bits that represent the context under which completion is occurring.
5259 *
5260 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
5261 * contexts are occurring simultaneously.
5262 */
5263enum CXCompletionContext {
5264 /**
5265 * \brief The context for completions is unexposed, as only Clang results
5266 * should be included. (This is equivalent to having no context bits set.)
5267 */
5268 CXCompletionContext_Unexposed = 0,
5269
5270 /**
5271 * \brief Completions for any possible type should be included in the results.
5272 */
5273 CXCompletionContext_AnyType = 1 << 0,
5274
5275 /**
5276 * \brief Completions for any possible value (variables, function calls, etc.)
5277 * should be included in the results.
5278 */
5279 CXCompletionContext_AnyValue = 1 << 1,
5280 /**
5281 * \brief Completions for values that resolve to an Objective-C object should
5282 * be included in the results.
5283 */
5284 CXCompletionContext_ObjCObjectValue = 1 << 2,
5285 /**
5286 * \brief Completions for values that resolve to an Objective-C selector
5287 * should be included in the results.
5288 */
5289 CXCompletionContext_ObjCSelectorValue = 1 << 3,
5290 /**
5291 * \brief Completions for values that resolve to a C++ class type should be
5292 * included in the results.
5293 */
5294 CXCompletionContext_CXXClassTypeValue = 1 << 4,
5295
5296 /**
5297 * \brief Completions for fields of the member being accessed using the dot
5298 * operator should be included in the results.
5299 */
5300 CXCompletionContext_DotMemberAccess = 1 << 5,
5301 /**
5302 * \brief Completions for fields of the member being accessed using the arrow
5303 * operator should be included in the results.
5304 */
5305 CXCompletionContext_ArrowMemberAccess = 1 << 6,
5306 /**
5307 * \brief Completions for properties of the Objective-C object being accessed
5308 * using the dot operator should be included in the results.
5309 */
5310 CXCompletionContext_ObjCPropertyAccess = 1 << 7,
5311
5312 /**
5313 * \brief Completions for enum tags should be included in the results.
5314 */
5315 CXCompletionContext_EnumTag = 1 << 8,
5316 /**
5317 * \brief Completions for union tags should be included in the results.
5318 */
5319 CXCompletionContext_UnionTag = 1 << 9,
5320 /**
5321 * \brief Completions for struct tags should be included in the results.
5322 */
5323 CXCompletionContext_StructTag = 1 << 10,
5324
5325 /**
5326 * \brief Completions for C++ class names should be included in the results.
5327 */
5328 CXCompletionContext_ClassTag = 1 << 11,
5329 /**
5330 * \brief Completions for C++ namespaces and namespace aliases should be
5331 * included in the results.
5332 */
5333 CXCompletionContext_Namespace = 1 << 12,
5334 /**
5335 * \brief Completions for C++ nested name specifiers should be included in
5336 * the results.
5337 */
5338 CXCompletionContext_NestedNameSpecifier = 1 << 13,
5339
5340 /**
5341 * \brief Completions for Objective-C interfaces (classes) should be included
5342 * in the results.
5343 */
5344 CXCompletionContext_ObjCInterface = 1 << 14,
5345 /**
5346 * \brief Completions for Objective-C protocols should be included in
5347 * the results.
5348 */
5349 CXCompletionContext_ObjCProtocol = 1 << 15,
5350 /**
5351 * \brief Completions for Objective-C categories should be included in
5352 * the results.
5353 */
5354 CXCompletionContext_ObjCCategory = 1 << 16,
5355 /**
5356 * \brief Completions for Objective-C instance messages should be included
5357 * in the results.
5358 */
5359 CXCompletionContext_ObjCInstanceMessage = 1 << 17,
5360 /**
5361 * \brief Completions for Objective-C class messages should be included in
5362 * the results.
5363 */
5364 CXCompletionContext_ObjCClassMessage = 1 << 18,
5365 /**
5366 * \brief Completions for Objective-C selector names should be included in
5367 * the results.
5368 */
5369 CXCompletionContext_ObjCSelectorName = 1 << 19,
5370
5371 /**
5372 * \brief Completions for preprocessor macro names should be included in
5373 * the results.
5374 */
5375 CXCompletionContext_MacroName = 1 << 20,
5376
5377 /**
5378 * \brief Natural language completions should be included in the results.
5379 */
5380 CXCompletionContext_NaturalLanguage = 1 << 21,
5381
5382 /**
5383 * \brief The current context is unknown, so set all contexts.
5384 */
5385 CXCompletionContext_Unknown = ((1 << 22) - 1)
5386};
5387
5388/**
5389 * \brief Returns a default set of code-completion options that can be
5390 * passed to\c clang_codeCompleteAt().
5391 */
5392CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
5393
5394/**
5395 * \brief Perform code completion at a given location in a translation unit.
5396 *
5397 * This function performs code completion at a particular file, line, and
5398 * column within source code, providing results that suggest potential
5399 * code snippets based on the context of the completion. The basic model
5400 * for code completion is that Clang will parse a complete source file,
5401 * performing syntax checking up to the location where code-completion has
5402 * been requested. At that point, a special code-completion token is passed
5403 * to the parser, which recognizes this token and determines, based on the
5404 * current location in the C/Objective-C/C++ grammar and the state of
5405 * semantic analysis, what completions to provide. These completions are
5406 * returned via a new \c CXCodeCompleteResults structure.
5407 *
5408 * Code completion itself is meant to be triggered by the client when the
5409 * user types punctuation characters or whitespace, at which point the
5410 * code-completion location will coincide with the cursor. For example, if \c p
5411 * is a pointer, code-completion might be triggered after the "-" and then
5412 * after the ">" in \c p->. When the code-completion location is afer the ">",
5413 * the completion results will provide, e.g., the members of the struct that
5414 * "p" points to. The client is responsible for placing the cursor at the
5415 * beginning of the token currently being typed, then filtering the results
5416 * based on the contents of the token. For example, when code-completing for
5417 * the expression \c p->get, the client should provide the location just after
5418 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
5419 * client can filter the results based on the current token text ("get"), only
5420 * showing those results that start with "get". The intent of this interface
5421 * is to separate the relatively high-latency acquisition of code-completion
5422 * results from the filtering of results on a per-character basis, which must
5423 * have a lower latency.
5424 *
5425 * \param TU The translation unit in which code-completion should
5426 * occur. The source files for this translation unit need not be
5427 * completely up-to-date (and the contents of those source files may
5428 * be overridden via \p unsaved_files). Cursors referring into the
5429 * translation unit may be invalidated by this invocation.
5430 *
5431 * \param complete_filename The name of the source file where code
5432 * completion should be performed. This filename may be any file
5433 * included in the translation unit.
5434 *
5435 * \param complete_line The line at which code-completion should occur.
5436 *
5437 * \param complete_column The column at which code-completion should occur.
5438 * Note that the column should point just after the syntactic construct that
5439 * initiated code completion, and not in the middle of a lexical token.
5440 *
5441 * \param unsaved_files the Files that have not yet been saved to disk
5442 * but may be required for parsing or code completion, including the
5443 * contents of those files. The contents and name of these files (as
5444 * specified by CXUnsavedFile) are copied when necessary, so the
5445 * client only needs to guarantee their validity until the call to
5446 * this function returns.
5447 *
5448 * \param num_unsaved_files The number of unsaved file entries in \p
5449 * unsaved_files.
5450 *
5451 * \param options Extra options that control the behavior of code
5452 * completion, expressed as a bitwise OR of the enumerators of the
5453 * CXCodeComplete_Flags enumeration. The
5454 * \c clang_defaultCodeCompleteOptions() function returns a default set
5455 * of code-completion options.
5456 *
5457 * \returns If successful, a new \c CXCodeCompleteResults structure
5458 * containing code-completion results, which should eventually be
5459 * freed with \c clang_disposeCodeCompleteResults(). If code
5460 * completion fails, returns NULL.
5461 */
5462CINDEX_LINKAGE
5463CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
5464 const char *complete_filename,
5465 unsigned complete_line,
5466 unsigned complete_column,
5467 struct CXUnsavedFile *unsaved_files,
5468 unsigned num_unsaved_files,
5469 unsigned options);
5470
5471/**
5472 * \brief Sort the code-completion results in case-insensitive alphabetical
5473 * order.
5474 *
5475 * \param Results The set of results to sort.
5476 * \param NumResults The number of results in \p Results.
5477 */
5478CINDEX_LINKAGE
5479void clang_sortCodeCompletionResults(CXCompletionResult *Results,
5480 unsigned NumResults);
5481
5482/**
5483 * \brief Free the given set of code-completion results.
5484 */
5485CINDEX_LINKAGE
5486void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
5487
5488/**
5489 * \brief Determine the number of diagnostics produced prior to the
5490 * location where code completion was performed.
5491 */
5492CINDEX_LINKAGE
5493unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
5494
5495/**
5496 * \brief Retrieve a diagnostic associated with the given code completion.
5497 *
5498 * \param Results the code completion results to query.
5499 * \param Index the zero-based diagnostic number to retrieve.
5500 *
5501 * \returns the requested diagnostic. This diagnostic must be freed
5502 * via a call to \c clang_disposeDiagnostic().
5503 */
5504CINDEX_LINKAGE
5505CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
5506 unsigned Index);
5507
5508/**
5509 * \brief Determines what completions are appropriate for the context
5510 * the given code completion.
5511 *
5512 * \param Results the code completion results to query
5513 *
5514 * \returns the kinds of completions that are appropriate for use
5515 * along with the given code completion results.
5516 */
5517CINDEX_LINKAGE
5518unsigned long long clang_codeCompleteGetContexts(
5519 CXCodeCompleteResults *Results);
5520
5521/**
5522 * \brief Returns the cursor kind for the container for the current code
5523 * completion context. The container is only guaranteed to be set for
5524 * contexts where a container exists (i.e. member accesses or Objective-C
5525 * message sends); if there is not a container, this function will return
5526 * CXCursor_InvalidCode.
5527 *
5528 * \param Results the code completion results to query
5529 *
5530 * \param IsIncomplete on return, this value will be false if Clang has complete
5531 * information about the container. If Clang does not have complete
5532 * information, this value will be true.
5533 *
5534 * \returns the container kind, or CXCursor_InvalidCode if there is not a
5535 * container
5536 */
5537CINDEX_LINKAGE
5538enum CXCursorKind clang_codeCompleteGetContainerKind(
5539 CXCodeCompleteResults *Results,
5540 unsigned *IsIncomplete);
5541
5542/**
5543 * \brief Returns the USR for the container for the current code completion
5544 * context. If there is not a container for the current context, this
5545 * function will return the empty string.
5546 *
5547 * \param Results the code completion results to query
5548 *
5549 * \returns the USR for the container
5550 */
5551CINDEX_LINKAGE
5552CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
5553
5554/**
5555 * \brief Returns the currently-entered selector for an Objective-C message
5556 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
5557 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
5558 * CXCompletionContext_ObjCClassMessage.
5559 *
5560 * \param Results the code completion results to query
5561 *
5562 * \returns the selector (or partial selector) that has been entered thus far
5563 * for an Objective-C message send.
5564 */
5565CINDEX_LINKAGE
5566CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
5567
5568/**
5569 * @}
5570 */
5571
5572/**
5573 * \defgroup CINDEX_MISC Miscellaneous utility functions
5574 *
5575 * @{
5576 */
5577
5578/**
5579 * \brief Return a version string, suitable for showing to a user, but not
5580 * intended to be parsed (the format is not guaranteed to be stable).
5581 */
5582CINDEX_LINKAGE CXString clang_getClangVersion(void);
5583
5584/**
5585 * \brief Enable/disable crash recovery.
5586 *
5587 * \param isEnabled Flag to indicate if crash recovery is enabled. A non-zero
5588 * value enables crash recovery, while 0 disables it.
5589 */
5590CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
5591
5592 /**
5593 * \brief Visitor invoked for each file in a translation unit
5594 * (used with clang_getInclusions()).
5595 *
5596 * This visitor function will be invoked by clang_getInclusions() for each
5597 * file included (either at the top-level or by \#include directives) within
5598 * a translation unit. The first argument is the file being included, and
5599 * the second and third arguments provide the inclusion stack. The
5600 * array is sorted in order of immediate inclusion. For example,
5601 * the first element refers to the location that included 'included_file'.
5602 */
5603typedef void (*CXInclusionVisitor)(CXFile included_file,
5604 CXSourceLocation* inclusion_stack,
5605 unsigned include_len,
5606 CXClientData client_data);
5607
5608/**
5609 * \brief Visit the set of preprocessor inclusions in a translation unit.
5610 * The visitor function is called with the provided data for every included
5611 * file. This does not include headers included by the PCH file (unless one
5612 * is inspecting the inclusions in the PCH file itself).
5613 */
5614CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
5615 CXInclusionVisitor visitor,
5616 CXClientData client_data);
5617
5618typedef enum {
5619 CXEval_Int = 1 ,
5620 CXEval_Float = 2,
5621 CXEval_ObjCStrLiteral = 3,
5622 CXEval_StrLiteral = 4,
5623 CXEval_CFStr = 5,
5624 CXEval_Other = 6,
5625
5626 CXEval_UnExposed = 0
5627
5628} CXEvalResultKind ;
5629
5630/**
5631 * \brief Evaluation result of a cursor
5632 */
5633typedef void * CXEvalResult;
5634
5635/**
5636 * \brief If cursor is a statement declaration tries to evaluate the
5637 * statement and if its variable, tries to evaluate its initializer,
5638 * into its corresponding type.
5639 */
5640CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C);
5641
5642/**
5643 * \brief Returns the kind of the evaluated result.
5644 */
5645CINDEX_LINKAGE CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E);
5646
5647/**
5648 * \brief Returns the evaluation result as integer if the
5649 * kind is Int.
5650 */
5651CINDEX_LINKAGE int clang_EvalResult_getAsInt(CXEvalResult E);
5652
5653/**
5654 * \brief Returns the evaluation result as a long long integer if the
5655 * kind is Int. This prevents overflows that may happen if the result is
5656 * returned with clang_EvalResult_getAsInt.
5657 */
5658CINDEX_LINKAGE long long clang_EvalResult_getAsLongLong(CXEvalResult E);
5659
5660/**
5661 * \brief Returns a non-zero value if the kind is Int and the evaluation
5662 * result resulted in an unsigned integer.
5663 */
5664CINDEX_LINKAGE unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E);
5665
5666/**
5667 * \brief Returns the evaluation result as an unsigned integer if
5668 * the kind is Int and clang_EvalResult_isUnsignedInt is non-zero.
5669 */
5670CINDEX_LINKAGE unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E);
5671
5672/**
5673 * \brief Returns the evaluation result as double if the
5674 * kind is double.
5675 */
5676CINDEX_LINKAGE double clang_EvalResult_getAsDouble(CXEvalResult E);
5677
5678/**
5679 * \brief Returns the evaluation result as a constant string if the
5680 * kind is other than Int or float. User must not free this pointer,
5681 * instead call clang_EvalResult_dispose on the CXEvalResult returned
5682 * by clang_Cursor_Evaluate.
5683 */
5684CINDEX_LINKAGE const char* clang_EvalResult_getAsStr(CXEvalResult E);
5685
5686/**
5687 * \brief Disposes the created Eval memory.
5688 */
5689CINDEX_LINKAGE void clang_EvalResult_dispose(CXEvalResult E);
5690/**
5691 * @}
5692 */
5693
5694/** \defgroup CINDEX_REMAPPING Remapping functions
5695 *
5696 * @{
5697 */
5698
5699/**
5700 * \brief A remapping of original source files and their translated files.
5701 */
5702typedef void *CXRemapping;
5703
5704/**
5705 * \brief Retrieve a remapping.
5706 *
5707 * \param path the path that contains metadata about remappings.
5708 *
5709 * \returns the requested remapping. This remapping must be freed
5710 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5711 */
5712CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
5713
5714/**
5715 * \brief Retrieve a remapping.
5716 *
5717 * \param filePaths pointer to an array of file paths containing remapping info.
5718 *
5719 * \param numFiles number of file paths.
5720 *
5721 * \returns the requested remapping. This remapping must be freed
5722 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
5723 */
5724CINDEX_LINKAGE
5725CXRemapping clang_getRemappingsFromFileList(const char **filePaths,
5726 unsigned numFiles);
5727
5728/**
5729 * \brief Determine the number of remappings.
5730 */
5731CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
5732
5733/**
5734 * \brief Get the original and the associated filename from the remapping.
5735 *
5736 * \param original If non-NULL, will be set to the original filename.
5737 *
5738 * \param transformed If non-NULL, will be set to the filename that the original
5739 * is associated with.
5740 */
5741CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
5742 CXString *original, CXString *transformed);
5743
5744/**
5745 * \brief Dispose the remapping.
5746 */
5747CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
5748
5749/**
5750 * @}
5751 */
5752
5753/** \defgroup CINDEX_HIGH Higher level API functions
5754 *
5755 * @{
5756 */
5757
5758enum CXVisitorResult {
5759 CXVisit_Break,
5760 CXVisit_Continue
5761};
5762
5763typedef struct CXCursorAndRangeVisitor {
5764 void *context;
5765 enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
5766} CXCursorAndRangeVisitor;
5767
5768typedef enum {
5769 /**
5770 * \brief Function returned successfully.
5771 */
5772 CXResult_Success = 0,
5773 /**
5774 * \brief One of the parameters was invalid for the function.
5775 */
5776 CXResult_Invalid = 1,
5777 /**
5778 * \brief The function was terminated by a callback (e.g. it returned
5779 * CXVisit_Break)
5780 */
5781 CXResult_VisitBreak = 2
5782
5783} CXResult;
5784
5785/**
5786 * \brief Find references of a declaration in a specific file.
5787 *
5788 * \param cursor pointing to a declaration or a reference of one.
5789 *
5790 * \param file to search for references.
5791 *
5792 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5793 * each reference found.
5794 * The CXSourceRange will point inside the file; if the reference is inside
5795 * a macro (and not a macro argument) the CXSourceRange will be invalid.
5796 *
5797 * \returns one of the CXResult enumerators.
5798 */
5799CINDEX_LINKAGE CXResult clang_findReferencesInFile(CXCursor cursor, CXFile file,
5800 CXCursorAndRangeVisitor visitor);
5801
5802/**
5803 * \brief Find #import/#include directives in a specific file.
5804 *
5805 * \param TU translation unit containing the file to query.
5806 *
5807 * \param file to search for #import/#include directives.
5808 *
5809 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
5810 * each directive found.
5811 *
5812 * \returns one of the CXResult enumerators.
5813 */
5814CINDEX_LINKAGE CXResult clang_findIncludesInFile(CXTranslationUnit TU,
5815 CXFile file,
5816 CXCursorAndRangeVisitor visitor);
5817
5818#ifdef __has_feature
5819# if __has_feature(blocks)
5820
5821typedef enum CXVisitorResult
5822 (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
5823
5824CINDEX_LINKAGE
5825CXResult clang_findReferencesInFileWithBlock(CXCursor, CXFile,
5826 CXCursorAndRangeVisitorBlock);
5827
5828CINDEX_LINKAGE
5829CXResult clang_findIncludesInFileWithBlock(CXTranslationUnit, CXFile,
5830 CXCursorAndRangeVisitorBlock);
5831
5832# endif
5833#endif
5834
5835/**
5836 * \brief The client's data object that is associated with a CXFile.
5837 */
5838typedef void *CXIdxClientFile;
5839
5840/**
5841 * \brief The client's data object that is associated with a semantic entity.
5842 */
5843typedef void *CXIdxClientEntity;
5844
5845/**
5846 * \brief The client's data object that is associated with a semantic container
5847 * of entities.
5848 */
5849typedef void *CXIdxClientContainer;
5850
5851/**
5852 * \brief The client's data object that is associated with an AST file (PCH
5853 * or module).
5854 */
5855typedef void *CXIdxClientASTFile;
5856
5857/**
5858 * \brief Source location passed to index callbacks.
5859 */
5860typedef struct {
5861 void *ptr_data[2];
5862 unsigned int_data;
5863} CXIdxLoc;
5864
5865/**
5866 * \brief Data for ppIncludedFile callback.
5867 */
5868typedef struct {
5869 /**
5870 * \brief Location of '#' in the \#include/\#import directive.
5871 */
5872 CXIdxLoc hashLoc;
5873 /**
5874 * \brief Filename as written in the \#include/\#import directive.
5875 */
5876 const char *filename;
5877 /**
5878 * \brief The actual file that the \#include/\#import directive resolved to.
5879 */
5880 CXFile file;
5881 int isImport;
5882 int isAngled;
5883 /**
5884 * \brief Non-zero if the directive was automatically turned into a module
5885 * import.
5886 */
5887 int isModuleImport;
5888} CXIdxIncludedFileInfo;
5889
5890/**
5891 * \brief Data for IndexerCallbacks#importedASTFile.
5892 */
5893typedef struct {
5894 /**
5895 * \brief Top level AST file containing the imported PCH, module or submodule.
5896 */
5897 CXFile file;
5898 /**
5899 * \brief The imported module or NULL if the AST file is a PCH.
5900 */
5901 CXModule module;
5902 /**
5903 * \brief Location where the file is imported. Applicable only for modules.
5904 */
5905 CXIdxLoc loc;
5906 /**
5907 * \brief Non-zero if an inclusion directive was automatically turned into
5908 * a module import. Applicable only for modules.
5909 */
5910 int isImplicit;
5911
5912} CXIdxImportedASTFileInfo;
5913
5914typedef enum {
5915 CXIdxEntity_Unexposed = 0,
5916 CXIdxEntity_Typedef = 1,
5917 CXIdxEntity_Function = 2,
5918 CXIdxEntity_Variable = 3,
5919 CXIdxEntity_Field = 4,
5920 CXIdxEntity_EnumConstant = 5,
5921
5922 CXIdxEntity_ObjCClass = 6,
5923 CXIdxEntity_ObjCProtocol = 7,
5924 CXIdxEntity_ObjCCategory = 8,
5925
5926 CXIdxEntity_ObjCInstanceMethod = 9,
5927 CXIdxEntity_ObjCClassMethod = 10,
5928 CXIdxEntity_ObjCProperty = 11,
5929 CXIdxEntity_ObjCIvar = 12,
5930
5931 CXIdxEntity_Enum = 13,
5932 CXIdxEntity_Struct = 14,
5933 CXIdxEntity_Union = 15,
5934
5935 CXIdxEntity_CXXClass = 16,
5936 CXIdxEntity_CXXNamespace = 17,
5937 CXIdxEntity_CXXNamespaceAlias = 18,
5938 CXIdxEntity_CXXStaticVariable = 19,
5939 CXIdxEntity_CXXStaticMethod = 20,
5940 CXIdxEntity_CXXInstanceMethod = 21,
5941 CXIdxEntity_CXXConstructor = 22,
5942 CXIdxEntity_CXXDestructor = 23,
5943 CXIdxEntity_CXXConversionFunction = 24,
5944 CXIdxEntity_CXXTypeAlias = 25,
5945 CXIdxEntity_CXXInterface = 26
5946
5947} CXIdxEntityKind;
5948
5949typedef enum {
5950 CXIdxEntityLang_None = 0,
5951 CXIdxEntityLang_C = 1,
5952 CXIdxEntityLang_ObjC = 2,
5953 CXIdxEntityLang_CXX = 3,
5954 CXIdxEntityLang_Swift = 4
5955} CXIdxEntityLanguage;
5956
5957/**
5958 * \brief Extra C++ template information for an entity. This can apply to:
5959 * CXIdxEntity_Function
5960 * CXIdxEntity_CXXClass
5961 * CXIdxEntity_CXXStaticMethod
5962 * CXIdxEntity_CXXInstanceMethod
5963 * CXIdxEntity_CXXConstructor
5964 * CXIdxEntity_CXXConversionFunction
5965 * CXIdxEntity_CXXTypeAlias
5966 */
5967typedef enum {
5968 CXIdxEntity_NonTemplate = 0,
5969 CXIdxEntity_Template = 1,
5970 CXIdxEntity_TemplatePartialSpecialization = 2,
5971 CXIdxEntity_TemplateSpecialization = 3
5972} CXIdxEntityCXXTemplateKind;
5973
5974typedef enum {
5975 CXIdxAttr_Unexposed = 0,
5976 CXIdxAttr_IBAction = 1,
5977 CXIdxAttr_IBOutlet = 2,
5978 CXIdxAttr_IBOutletCollection = 3
5979} CXIdxAttrKind;
5980
5981typedef struct {
5982 CXIdxAttrKind kind;
5983 CXCursor cursor;
5984 CXIdxLoc loc;
5985} CXIdxAttrInfo;
5986
5987typedef struct {
5988 CXIdxEntityKind kind;
5989 CXIdxEntityCXXTemplateKind templateKind;
5990 CXIdxEntityLanguage lang;
5991 const char *name;
5992 const char *USR;
5993 CXCursor cursor;
5994 const CXIdxAttrInfo *const *attributes;
5995 unsigned numAttributes;
5996} CXIdxEntityInfo;
5997
5998typedef struct {
5999 CXCursor cursor;
6000} CXIdxContainerInfo;
6001
6002typedef struct {
6003 const CXIdxAttrInfo *attrInfo;
6004 const CXIdxEntityInfo *objcClass;
6005 CXCursor classCursor;
6006 CXIdxLoc classLoc;
6007} CXIdxIBOutletCollectionAttrInfo;
6008
6009typedef enum {
6010 CXIdxDeclFlag_Skipped = 0x1
6011} CXIdxDeclInfoFlags;
6012
6013typedef struct {
6014 const CXIdxEntityInfo *entityInfo;
6015 CXCursor cursor;
6016 CXIdxLoc loc;
6017 const CXIdxContainerInfo *semanticContainer;
6018 /**
6019 * \brief Generally same as #semanticContainer but can be different in
6020 * cases like out-of-line C++ member functions.
6021 */
6022 const CXIdxContainerInfo *lexicalContainer;
6023 int isRedeclaration;
6024 int isDefinition;
6025 int isContainer;
6026 const CXIdxContainerInfo *declAsContainer;
6027 /**
6028 * \brief Whether the declaration exists in code or was created implicitly
6029 * by the compiler, e.g. implicit Objective-C methods for properties.
6030 */
6031 int isImplicit;
6032 const CXIdxAttrInfo *const *attributes;
6033 unsigned numAttributes;
6034
6035 unsigned flags;
6036
6037} CXIdxDeclInfo;
6038
6039typedef enum {
6040 CXIdxObjCContainer_ForwardRef = 0,
6041 CXIdxObjCContainer_Interface = 1,
6042 CXIdxObjCContainer_Implementation = 2
6043} CXIdxObjCContainerKind;
6044
6045typedef struct {
6046 const CXIdxDeclInfo *declInfo;
6047 CXIdxObjCContainerKind kind;
6048} CXIdxObjCContainerDeclInfo;
6049
6050typedef struct {
6051 const CXIdxEntityInfo *base;
6052 CXCursor cursor;
6053 CXIdxLoc loc;
6054} CXIdxBaseClassInfo;
6055
6056typedef struct {
6057 const CXIdxEntityInfo *protocol;
6058 CXCursor cursor;
6059 CXIdxLoc loc;
6060} CXIdxObjCProtocolRefInfo;
6061
6062typedef struct {
6063 const CXIdxObjCProtocolRefInfo *const *protocols;
6064 unsigned numProtocols;
6065} CXIdxObjCProtocolRefListInfo;
6066
6067typedef struct {
6068 const CXIdxObjCContainerDeclInfo *containerInfo;
6069 const CXIdxBaseClassInfo *superInfo;
6070 const CXIdxObjCProtocolRefListInfo *protocols;
6071} CXIdxObjCInterfaceDeclInfo;
6072
6073typedef struct {
6074 const CXIdxObjCContainerDeclInfo *containerInfo;
6075 const CXIdxEntityInfo *objcClass;
6076 CXCursor classCursor;
6077 CXIdxLoc classLoc;
6078 const CXIdxObjCProtocolRefListInfo *protocols;
6079} CXIdxObjCCategoryDeclInfo;
6080
6081typedef struct {
6082 const CXIdxDeclInfo *declInfo;
6083 const CXIdxEntityInfo *getter;
6084 const CXIdxEntityInfo *setter;
6085} CXIdxObjCPropertyDeclInfo;
6086
6087typedef struct {
6088 const CXIdxDeclInfo *declInfo;
6089 const CXIdxBaseClassInfo *const *bases;
6090 unsigned numBases;
6091} CXIdxCXXClassDeclInfo;
6092
6093/**
6094 * \brief Data for IndexerCallbacks#indexEntityReference.
6095 *
6096 * This may be deprecated in a future version as this duplicates
6097 * the \c CXSymbolRole_Implicit bit in \c CXSymbolRole.
6098 */
6099typedef enum {
6100 /**
6101 * \brief The entity is referenced directly in user's code.
6102 */
6103 CXIdxEntityRef_Direct = 1,
6104 /**
6105 * \brief An implicit reference, e.g. a reference of an Objective-C method
6106 * via the dot syntax.
6107 */
6108 CXIdxEntityRef_Implicit = 2
6109} CXIdxEntityRefKind;
6110
6111/**
6112 * \brief Roles that are attributed to symbol occurrences.
6113 *
6114 * Internal: this currently mirrors low 9 bits of clang::index::SymbolRole with
6115 * higher bits zeroed. These high bits may be exposed in the future.
6116 */
6117typedef enum {
6118 CXSymbolRole_None = 0,
6119 CXSymbolRole_Declaration = 1 << 0,
6120 CXSymbolRole_Definition = 1 << 1,
6121 CXSymbolRole_Reference = 1 << 2,
6122 CXSymbolRole_Read = 1 << 3,
6123 CXSymbolRole_Write = 1 << 4,
6124 CXSymbolRole_Call = 1 << 5,
6125 CXSymbolRole_Dynamic = 1 << 6,
6126 CXSymbolRole_AddressOf = 1 << 7,
6127 CXSymbolRole_Implicit = 1 << 8
6128} CXSymbolRole;
6129
6130/**
6131 * \brief Data for IndexerCallbacks#indexEntityReference.
6132 */
6133typedef struct {
6134 CXIdxEntityRefKind kind;
6135 /**
6136 * \brief Reference cursor.
6137 */
6138 CXCursor cursor;
6139 CXIdxLoc loc;
6140 /**
6141 * \brief The entity that gets referenced.
6142 */
6143 const CXIdxEntityInfo *referencedEntity;
6144 /**
6145 * \brief Immediate "parent" of the reference. For example:
6146 *
6147 * \code
6148 * Foo *var;
6149 * \endcode
6150 *
6151 * The parent of reference of type 'Foo' is the variable 'var'.
6152 * For references inside statement bodies of functions/methods,
6153 * the parentEntity will be the function/method.
6154 */
6155 const CXIdxEntityInfo *parentEntity;
6156 /**
6157 * \brief Lexical container context of the reference.
6158 */
6159 const CXIdxContainerInfo *container;
6160 /**
6161 * \brief Sets of symbol roles of the reference.
6162 */
6163 CXSymbolRole role;
6164} CXIdxEntityRefInfo;
6165
6166/**
6167 * \brief A group of callbacks used by #clang_indexSourceFile and
6168 * #clang_indexTranslationUnit.
6169 */
6170typedef struct {
6171 /**
6172 * \brief Called periodically to check whether indexing should be aborted.
6173 * Should return 0 to continue, and non-zero to abort.
6174 */
6175 int (*abortQuery)(CXClientData client_data, void *reserved);
6176
6177 /**
6178 * \brief Called at the end of indexing; passes the complete diagnostic set.
6179 */
6180 void (*diagnostic)(CXClientData client_data,
6181 CXDiagnosticSet, void *reserved);
6182
6183 CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
6184 CXFile mainFile, void *reserved);
6185
6186 /**
6187 * \brief Called when a file gets \#included/\#imported.
6188 */
6189 CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
6190 const CXIdxIncludedFileInfo *);
6191
6192 /**
6193 * \brief Called when a AST file (PCH or module) gets imported.
6194 *
6195 * AST files will not get indexed (there will not be callbacks to index all
6196 * the entities in an AST file). The recommended action is that, if the AST
6197 * file is not already indexed, to initiate a new indexing job specific to
6198 * the AST file.
6199 */
6200 CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
6201 const CXIdxImportedASTFileInfo *);
6202
6203 /**
6204 * \brief Called at the beginning of indexing a translation unit.
6205 */
6206 CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
6207 void *reserved);
6208
6209 void (*indexDeclaration)(CXClientData client_data,
6210 const CXIdxDeclInfo *);
6211
6212 /**
6213 * \brief Called to index a reference of an entity.
6214 */
6215 void (*indexEntityReference)(CXClientData client_data,
6216 const CXIdxEntityRefInfo *);
6217
6218} IndexerCallbacks;
6219
6220CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
6221CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
6222clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
6223
6224CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
6225clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
6226
6227CINDEX_LINKAGE
6228const CXIdxObjCCategoryDeclInfo *
6229clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
6230
6231CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
6232clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
6233
6234CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
6235clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
6236
6237CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
6238clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
6239
6240CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
6241clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
6242
6243/**
6244 * \brief For retrieving a custom CXIdxClientContainer attached to a
6245 * container.
6246 */
6247CINDEX_LINKAGE CXIdxClientContainer
6248clang_index_getClientContainer(const CXIdxContainerInfo *);
6249
6250/**
6251 * \brief For setting a custom CXIdxClientContainer attached to a
6252 * container.
6253 */
6254CINDEX_LINKAGE void
6255clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
6256
6257/**
6258 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
6259 */
6260CINDEX_LINKAGE CXIdxClientEntity
6261clang_index_getClientEntity(const CXIdxEntityInfo *);
6262
6263/**
6264 * \brief For setting a custom CXIdxClientEntity attached to an entity.
6265 */
6266CINDEX_LINKAGE void
6267clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
6268
6269/**
6270 * \brief An indexing action/session, to be applied to one or multiple
6271 * translation units.
6272 */
6273typedef void *CXIndexAction;
6274
6275/**
6276 * \brief An indexing action/session, to be applied to one or multiple
6277 * translation units.
6278 *
6279 * \param CIdx The index object with which the index action will be associated.
6280 */
6281CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
6282
6283/**
6284 * \brief Destroy the given index action.
6285 *
6286 * The index action must not be destroyed until all of the translation units
6287 * created within that index action have been destroyed.
6288 */
6289CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
6290
6291typedef enum {
6292 /**
6293 * \brief Used to indicate that no special indexing options are needed.
6294 */
6295 CXIndexOpt_None = 0x0,
6296
6297 /**
6298 * \brief Used to indicate that IndexerCallbacks#indexEntityReference should
6299 * be invoked for only one reference of an entity per source file that does
6300 * not also include a declaration/definition of the entity.
6301 */
6302 CXIndexOpt_SuppressRedundantRefs = 0x1,
6303
6304 /**
6305 * \brief Function-local symbols should be indexed. If this is not set
6306 * function-local symbols will be ignored.
6307 */
6308 CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
6309
6310 /**
6311 * \brief Implicit function/class template instantiations should be indexed.
6312 * If this is not set, implicit instantiations will be ignored.
6313 */
6314 CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4,
6315
6316 /**
6317 * \brief Suppress all compiler warnings when parsing for indexing.
6318 */
6319 CXIndexOpt_SuppressWarnings = 0x8,
6320
6321 /**
6322 * \brief Skip a function/method body that was already parsed during an
6323 * indexing session associated with a \c CXIndexAction object.
6324 * Bodies in system headers are always skipped.
6325 */
6326 CXIndexOpt_SkipParsedBodiesInSession = 0x10
6327
6328} CXIndexOptFlags;
6329
6330/**
6331 * \brief Index the given source file and the translation unit corresponding
6332 * to that file via callbacks implemented through #IndexerCallbacks.
6333 *
6334 * \param client_data pointer data supplied by the client, which will
6335 * be passed to the invoked callbacks.
6336 *
6337 * \param index_callbacks Pointer to indexing callbacks that the client
6338 * implements.
6339 *
6340 * \param index_callbacks_size Size of #IndexerCallbacks structure that gets
6341 * passed in index_callbacks.
6342 *
6343 * \param index_options A bitmask of options that affects how indexing is
6344 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
6345 *
6346 * \param[out] out_TU pointer to store a \c CXTranslationUnit that can be
6347 * reused after indexing is finished. Set to \c NULL if you do not require it.
6348 *
6349 * \returns 0 on success or if there were errors from which the compiler could
6350 * recover. If there is a failure from which there is no recovery, returns
6351 * a non-zero \c CXErrorCode.
6352 *
6353 * The rest of the parameters are the same as #clang_parseTranslationUnit.
6354 */
6355CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
6356 CXClientData client_data,
6357 IndexerCallbacks *index_callbacks,
6358 unsigned index_callbacks_size,
6359 unsigned index_options,
6360 const char *source_filename,
6361 const char * const *command_line_args,
6362 int num_command_line_args,
6363 struct CXUnsavedFile *unsaved_files,
6364 unsigned num_unsaved_files,
6365 CXTranslationUnit *out_TU,
6366 unsigned TU_options);
6367
6368/**
6369 * \brief Same as clang_indexSourceFile but requires a full command line
6370 * for \c command_line_args including argv[0]. This is useful if the standard
6371 * library paths are relative to the binary.
6372 */
6373CINDEX_LINKAGE int clang_indexSourceFileFullArgv(
6374 CXIndexAction, CXClientData client_data, IndexerCallbacks *index_callbacks,
6375 unsigned index_callbacks_size, unsigned index_options,
6376 const char *source_filename, const char *const *command_line_args,
6377 int num_command_line_args, struct CXUnsavedFile *unsaved_files,
6378 unsigned num_unsaved_files, CXTranslationUnit *out_TU, unsigned TU_options);
6379
6380/**
6381 * \brief Index the given translation unit via callbacks implemented through
6382 * #IndexerCallbacks.
6383 *
6384 * The order of callback invocations is not guaranteed to be the same as
6385 * when indexing a source file. The high level order will be:
6386 *
6387 * -Preprocessor callbacks invocations
6388 * -Declaration/reference callbacks invocations
6389 * -Diagnostic callback invocations
6390 *
6391 * The parameters are the same as #clang_indexSourceFile.
6392 *
6393 * \returns If there is a failure from which there is no recovery, returns
6394 * non-zero, otherwise returns 0.
6395 */
6396CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
6397 CXClientData client_data,
6398 IndexerCallbacks *index_callbacks,
6399 unsigned index_callbacks_size,
6400 unsigned index_options,
6401 CXTranslationUnit);
6402
6403/**
6404 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
6405 * the given CXIdxLoc.
6406 *
6407 * If the location refers into a macro expansion, retrieves the
6408 * location of the macro expansion and if it refers into a macro argument
6409 * retrieves the location of the argument.
6410 */
6411CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
6412 CXIdxClientFile *indexFile,
6413 CXFile *file,
6414 unsigned *line,
6415 unsigned *column,
6416 unsigned *offset);
6417
6418/**
6419 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
6420 */
6421CINDEX_LINKAGE
6422CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
6423
6424/**
6425 * \brief Visitor invoked for each field found by a traversal.
6426 *
6427 * This visitor function will be invoked for each field found by
6428 * \c clang_Type_visitFields. Its first argument is the cursor being
6429 * visited, its second argument is the client data provided to
6430 * \c clang_Type_visitFields.
6431 *
6432 * The visitor should return one of the \c CXVisitorResult values
6433 * to direct \c clang_Type_visitFields.
6434 */
6435typedef enum CXVisitorResult (*CXFieldVisitor)(CXCursor C,
6436 CXClientData client_data);
6437
6438/**
6439 * \brief Visit the fields of a particular type.
6440 *
6441 * This function visits all the direct fields of the given cursor,
6442 * invoking the given \p visitor function with the cursors of each
6443 * visited field. The traversal may be ended prematurely, if
6444 * the visitor returns \c CXFieldVisit_Break.
6445 *
6446 * \param T the record type whose field may be visited.
6447 *
6448 * \param visitor the visitor function that will be invoked for each
6449 * field of \p T.
6450 *
6451 * \param client_data pointer data supplied by the client, which will
6452 * be passed to the visitor each time it is invoked.
6453 *
6454 * \returns a non-zero value if the traversal was terminated
6455 * prematurely by the visitor returning \c CXFieldVisit_Break.
6456 */
6457CINDEX_LINKAGE unsigned clang_Type_visitFields(CXType T,
6458 CXFieldVisitor visitor,
6459 CXClientData client_data);
6460
6461/**
6462 * @}
6463 */
6464
6465/**
6466 * @}
6467 */
6468
6469#ifdef __cplusplus
6470}
6471#endif
6472#endif