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