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