Index.h revision 5b419362c29b7aa09d9a75a14fe1b11985625bf0
1/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|*                                                                            *|
3|*                     The LLVM Compiler Infrastructure                       *|
4|*                                                                            *|
5|* This file is distributed under the University of Illinois Open Source      *|
6|* License. See LICENSE.TXT for details.                                      *|
7|*                                                                            *|
8|*===----------------------------------------------------------------------===*|
9|*                                                                            *|
10|* This header provides a public inferface to a Clang library for extracting  *|
11|* high-level symbol information from source files without exposing the full  *|
12|* Clang C++ API.                                                             *|
13|*                                                                            *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
19#include <sys/stat.h>
20#include <time.h>
21#include <stdio.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* MSVC DLL import/export. */
28#ifdef _MSC_VER
29  #ifdef _CINDEX_LIB_
30    #define CINDEX_LINKAGE __declspec(dllexport)
31  #else
32    #define CINDEX_LINKAGE __declspec(dllimport)
33  #endif
34#else
35  #define CINDEX_LINKAGE
36#endif
37
38/** \defgroup CINDEX libclang: C Interface to Clang
39 *
40 * The C Interface to Clang provides a relatively small API that exposes
41 * facilities for parsing source code into an abstract syntax tree (AST),
42 * loading already-parsed ASTs, traversing the AST, associating
43 * physical source locations with elements within the AST, and other
44 * facilities that support Clang-based development tools.
45 *
46 * This C interface to Clang will never provide all of the information
47 * representation stored in Clang's C++ AST, nor should it: the intent is to
48 * maintain an API that is relatively stable from one release to the next,
49 * providing only the basic functionality needed to support development tools.
50 *
51 * To avoid namespace pollution, data types are prefixed with "CX" and
52 * functions are prefixed with "clang_".
53 *
54 * @{
55 */
56
57/**
58 * \brief An "index" that consists of a set of translation units that would
59 * typically be linked together into an executable or library.
60 */
61typedef void *CXIndex;
62
63/**
64 * \brief A single translation unit, which resides in an index.
65 */
66typedef struct CXTranslationUnitImpl *CXTranslationUnit;
67
68/**
69 * \brief Opaque pointer representing client data that will be passed through
70 * to various callbacks and visitors.
71 */
72typedef void *CXClientData;
73
74/**
75 * \brief Provides the contents of a file that has not yet been saved to disk.
76 *
77 * Each CXUnsavedFile instance provides the name of a file on the
78 * system along with the current contents of that file that have not
79 * yet been saved to disk.
80 */
81struct CXUnsavedFile {
82  /**
83   * \brief The file whose contents have not yet been saved.
84   *
85   * This file must already exist in the file system.
86   */
87  const char *Filename;
88
89  /**
90   * \brief A buffer containing the unsaved contents of this file.
91   */
92  const char *Contents;
93
94  /**
95   * \brief The length of the unsaved contents of this buffer.
96   */
97  unsigned long Length;
98};
99
100/**
101 * \brief Describes the availability of a particular entity, which indicates
102 * whether the use of this entity will result in a warning or error due to
103 * it being deprecated or unavailable.
104 */
105enum CXAvailabilityKind {
106  /**
107   * \brief The entity is available.
108   */
109  CXAvailability_Available,
110  /**
111   * \brief The entity is available, but has been deprecated (and its use is
112   * not recommended).
113   */
114  CXAvailability_Deprecated,
115  /**
116   * \brief The entity is not available; any use of it will be an error.
117   */
118  CXAvailability_NotAvailable,
119  /**
120   * \brief The entity is available, but not accessible; any use of it will be
121   * an error.
122   */
123  CXAvailability_NotAccessible
124};
125
126/**
127 * \defgroup CINDEX_STRING String manipulation routines
128 *
129 * @{
130 */
131
132/**
133 * \brief A character string.
134 *
135 * The \c CXString type is used to return strings from the interface when
136 * the ownership of that string might different from one call to the next.
137 * Use \c clang_getCString() to retrieve the string data and, once finished
138 * with the string data, call \c clang_disposeString() to free the string.
139 */
140typedef struct {
141  void *data;
142  unsigned private_flags;
143} CXString;
144
145/**
146 * \brief Retrieve the character data associated with the given string.
147 */
148CINDEX_LINKAGE const char *clang_getCString(CXString string);
149
150/**
151 * \brief Free the given string,
152 */
153CINDEX_LINKAGE void clang_disposeString(CXString string);
154
155/**
156 * @}
157 */
158
159/**
160 * \brief clang_createIndex() provides a shared context for creating
161 * translation units. It provides two options:
162 *
163 * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
164 * declarations (when loading any new translation units). A "local" declaration
165 * is one that belongs in the translation unit itself and not in a precompiled
166 * header that was used by the translation unit. If zero, all declarations
167 * will be enumerated.
168 *
169 * Here is an example:
170 *
171 *   // excludeDeclsFromPCH = 1, displayDiagnostics=1
172 *   Idx = clang_createIndex(1, 1);
173 *
174 *   // IndexTest.pch was produced with the following command:
175 *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
176 *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
177 *
178 *   // This will load all the symbols from 'IndexTest.pch'
179 *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
180 *                       TranslationUnitVisitor, 0);
181 *   clang_disposeTranslationUnit(TU);
182 *
183 *   // This will load all the symbols from 'IndexTest.c', excluding symbols
184 *   // from 'IndexTest.pch'.
185 *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
186 *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args,
187 *                                                  0, 0);
188 *   clang_visitChildren(clang_getTranslationUnitCursor(TU),
189 *                       TranslationUnitVisitor, 0);
190 *   clang_disposeTranslationUnit(TU);
191 *
192 * This process of creating the 'pch', loading it separately, and using it (via
193 * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
194 * (which gives the indexer the same performance benefit as the compiler).
195 */
196CINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
197                                         int displayDiagnostics);
198
199/**
200 * \brief Destroy the given index.
201 *
202 * The index must not be destroyed until all of the translation units created
203 * within that index have been destroyed.
204 */
205CINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
206
207/**
208 * \defgroup CINDEX_FILES File manipulation routines
209 *
210 * @{
211 */
212
213/**
214 * \brief A particular source file that is part of a translation unit.
215 */
216typedef void *CXFile;
217
218
219/**
220 * \brief Retrieve the complete file and path name of the given file.
221 */
222CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
223
224/**
225 * \brief Retrieve the last modification time of the given file.
226 */
227CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
228
229/**
230 * \brief Determine whether the given header is guarded against
231 * multiple inclusions, either with the conventional
232 * #ifndef/#define/#endif macro guards or with #pragma once.
233 */
234CINDEX_LINKAGE unsigned
235clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
236
237/**
238 * \brief Retrieve a file handle within the given translation unit.
239 *
240 * \param tu the translation unit
241 *
242 * \param file_name the name of the file.
243 *
244 * \returns the file handle for the named file in the translation unit \p tu,
245 * or a NULL file handle if the file was not a part of this translation unit.
246 */
247CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
248                                    const char *file_name);
249
250/**
251 * @}
252 */
253
254/**
255 * \defgroup CINDEX_LOCATIONS Physical source locations
256 *
257 * Clang represents physical source locations in its abstract syntax tree in
258 * great detail, with file, line, and column information for the majority of
259 * the tokens parsed in the source code. These data types and functions are
260 * used to represent source location information, either for a particular
261 * point in the program or for a range of points in the program, and extract
262 * specific location information from those data types.
263 *
264 * @{
265 */
266
267/**
268 * \brief Identifies a specific source location within a translation
269 * unit.
270 *
271 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
272 * to map a source location to a particular file, line, and column.
273 */
274typedef struct {
275  void *ptr_data[2];
276  unsigned int_data;
277} CXSourceLocation;
278
279/**
280 * \brief Identifies a half-open character range in the source code.
281 *
282 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
283 * starting and end locations from a source range, respectively.
284 */
285typedef struct {
286  void *ptr_data[2];
287  unsigned begin_int_data;
288  unsigned end_int_data;
289} CXSourceRange;
290
291/**
292 * \brief Retrieve a NULL (invalid) source location.
293 */
294CINDEX_LINKAGE CXSourceLocation clang_getNullLocation();
295
296/**
297 * \determine Determine whether two source locations, which must refer into
298 * the same translation unit, refer to exactly the same point in the source
299 * code.
300 *
301 * \returns non-zero if the source locations refer to the same location, zero
302 * if they refer to different locations.
303 */
304CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
305                                             CXSourceLocation loc2);
306
307/**
308 * \brief Retrieves the source location associated with a given file/line/column
309 * in a particular translation unit.
310 */
311CINDEX_LINKAGE CXSourceLocation clang_getLocation(CXTranslationUnit tu,
312                                                  CXFile file,
313                                                  unsigned line,
314                                                  unsigned column);
315/**
316 * \brief Retrieves the source location associated with a given character offset
317 * in a particular translation unit.
318 */
319CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
320                                                           CXFile file,
321                                                           unsigned offset);
322
323/**
324 * \brief Retrieve a NULL (invalid) source range.
325 */
326CINDEX_LINKAGE CXSourceRange clang_getNullRange();
327
328/**
329 * \brief Retrieve a source range given the beginning and ending source
330 * locations.
331 */
332CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
333                                            CXSourceLocation end);
334
335/**
336 * \brief Determine whether two ranges are equivalent.
337 *
338 * \returns non-zero if the ranges are the same, zero if they differ.
339 */
340CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
341                                          CXSourceRange range2);
342
343/**
344 * \brief Returns non-zero if \arg range is null.
345 */
346CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
347
348/**
349 * \brief Retrieve the file, line, column, and offset represented by
350 * the given source location.
351 *
352 * If the location refers into a macro expansion, retrieves the
353 * location of the macro expansion.
354 *
355 * \param location the location within a source file that will be decomposed
356 * into its parts.
357 *
358 * \param file [out] if non-NULL, will be set to the file to which the given
359 * source location points.
360 *
361 * \param line [out] if non-NULL, will be set to the line to which the given
362 * source location points.
363 *
364 * \param column [out] if non-NULL, will be set to the column to which the given
365 * source location points.
366 *
367 * \param offset [out] if non-NULL, will be set to the offset into the
368 * buffer to which the given source location points.
369 */
370CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
371                                               CXFile *file,
372                                               unsigned *line,
373                                               unsigned *column,
374                                               unsigned *offset);
375
376/**
377 * \brief Retrieve the file, line, column, and offset represented by
378 * the given source location, as specified in a # line directive.
379 *
380 * Example: given the following source code in a file somefile.c
381 *
382 * #123 "dummy.c" 1
383 *
384 * static int func(void)
385 * {
386 *     return 0;
387 * }
388 *
389 * the location information returned by this function would be
390 *
391 * File: dummy.c Line: 124 Column: 12
392 *
393 * whereas clang_getExpansionLocation would have returned
394 *
395 * File: somefile.c Line: 3 Column: 12
396 *
397 * \param location the location within a source file that will be decomposed
398 * into its parts.
399 *
400 * \param filename [out] if non-NULL, will be set to the filename of the
401 * source location. Note that filenames returned will be for "virtual" files,
402 * which don't necessarily exist on the machine running clang - e.g. when
403 * parsing preprocessed output obtained from a different environment. If
404 * a non-NULL value is passed in, remember to dispose of the returned value
405 * using \c clang_disposeString() once you've finished with it. For an invalid
406 * source location, an empty string is returned.
407 *
408 * \param line [out] if non-NULL, will be set to the line number of the
409 * source location. For an invalid source location, zero is returned.
410 *
411 * \param column [out] if non-NULL, will be set to the column number of the
412 * source location. For an invalid source location, zero is returned.
413 */
414CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
415                                              CXString *filename,
416                                              unsigned *line,
417                                              unsigned *column);
418
419/**
420 * \brief Legacy API to retrieve the file, line, column, and offset represented
421 * by the given source location.
422 *
423 * This interface has been replaced by the newer interface
424 * \see clang_getExpansionLocation(). See that interface's documentation for
425 * details.
426 */
427CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
428                                                   CXFile *file,
429                                                   unsigned *line,
430                                                   unsigned *column,
431                                                   unsigned *offset);
432
433/**
434 * \brief Retrieve the file, line, column, and offset represented by
435 * the given source location.
436 *
437 * If the location refers into a macro instantiation, return where the
438 * location was originally spelled in the source file.
439 *
440 * \param location the location within a source file that will be decomposed
441 * into its parts.
442 *
443 * \param file [out] if non-NULL, will be set to the file to which the given
444 * source location points.
445 *
446 * \param line [out] if non-NULL, will be set to the line to which the given
447 * source location points.
448 *
449 * \param column [out] if non-NULL, will be set to the column to which the given
450 * source location points.
451 *
452 * \param offset [out] if non-NULL, will be set to the offset into the
453 * buffer to which the given source location points.
454 */
455CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
456                                              CXFile *file,
457                                              unsigned *line,
458                                              unsigned *column,
459                                              unsigned *offset);
460
461/**
462 * \brief Retrieve a source location representing the first character within a
463 * source range.
464 */
465CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
466
467/**
468 * \brief Retrieve a source location representing the last character within a
469 * source range.
470 */
471CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
472
473/**
474 * @}
475 */
476
477/**
478 * \defgroup CINDEX_DIAG Diagnostic reporting
479 *
480 * @{
481 */
482
483/**
484 * \brief Describes the severity of a particular diagnostic.
485 */
486enum CXDiagnosticSeverity {
487  /**
488   * \brief A diagnostic that has been suppressed, e.g., by a command-line
489   * option.
490   */
491  CXDiagnostic_Ignored = 0,
492
493  /**
494   * \brief This diagnostic is a note that should be attached to the
495   * previous (non-note) diagnostic.
496   */
497  CXDiagnostic_Note    = 1,
498
499  /**
500   * \brief This diagnostic indicates suspicious code that may not be
501   * wrong.
502   */
503  CXDiagnostic_Warning = 2,
504
505  /**
506   * \brief This diagnostic indicates that the code is ill-formed.
507   */
508  CXDiagnostic_Error   = 3,
509
510  /**
511   * \brief This diagnostic indicates that the code is ill-formed such
512   * that future parser recovery is unlikely to produce useful
513   * results.
514   */
515  CXDiagnostic_Fatal   = 4
516};
517
518/**
519 * \brief A single diagnostic, containing the diagnostic's severity,
520 * location, text, source ranges, and fix-it hints.
521 */
522typedef void *CXDiagnostic;
523
524/**
525 * \brief A group of CXDiagnostics.
526 */
527typedef void *CXDiagnosticSet;
528
529/**
530 * \brief Determine the number of diagnostics in a CXDiagnosticSet.
531 */
532CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags);
533
534/**
535 * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet.
536 *
537 * \param Unit the CXDiagnosticSet to query.
538 * \param Index the zero-based diagnostic number to retrieve.
539 *
540 * \returns the requested diagnostic. This diagnostic must be freed
541 * via a call to \c clang_disposeDiagnostic().
542 */
543CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags,
544                                                     unsigned Index);
545
546
547/**
548 * \brief Describes the kind of error that occurred (if any) in a call to
549 * \c clang_loadDiagnostics.
550 */
551enum CXLoadDiag_Error {
552  /**
553   * \brief Indicates that no error occurred.
554   */
555  CXLoadDiag_None = 0,
556
557  /**
558   * \brief Indicates that an unknown error occurred while attempting to
559   * deserialize diagnostics.
560   */
561  CXLoadDiag_Unknown = 1,
562
563  /**
564   * \brief Indicates that the file containing the serialized diagnostics
565   * could not be opened.
566   */
567  CXLoadDiag_CannotLoad = 2,
568
569  /**
570   * \brief Indicates that the serialized diagnostics file is invalid or
571   *  corrupt.
572   */
573  CXLoadDiag_InvalidFile = 3
574};
575
576/**
577 * \brief Deserialize a set of diagnostics from a Clang diagnostics bitcode
578 *  file.
579 *
580 * \param The name of the file to deserialize.
581 * \param A pointer to a enum value recording if there was a problem
582 *        deserializing the diagnostics.
583 * \param A pointer to a CXString for recording the error string
584 *        if the file was not successfully loaded.
585 *
586 * \returns A loaded CXDiagnosticSet if successful, and NULL otherwise.  These
587 *  diagnostics should be released using clang_disposeDiagnosticSet().
588 */
589CINDEX_LINKAGE CXDiagnosticSet clang_loadDiagnostics(const char *file,
590                                                  enum CXLoadDiag_Error *error,
591                                                  CXString *errorString);
592
593/**
594 * \brief Release a CXDiagnosticSet and all of its contained diagnostics.
595 */
596CINDEX_LINKAGE void clang_disposeDiagnosticSet(CXDiagnosticSet Diags);
597
598/**
599 * \brief Retrieve the child diagnostics of a CXDiagnostic.  This
600 *  CXDiagnosticSet does not need to be released by clang_diposeDiagnosticSet.
601 */
602CINDEX_LINKAGE CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic D);
603
604/**
605 * \brief Determine the number of diagnostics produced for the given
606 * translation unit.
607 */
608CINDEX_LINKAGE unsigned clang_getNumDiagnostics(CXTranslationUnit Unit);
609
610/**
611 * \brief Retrieve a diagnostic associated with the given translation unit.
612 *
613 * \param Unit the translation unit to query.
614 * \param Index the zero-based diagnostic number to retrieve.
615 *
616 * \returns the requested diagnostic. This diagnostic must be freed
617 * via a call to \c clang_disposeDiagnostic().
618 */
619CINDEX_LINKAGE CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit,
620                                                unsigned Index);
621
622/**
623 * \brief Retrieve the complete set of diagnostics associated with a
624 *        translation unit.
625 *
626 * \param Unit the translation unit to query.
627 */
628CINDEX_LINKAGE CXDiagnosticSet
629  clang_getDiagnosticSetFromTU(CXTranslationUnit Unit);
630
631/**
632 * \brief Destroy a diagnostic.
633 */
634CINDEX_LINKAGE void clang_disposeDiagnostic(CXDiagnostic Diagnostic);
635
636/**
637 * \brief Options to control the display of diagnostics.
638 *
639 * The values in this enum are meant to be combined to customize the
640 * behavior of \c clang_displayDiagnostic().
641 */
642enum CXDiagnosticDisplayOptions {
643  /**
644   * \brief Display the source-location information where the
645   * diagnostic was located.
646   *
647   * When set, diagnostics will be prefixed by the file, line, and
648   * (optionally) column to which the diagnostic refers. For example,
649   *
650   * \code
651   * test.c:28: warning: extra tokens at end of #endif directive
652   * \endcode
653   *
654   * This option corresponds to the clang flag \c -fshow-source-location.
655   */
656  CXDiagnostic_DisplaySourceLocation = 0x01,
657
658  /**
659   * \brief If displaying the source-location information of the
660   * diagnostic, also include the column number.
661   *
662   * This option corresponds to the clang flag \c -fshow-column.
663   */
664  CXDiagnostic_DisplayColumn = 0x02,
665
666  /**
667   * \brief If displaying the source-location information of the
668   * diagnostic, also include information about source ranges in a
669   * machine-parsable format.
670   *
671   * This option corresponds to the clang flag
672   * \c -fdiagnostics-print-source-range-info.
673   */
674  CXDiagnostic_DisplaySourceRanges = 0x04,
675
676  /**
677   * \brief Display the option name associated with this diagnostic, if any.
678   *
679   * The option name displayed (e.g., -Wconversion) will be placed in brackets
680   * after the diagnostic text. This option corresponds to the clang flag
681   * \c -fdiagnostics-show-option.
682   */
683  CXDiagnostic_DisplayOption = 0x08,
684
685  /**
686   * \brief Display the category number associated with this diagnostic, if any.
687   *
688   * The category number is displayed within brackets after the diagnostic text.
689   * This option corresponds to the clang flag
690   * \c -fdiagnostics-show-category=id.
691   */
692  CXDiagnostic_DisplayCategoryId = 0x10,
693
694  /**
695   * \brief Display the category name associated with this diagnostic, if any.
696   *
697   * The category name is displayed within brackets after the diagnostic text.
698   * This option corresponds to the clang flag
699   * \c -fdiagnostics-show-category=name.
700   */
701  CXDiagnostic_DisplayCategoryName = 0x20
702};
703
704/**
705 * \brief Format the given diagnostic in a manner that is suitable for display.
706 *
707 * This routine will format the given diagnostic to a string, rendering
708 * the diagnostic according to the various options given. The
709 * \c clang_defaultDiagnosticDisplayOptions() function returns the set of
710 * options that most closely mimics the behavior of the clang compiler.
711 *
712 * \param Diagnostic The diagnostic to print.
713 *
714 * \param Options A set of options that control the diagnostic display,
715 * created by combining \c CXDiagnosticDisplayOptions values.
716 *
717 * \returns A new string containing for formatted diagnostic.
718 */
719CINDEX_LINKAGE CXString clang_formatDiagnostic(CXDiagnostic Diagnostic,
720                                               unsigned Options);
721
722/**
723 * \brief Retrieve the set of display options most similar to the
724 * default behavior of the clang compiler.
725 *
726 * \returns A set of display options suitable for use with \c
727 * clang_displayDiagnostic().
728 */
729CINDEX_LINKAGE unsigned clang_defaultDiagnosticDisplayOptions(void);
730
731/**
732 * \brief Determine the severity of the given diagnostic.
733 */
734CINDEX_LINKAGE enum CXDiagnosticSeverity
735clang_getDiagnosticSeverity(CXDiagnostic);
736
737/**
738 * \brief Retrieve the source location of the given diagnostic.
739 *
740 * This location is where Clang would print the caret ('^') when
741 * displaying the diagnostic on the command line.
742 */
743CINDEX_LINKAGE CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic);
744
745/**
746 * \brief Retrieve the text of the given diagnostic.
747 */
748CINDEX_LINKAGE CXString clang_getDiagnosticSpelling(CXDiagnostic);
749
750/**
751 * \brief Retrieve the name of the command-line option that enabled this
752 * diagnostic.
753 *
754 * \param Diag The diagnostic to be queried.
755 *
756 * \param Disable If non-NULL, will be set to the option that disables this
757 * diagnostic (if any).
758 *
759 * \returns A string that contains the command-line option used to enable this
760 * warning, such as "-Wconversion" or "-pedantic".
761 */
762CINDEX_LINKAGE CXString clang_getDiagnosticOption(CXDiagnostic Diag,
763                                                  CXString *Disable);
764
765/**
766 * \brief Retrieve the category number for this diagnostic.
767 *
768 * Diagnostics can be categorized into groups along with other, related
769 * diagnostics (e.g., diagnostics under the same warning flag). This routine
770 * retrieves the category number for the given diagnostic.
771 *
772 * \returns The number of the category that contains this diagnostic, or zero
773 * if this diagnostic is uncategorized.
774 */
775CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
776
777/**
778 * \brief Retrieve the name of a particular diagnostic category.
779 *
780 * \param Category A diagnostic category number, as returned by
781 * \c clang_getDiagnosticCategory().
782 *
783 * \returns The name of the given diagnostic category.
784 */
785CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
786
787/**
788 * \brief Determine the number of source ranges associated with the given
789 * diagnostic.
790 */
791CINDEX_LINKAGE unsigned clang_getDiagnosticNumRanges(CXDiagnostic);
792
793/**
794 * \brief Retrieve a source range associated with the diagnostic.
795 *
796 * A diagnostic's source ranges highlight important elements in the source
797 * code. On the command line, Clang displays source ranges by
798 * underlining them with '~' characters.
799 *
800 * \param Diagnostic the diagnostic whose range is being extracted.
801 *
802 * \param Range the zero-based index specifying which range to
803 *
804 * \returns the requested source range.
805 */
806CINDEX_LINKAGE CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diagnostic,
807                                                      unsigned Range);
808
809/**
810 * \brief Determine the number of fix-it hints associated with the
811 * given diagnostic.
812 */
813CINDEX_LINKAGE unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diagnostic);
814
815/**
816 * \brief Retrieve the replacement information for a given fix-it.
817 *
818 * Fix-its are described in terms of a source range whose contents
819 * should be replaced by a string. This approach generalizes over
820 * three kinds of operations: removal of source code (the range covers
821 * the code to be removed and the replacement string is empty),
822 * replacement of source code (the range covers the code to be
823 * replaced and the replacement string provides the new code), and
824 * insertion (both the start and end of the range point at the
825 * insertion location, and the replacement string provides the text to
826 * insert).
827 *
828 * \param Diagnostic The diagnostic whose fix-its are being queried.
829 *
830 * \param FixIt The zero-based index of the fix-it.
831 *
832 * \param ReplacementRange The source range whose contents will be
833 * replaced with the returned replacement string. Note that source
834 * ranges are half-open ranges [a, b), so the source code should be
835 * replaced from a and up to (but not including) b.
836 *
837 * \returns A string containing text that should be replace the source
838 * code indicated by the \c ReplacementRange.
839 */
840CINDEX_LINKAGE CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic,
841                                                 unsigned FixIt,
842                                               CXSourceRange *ReplacementRange);
843
844/**
845 * @}
846 */
847
848/**
849 * \defgroup CINDEX_TRANSLATION_UNIT Translation unit manipulation
850 *
851 * The routines in this group provide the ability to create and destroy
852 * translation units from files, either by parsing the contents of the files or
853 * by reading in a serialized representation of a translation unit.
854 *
855 * @{
856 */
857
858/**
859 * \brief Get the original translation unit source file name.
860 */
861CINDEX_LINKAGE CXString
862clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
863
864/**
865 * \brief Return the CXTranslationUnit for a given source file and the provided
866 * command line arguments one would pass to the compiler.
867 *
868 * Note: The 'source_filename' argument is optional.  If the caller provides a
869 * NULL pointer, the name of the source file is expected to reside in the
870 * specified command line arguments.
871 *
872 * Note: When encountered in 'clang_command_line_args', the following options
873 * are ignored:
874 *
875 *   '-c'
876 *   '-emit-ast'
877 *   '-fsyntax-only'
878 *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
879 *
880 * \param CIdx The index object with which the translation unit will be
881 * associated.
882 *
883 * \param source_filename - The name of the source file to load, or NULL if the
884 * source file is included in \p clang_command_line_args.
885 *
886 * \param num_clang_command_line_args The number of command-line arguments in
887 * \p clang_command_line_args.
888 *
889 * \param clang_command_line_args The command-line arguments that would be
890 * passed to the \c clang executable if it were being invoked out-of-process.
891 * These command-line options will be parsed and will affect how the translation
892 * unit is parsed. Note that the following options are ignored: '-c',
893 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
894 *
895 * \param num_unsaved_files the number of unsaved file entries in \p
896 * unsaved_files.
897 *
898 * \param unsaved_files the files that have not yet been saved to disk
899 * but may be required for code completion, including the contents of
900 * those files.  The contents and name of these files (as specified by
901 * CXUnsavedFile) are copied when necessary, so the client only needs to
902 * guarantee their validity until the call to this function returns.
903 */
904CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
905                                         CXIndex CIdx,
906                                         const char *source_filename,
907                                         int num_clang_command_line_args,
908                                   const char * const *clang_command_line_args,
909                                         unsigned num_unsaved_files,
910                                         struct CXUnsavedFile *unsaved_files);
911
912/**
913 * \brief Create a translation unit from an AST file (-emit-ast).
914 */
915CINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(CXIndex,
916                                             const char *ast_filename);
917
918/**
919 * \brief Flags that control the creation of translation units.
920 *
921 * The enumerators in this enumeration type are meant to be bitwise
922 * ORed together to specify which options should be used when
923 * constructing the translation unit.
924 */
925enum CXTranslationUnit_Flags {
926  /**
927   * \brief Used to indicate that no special translation-unit options are
928   * needed.
929   */
930  CXTranslationUnit_None = 0x0,
931
932  /**
933   * \brief Used to indicate that the parser should construct a "detailed"
934   * preprocessing record, including all macro definitions and instantiations.
935   *
936   * Constructing a detailed preprocessing record requires more memory
937   * and time to parse, since the information contained in the record
938   * is usually not retained. However, it can be useful for
939   * applications that require more detailed information about the
940   * behavior of the preprocessor.
941   */
942  CXTranslationUnit_DetailedPreprocessingRecord = 0x01,
943
944  /**
945   * \brief Used to indicate that the translation unit is incomplete.
946   *
947   * When a translation unit is considered "incomplete", semantic
948   * analysis that is typically performed at the end of the
949   * translation unit will be suppressed. For example, this suppresses
950   * the completion of tentative declarations in C and of
951   * instantiation of implicitly-instantiation function templates in
952   * C++. This option is typically used when parsing a header with the
953   * intent of producing a precompiled header.
954   */
955  CXTranslationUnit_Incomplete = 0x02,
956
957  /**
958   * \brief Used to indicate that the translation unit should be built with an
959   * implicit precompiled header for the preamble.
960   *
961   * An implicit precompiled header is used as an optimization when a
962   * particular translation unit is likely to be reparsed many times
963   * when the sources aren't changing that often. In this case, an
964   * implicit precompiled header will be built containing all of the
965   * initial includes at the top of the main file (what we refer to as
966   * the "preamble" of the file). In subsequent parses, if the
967   * preamble or the files in it have not changed, \c
968   * clang_reparseTranslationUnit() will re-use the implicit
969   * precompiled header to improve parsing performance.
970   */
971  CXTranslationUnit_PrecompiledPreamble = 0x04,
972
973  /**
974   * \brief Used to indicate that the translation unit should cache some
975   * code-completion results with each reparse of the source file.
976   *
977   * Caching of code-completion results is a performance optimization that
978   * introduces some overhead to reparsing but improves the performance of
979   * code-completion operations.
980   */
981  CXTranslationUnit_CacheCompletionResults = 0x08,
982  /**
983   * \brief DEPRECATED: Enable precompiled preambles in C++.
984   *
985   * Note: this is a *temporary* option that is available only while
986   * we are testing C++ precompiled preamble support. It is deprecated.
987   */
988  CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
989
990  /**
991   * \brief DEPRECATED: Enabled chained precompiled preambles in C++.
992   *
993   * Note: this is a *temporary* option that is available only while
994   * we are testing C++ precompiled preamble support. It is deprecated.
995   */
996  CXTranslationUnit_CXXChainedPCH = 0x20,
997
998  /**
999   * \brief Used to indicate that the "detailed" preprocessing record,
1000   * if requested, should also contain nested macro expansions.
1001   *
1002   * Nested macro expansions (i.e., macro expansions that occur
1003   * inside another macro expansion) can, in some code bases, require
1004   * a large amount of storage to due preprocessor metaprogramming. Moreover,
1005   * its fairly rare that this information is useful for libclang clients.
1006   */
1007  CXTranslationUnit_NestedMacroExpansions = 0x40,
1008
1009  /**
1010   * \brief Legacy name to indicate that the "detailed" preprocessing record,
1011   * if requested, should contain nested macro expansions.
1012   *
1013   * \see CXTranslationUnit_NestedMacroExpansions for the current name for this
1014   * value, and its semantics. This is just an alias.
1015   */
1016  CXTranslationUnit_NestedMacroInstantiations =
1017    CXTranslationUnit_NestedMacroExpansions
1018};
1019
1020/**
1021 * \brief Returns the set of flags that is suitable for parsing a translation
1022 * unit that is being edited.
1023 *
1024 * The set of flags returned provide options for \c clang_parseTranslationUnit()
1025 * to indicate that the translation unit is likely to be reparsed many times,
1026 * either explicitly (via \c clang_reparseTranslationUnit()) or implicitly
1027 * (e.g., by code completion (\c clang_codeCompletionAt())). The returned flag
1028 * set contains an unspecified set of optimizations (e.g., the precompiled
1029 * preamble) geared toward improving the performance of these routines. The
1030 * set of optimizations enabled may change from one version to the next.
1031 */
1032CINDEX_LINKAGE unsigned clang_defaultEditingTranslationUnitOptions(void);
1033
1034/**
1035 * \brief Parse the given source file and the translation unit corresponding
1036 * to that file.
1037 *
1038 * This routine is the main entry point for the Clang C API, providing the
1039 * ability to parse a source file into a translation unit that can then be
1040 * queried by other functions in the API. This routine accepts a set of
1041 * command-line arguments so that the compilation can be configured in the same
1042 * way that the compiler is configured on the command line.
1043 *
1044 * \param CIdx The index object with which the translation unit will be
1045 * associated.
1046 *
1047 * \param source_filename The name of the source file to load, or NULL if the
1048 * source file is included in \p command_line_args.
1049 *
1050 * \param command_line_args The command-line arguments that would be
1051 * passed to the \c clang executable if it were being invoked out-of-process.
1052 * These command-line options will be parsed and will affect how the translation
1053 * unit is parsed. Note that the following options are ignored: '-c',
1054 * '-emit-ast', '-fsyntex-only' (which is the default), and '-o <output file>'.
1055 *
1056 * \param num_command_line_args The number of command-line arguments in
1057 * \p command_line_args.
1058 *
1059 * \param unsaved_files the files that have not yet been saved to disk
1060 * but may be required for parsing, including the contents of
1061 * those files.  The contents and name of these files (as specified by
1062 * CXUnsavedFile) are copied when necessary, so the client only needs to
1063 * guarantee their validity until the call to this function returns.
1064 *
1065 * \param num_unsaved_files the number of unsaved file entries in \p
1066 * unsaved_files.
1067 *
1068 * \param options A bitmask of options that affects how the translation unit
1069 * is managed but not its compilation. This should be a bitwise OR of the
1070 * CXTranslationUnit_XXX flags.
1071 *
1072 * \returns A new translation unit describing the parsed code and containing
1073 * any diagnostics produced by the compiler. If there is a failure from which
1074 * the compiler cannot recover, returns NULL.
1075 */
1076CINDEX_LINKAGE CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
1077                                                    const char *source_filename,
1078                                         const char * const *command_line_args,
1079                                                      int num_command_line_args,
1080                                            struct CXUnsavedFile *unsaved_files,
1081                                                     unsigned num_unsaved_files,
1082                                                            unsigned options);
1083
1084/**
1085 * \brief Flags that control how translation units are saved.
1086 *
1087 * The enumerators in this enumeration type are meant to be bitwise
1088 * ORed together to specify which options should be used when
1089 * saving the translation unit.
1090 */
1091enum CXSaveTranslationUnit_Flags {
1092  /**
1093   * \brief Used to indicate that no special saving options are needed.
1094   */
1095  CXSaveTranslationUnit_None = 0x0
1096};
1097
1098/**
1099 * \brief Returns the set of flags that is suitable for saving a translation
1100 * unit.
1101 *
1102 * The set of flags returned provide options for
1103 * \c clang_saveTranslationUnit() by default. The returned flag
1104 * set contains an unspecified set of options that save translation units with
1105 * the most commonly-requested data.
1106 */
1107CINDEX_LINKAGE unsigned clang_defaultSaveOptions(CXTranslationUnit TU);
1108
1109/**
1110 * \brief Describes the kind of error that occurred (if any) in a call to
1111 * \c clang_saveTranslationUnit().
1112 */
1113enum CXSaveError {
1114  /**
1115   * \brief Indicates that no error occurred while saving a translation unit.
1116   */
1117  CXSaveError_None = 0,
1118
1119  /**
1120   * \brief Indicates that an unknown error occurred while attempting to save
1121   * the file.
1122   *
1123   * This error typically indicates that file I/O failed when attempting to
1124   * write the file.
1125   */
1126  CXSaveError_Unknown = 1,
1127
1128  /**
1129   * \brief Indicates that errors during translation prevented this attempt
1130   * to save the translation unit.
1131   *
1132   * Errors that prevent the translation unit from being saved can be
1133   * extracted using \c clang_getNumDiagnostics() and \c clang_getDiagnostic().
1134   */
1135  CXSaveError_TranslationErrors = 2,
1136
1137  /**
1138   * \brief Indicates that the translation unit to be saved was somehow
1139   * invalid (e.g., NULL).
1140   */
1141  CXSaveError_InvalidTU = 3
1142};
1143
1144/**
1145 * \brief Saves a translation unit into a serialized representation of
1146 * that translation unit on disk.
1147 *
1148 * Any translation unit that was parsed without error can be saved
1149 * into a file. The translation unit can then be deserialized into a
1150 * new \c CXTranslationUnit with \c clang_createTranslationUnit() or,
1151 * if it is an incomplete translation unit that corresponds to a
1152 * header, used as a precompiled header when parsing other translation
1153 * units.
1154 *
1155 * \param TU The translation unit to save.
1156 *
1157 * \param FileName The file to which the translation unit will be saved.
1158 *
1159 * \param options A bitmask of options that affects how the translation unit
1160 * is saved. This should be a bitwise OR of the
1161 * CXSaveTranslationUnit_XXX flags.
1162 *
1163 * \returns A value that will match one of the enumerators of the CXSaveError
1164 * enumeration. Zero (CXSaveError_None) indicates that the translation unit was
1165 * saved successfully, while a non-zero value indicates that a problem occurred.
1166 */
1167CINDEX_LINKAGE int clang_saveTranslationUnit(CXTranslationUnit TU,
1168                                             const char *FileName,
1169                                             unsigned options);
1170
1171/**
1172 * \brief Destroy the specified CXTranslationUnit object.
1173 */
1174CINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
1175
1176/**
1177 * \brief Flags that control the reparsing of translation units.
1178 *
1179 * The enumerators in this enumeration type are meant to be bitwise
1180 * ORed together to specify which options should be used when
1181 * reparsing the translation unit.
1182 */
1183enum CXReparse_Flags {
1184  /**
1185   * \brief Used to indicate that no special reparsing options are needed.
1186   */
1187  CXReparse_None = 0x0
1188};
1189
1190/**
1191 * \brief Returns the set of flags that is suitable for reparsing a translation
1192 * unit.
1193 *
1194 * The set of flags returned provide options for
1195 * \c clang_reparseTranslationUnit() by default. The returned flag
1196 * set contains an unspecified set of optimizations geared toward common uses
1197 * of reparsing. The set of optimizations enabled may change from one version
1198 * to the next.
1199 */
1200CINDEX_LINKAGE unsigned clang_defaultReparseOptions(CXTranslationUnit TU);
1201
1202/**
1203 * \brief Reparse the source files that produced this translation unit.
1204 *
1205 * This routine can be used to re-parse the source files that originally
1206 * created the given translation unit, for example because those source files
1207 * have changed (either on disk or as passed via \p unsaved_files). The
1208 * source code will be reparsed with the same command-line options as it
1209 * was originally parsed.
1210 *
1211 * Reparsing a translation unit invalidates all cursors and source locations
1212 * that refer into that translation unit. This makes reparsing a translation
1213 * unit semantically equivalent to destroying the translation unit and then
1214 * creating a new translation unit with the same command-line arguments.
1215 * However, it may be more efficient to reparse a translation
1216 * unit using this routine.
1217 *
1218 * \param TU The translation unit whose contents will be re-parsed. The
1219 * translation unit must originally have been built with
1220 * \c clang_createTranslationUnitFromSourceFile().
1221 *
1222 * \param num_unsaved_files The number of unsaved file entries in \p
1223 * unsaved_files.
1224 *
1225 * \param unsaved_files The files that have not yet been saved to disk
1226 * but may be required for parsing, including the contents of
1227 * those files.  The contents and name of these files (as specified by
1228 * CXUnsavedFile) are copied when necessary, so the client only needs to
1229 * guarantee their validity until the call to this function returns.
1230 *
1231 * \param options A bitset of options composed of the flags in CXReparse_Flags.
1232 * The function \c clang_defaultReparseOptions() produces a default set of
1233 * options recommended for most uses, based on the translation unit.
1234 *
1235 * \returns 0 if the sources could be reparsed. A non-zero value will be
1236 * returned if reparsing was impossible, such that the translation unit is
1237 * invalid. In such cases, the only valid call for \p TU is
1238 * \c clang_disposeTranslationUnit(TU).
1239 */
1240CINDEX_LINKAGE int clang_reparseTranslationUnit(CXTranslationUnit TU,
1241                                                unsigned num_unsaved_files,
1242                                          struct CXUnsavedFile *unsaved_files,
1243                                                unsigned options);
1244
1245/**
1246  * \brief Categorizes how memory is being used by a translation unit.
1247  */
1248enum CXTUResourceUsageKind {
1249  CXTUResourceUsage_AST = 1,
1250  CXTUResourceUsage_Identifiers = 2,
1251  CXTUResourceUsage_Selectors = 3,
1252  CXTUResourceUsage_GlobalCompletionResults = 4,
1253  CXTUResourceUsage_SourceManagerContentCache = 5,
1254  CXTUResourceUsage_AST_SideTables = 6,
1255  CXTUResourceUsage_SourceManager_Membuffer_Malloc = 7,
1256  CXTUResourceUsage_SourceManager_Membuffer_MMap = 8,
1257  CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc = 9,
1258  CXTUResourceUsage_ExternalASTSource_Membuffer_MMap = 10,
1259  CXTUResourceUsage_Preprocessor = 11,
1260  CXTUResourceUsage_PreprocessingRecord = 12,
1261  CXTUResourceUsage_SourceManager_DataStructures = 13,
1262  CXTUResourceUsage_Preprocessor_HeaderSearch = 14,
1263  CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN = CXTUResourceUsage_AST,
1264  CXTUResourceUsage_MEMORY_IN_BYTES_END =
1265    CXTUResourceUsage_Preprocessor_HeaderSearch,
1266
1267  CXTUResourceUsage_First = CXTUResourceUsage_AST,
1268  CXTUResourceUsage_Last = CXTUResourceUsage_Preprocessor_HeaderSearch
1269};
1270
1271/**
1272  * \brief Returns the human-readable null-terminated C string that represents
1273  *  the name of the memory category.  This string should never be freed.
1274  */
1275CINDEX_LINKAGE
1276const char *clang_getTUResourceUsageName(enum CXTUResourceUsageKind kind);
1277
1278typedef struct CXTUResourceUsageEntry {
1279  /* \brief The memory usage category. */
1280  enum CXTUResourceUsageKind kind;
1281  /* \brief Amount of resources used.
1282      The units will depend on the resource kind. */
1283  unsigned long amount;
1284} CXTUResourceUsageEntry;
1285
1286/**
1287  * \brief The memory usage of a CXTranslationUnit, broken into categories.
1288  */
1289typedef struct CXTUResourceUsage {
1290  /* \brief Private data member, used for queries. */
1291  void *data;
1292
1293  /* \brief The number of entries in the 'entries' array. */
1294  unsigned numEntries;
1295
1296  /* \brief An array of key-value pairs, representing the breakdown of memory
1297            usage. */
1298  CXTUResourceUsageEntry *entries;
1299
1300} CXTUResourceUsage;
1301
1302/**
1303  * \brief Return the memory usage of a translation unit.  This object
1304  *  should be released with clang_disposeCXTUResourceUsage().
1305  */
1306CINDEX_LINKAGE CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU);
1307
1308CINDEX_LINKAGE void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage);
1309
1310/**
1311 * @}
1312 */
1313
1314/**
1315 * \brief Describes the kind of entity that a cursor refers to.
1316 */
1317enum CXCursorKind {
1318  /* Declarations */
1319  /**
1320   * \brief A declaration whose specific kind is not exposed via this
1321   * interface.
1322   *
1323   * Unexposed declarations have the same operations as any other kind
1324   * of declaration; one can extract their location information,
1325   * spelling, find their definitions, etc. However, the specific kind
1326   * of the declaration is not reported.
1327   */
1328  CXCursor_UnexposedDecl                 = 1,
1329  /** \brief A C or C++ struct. */
1330  CXCursor_StructDecl                    = 2,
1331  /** \brief A C or C++ union. */
1332  CXCursor_UnionDecl                     = 3,
1333  /** \brief A C++ class. */
1334  CXCursor_ClassDecl                     = 4,
1335  /** \brief An enumeration. */
1336  CXCursor_EnumDecl                      = 5,
1337  /**
1338   * \brief A field (in C) or non-static data member (in C++) in a
1339   * struct, union, or C++ class.
1340   */
1341  CXCursor_FieldDecl                     = 6,
1342  /** \brief An enumerator constant. */
1343  CXCursor_EnumConstantDecl              = 7,
1344  /** \brief A function. */
1345  CXCursor_FunctionDecl                  = 8,
1346  /** \brief A variable. */
1347  CXCursor_VarDecl                       = 9,
1348  /** \brief A function or method parameter. */
1349  CXCursor_ParmDecl                      = 10,
1350  /** \brief An Objective-C @interface. */
1351  CXCursor_ObjCInterfaceDecl             = 11,
1352  /** \brief An Objective-C @interface for a category. */
1353  CXCursor_ObjCCategoryDecl              = 12,
1354  /** \brief An Objective-C @protocol declaration. */
1355  CXCursor_ObjCProtocolDecl              = 13,
1356  /** \brief An Objective-C @property declaration. */
1357  CXCursor_ObjCPropertyDecl              = 14,
1358  /** \brief An Objective-C instance variable. */
1359  CXCursor_ObjCIvarDecl                  = 15,
1360  /** \brief An Objective-C instance method. */
1361  CXCursor_ObjCInstanceMethodDecl        = 16,
1362  /** \brief An Objective-C class method. */
1363  CXCursor_ObjCClassMethodDecl           = 17,
1364  /** \brief An Objective-C @implementation. */
1365  CXCursor_ObjCImplementationDecl        = 18,
1366  /** \brief An Objective-C @implementation for a category. */
1367  CXCursor_ObjCCategoryImplDecl          = 19,
1368  /** \brief A typedef */
1369  CXCursor_TypedefDecl                   = 20,
1370  /** \brief A C++ class method. */
1371  CXCursor_CXXMethod                     = 21,
1372  /** \brief A C++ namespace. */
1373  CXCursor_Namespace                     = 22,
1374  /** \brief A linkage specification, e.g. 'extern "C"'. */
1375  CXCursor_LinkageSpec                   = 23,
1376  /** \brief A C++ constructor. */
1377  CXCursor_Constructor                   = 24,
1378  /** \brief A C++ destructor. */
1379  CXCursor_Destructor                    = 25,
1380  /** \brief A C++ conversion function. */
1381  CXCursor_ConversionFunction            = 26,
1382  /** \brief A C++ template type parameter. */
1383  CXCursor_TemplateTypeParameter         = 27,
1384  /** \brief A C++ non-type template parameter. */
1385  CXCursor_NonTypeTemplateParameter      = 28,
1386  /** \brief A C++ template template parameter. */
1387  CXCursor_TemplateTemplateParameter     = 29,
1388  /** \brief A C++ function template. */
1389  CXCursor_FunctionTemplate              = 30,
1390  /** \brief A C++ class template. */
1391  CXCursor_ClassTemplate                 = 31,
1392  /** \brief A C++ class template partial specialization. */
1393  CXCursor_ClassTemplatePartialSpecialization = 32,
1394  /** \brief A C++ namespace alias declaration. */
1395  CXCursor_NamespaceAlias                = 33,
1396  /** \brief A C++ using directive. */
1397  CXCursor_UsingDirective                = 34,
1398  /** \brief A C++ using declaration. */
1399  CXCursor_UsingDeclaration              = 35,
1400  /** \brief A C++ alias declaration */
1401  CXCursor_TypeAliasDecl                 = 36,
1402  /** \brief An Objective-C @synthesize definition. */
1403  CXCursor_ObjCSynthesizeDecl            = 37,
1404  /** \brief An Objective-C @dynamic definition. */
1405  CXCursor_ObjCDynamicDecl               = 38,
1406  /** \brief An access specifier. */
1407  CXCursor_CXXAccessSpecifier            = 39,
1408
1409  CXCursor_FirstDecl                     = CXCursor_UnexposedDecl,
1410  CXCursor_LastDecl                      = CXCursor_CXXAccessSpecifier,
1411
1412  /* References */
1413  CXCursor_FirstRef                      = 40, /* Decl references */
1414  CXCursor_ObjCSuperClassRef             = 40,
1415  CXCursor_ObjCProtocolRef               = 41,
1416  CXCursor_ObjCClassRef                  = 42,
1417  /**
1418   * \brief A reference to a type declaration.
1419   *
1420   * A type reference occurs anywhere where a type is named but not
1421   * declared. For example, given:
1422   *
1423   * \code
1424   * typedef unsigned size_type;
1425   * size_type size;
1426   * \endcode
1427   *
1428   * The typedef is a declaration of size_type (CXCursor_TypedefDecl),
1429   * while the type of the variable "size" is referenced. The cursor
1430   * referenced by the type of size is the typedef for size_type.
1431   */
1432  CXCursor_TypeRef                       = 43,
1433  CXCursor_CXXBaseSpecifier              = 44,
1434  /**
1435   * \brief A reference to a class template, function template, template
1436   * template parameter, or class template partial specialization.
1437   */
1438  CXCursor_TemplateRef                   = 45,
1439  /**
1440   * \brief A reference to a namespace or namespace alias.
1441   */
1442  CXCursor_NamespaceRef                  = 46,
1443  /**
1444   * \brief A reference to a member of a struct, union, or class that occurs in
1445   * some non-expression context, e.g., a designated initializer.
1446   */
1447  CXCursor_MemberRef                     = 47,
1448  /**
1449   * \brief A reference to a labeled statement.
1450   *
1451   * This cursor kind is used to describe the jump to "start_over" in the
1452   * goto statement in the following example:
1453   *
1454   * \code
1455   *   start_over:
1456   *     ++counter;
1457   *
1458   *     goto start_over;
1459   * \endcode
1460   *
1461   * A label reference cursor refers to a label statement.
1462   */
1463  CXCursor_LabelRef                      = 48,
1464
1465  /**
1466   * \brief A reference to a set of overloaded functions or function templates
1467   * that has not yet been resolved to a specific function or function template.
1468   *
1469   * An overloaded declaration reference cursor occurs in C++ templates where
1470   * a dependent name refers to a function. For example:
1471   *
1472   * \code
1473   * template<typename T> void swap(T&, T&);
1474   *
1475   * struct X { ... };
1476   * void swap(X&, X&);
1477   *
1478   * template<typename T>
1479   * void reverse(T* first, T* last) {
1480   *   while (first < last - 1) {
1481   *     swap(*first, *--last);
1482   *     ++first;
1483   *   }
1484   * }
1485   *
1486   * struct Y { };
1487   * void swap(Y&, Y&);
1488   * \endcode
1489   *
1490   * Here, the identifier "swap" is associated with an overloaded declaration
1491   * reference. In the template definition, "swap" refers to either of the two
1492   * "swap" functions declared above, so both results will be available. At
1493   * instantiation time, "swap" may also refer to other functions found via
1494   * argument-dependent lookup (e.g., the "swap" function at the end of the
1495   * example).
1496   *
1497   * The functions \c clang_getNumOverloadedDecls() and
1498   * \c clang_getOverloadedDecl() can be used to retrieve the definitions
1499   * referenced by this cursor.
1500   */
1501  CXCursor_OverloadedDeclRef             = 49,
1502
1503  CXCursor_LastRef                       = CXCursor_OverloadedDeclRef,
1504
1505  /* Error conditions */
1506  CXCursor_FirstInvalid                  = 70,
1507  CXCursor_InvalidFile                   = 70,
1508  CXCursor_NoDeclFound                   = 71,
1509  CXCursor_NotImplemented                = 72,
1510  CXCursor_InvalidCode                   = 73,
1511  CXCursor_LastInvalid                   = CXCursor_InvalidCode,
1512
1513  /* Expressions */
1514  CXCursor_FirstExpr                     = 100,
1515
1516  /**
1517   * \brief An expression whose specific kind is not exposed via this
1518   * interface.
1519   *
1520   * Unexposed expressions have the same operations as any other kind
1521   * of expression; one can extract their location information,
1522   * spelling, children, etc. However, the specific kind of the
1523   * expression is not reported.
1524   */
1525  CXCursor_UnexposedExpr                 = 100,
1526
1527  /**
1528   * \brief An expression that refers to some value declaration, such
1529   * as a function, varible, or enumerator.
1530   */
1531  CXCursor_DeclRefExpr                   = 101,
1532
1533  /**
1534   * \brief An expression that refers to a member of a struct, union,
1535   * class, Objective-C class, etc.
1536   */
1537  CXCursor_MemberRefExpr                 = 102,
1538
1539  /** \brief An expression that calls a function. */
1540  CXCursor_CallExpr                      = 103,
1541
1542  /** \brief An expression that sends a message to an Objective-C
1543   object or class. */
1544  CXCursor_ObjCMessageExpr               = 104,
1545
1546  /** \brief An expression that represents a block literal. */
1547  CXCursor_BlockExpr                     = 105,
1548
1549  /** \brief An integer literal.
1550   */
1551  CXCursor_IntegerLiteral                = 106,
1552
1553  /** \brief A floating point number literal.
1554   */
1555  CXCursor_FloatingLiteral               = 107,
1556
1557  /** \brief An imaginary number literal.
1558   */
1559  CXCursor_ImaginaryLiteral              = 108,
1560
1561  /** \brief A string literal.
1562   */
1563  CXCursor_StringLiteral                 = 109,
1564
1565  /** \brief A character literal.
1566   */
1567  CXCursor_CharacterLiteral              = 110,
1568
1569  /** \brief A parenthesized expression, e.g. "(1)".
1570   *
1571   * This AST node is only formed if full location information is requested.
1572   */
1573  CXCursor_ParenExpr                     = 111,
1574
1575  /** \brief This represents the unary-expression's (except sizeof and
1576   * alignof).
1577   */
1578  CXCursor_UnaryOperator                 = 112,
1579
1580  /** \brief [C99 6.5.2.1] Array Subscripting.
1581   */
1582  CXCursor_ArraySubscriptExpr            = 113,
1583
1584  /** \brief A builtin binary operation expression such as "x + y" or
1585   * "x <= y".
1586   */
1587  CXCursor_BinaryOperator                = 114,
1588
1589  /** \brief Compound assignment such as "+=".
1590   */
1591  CXCursor_CompoundAssignOperator        = 115,
1592
1593  /** \brief The ?: ternary operator.
1594   */
1595  CXCursor_ConditionalOperator           = 116,
1596
1597  /** \brief An explicit cast in C (C99 6.5.4) or a C-style cast in C++
1598   * (C++ [expr.cast]), which uses the syntax (Type)expr.
1599   *
1600   * For example: (int)f.
1601   */
1602  CXCursor_CStyleCastExpr                = 117,
1603
1604  /** \brief [C99 6.5.2.5]
1605   */
1606  CXCursor_CompoundLiteralExpr           = 118,
1607
1608  /** \brief Describes an C or C++ initializer list.
1609   */
1610  CXCursor_InitListExpr                  = 119,
1611
1612  /** \brief The GNU address of label extension, representing &&label.
1613   */
1614  CXCursor_AddrLabelExpr                 = 120,
1615
1616  /** \brief This is the GNU Statement Expression extension: ({int X=4; X;})
1617   */
1618  CXCursor_StmtExpr                      = 121,
1619
1620  /** \brief Represents a C11 generic selection.
1621   */
1622  CXCursor_GenericSelectionExpr          = 122,
1623
1624  /** \brief Implements the GNU __null extension, which is a name for a null
1625   * pointer constant that has integral type (e.g., int or long) and is the same
1626   * size and alignment as a pointer.
1627   *
1628   * The __null extension is typically only used by system headers, which define
1629   * NULL as __null in C++ rather than using 0 (which is an integer that may not
1630   * match the size of a pointer).
1631   */
1632  CXCursor_GNUNullExpr                   = 123,
1633
1634  /** \brief C++'s static_cast<> expression.
1635   */
1636  CXCursor_CXXStaticCastExpr             = 124,
1637
1638  /** \brief C++'s dynamic_cast<> expression.
1639   */
1640  CXCursor_CXXDynamicCastExpr            = 125,
1641
1642  /** \brief C++'s reinterpret_cast<> expression.
1643   */
1644  CXCursor_CXXReinterpretCastExpr        = 126,
1645
1646  /** \brief C++'s const_cast<> expression.
1647   */
1648  CXCursor_CXXConstCastExpr              = 127,
1649
1650  /** \brief Represents an explicit C++ type conversion that uses "functional"
1651   * notion (C++ [expr.type.conv]).
1652   *
1653   * Example:
1654   * \code
1655   *   x = int(0.5);
1656   * \endcode
1657   */
1658  CXCursor_CXXFunctionalCastExpr         = 128,
1659
1660  /** \brief A C++ typeid expression (C++ [expr.typeid]).
1661   */
1662  CXCursor_CXXTypeidExpr                 = 129,
1663
1664  /** \brief [C++ 2.13.5] C++ Boolean Literal.
1665   */
1666  CXCursor_CXXBoolLiteralExpr            = 130,
1667
1668  /** \brief [C++0x 2.14.7] C++ Pointer Literal.
1669   */
1670  CXCursor_CXXNullPtrLiteralExpr         = 131,
1671
1672  /** \brief Represents the "this" expression in C++
1673   */
1674  CXCursor_CXXThisExpr                   = 132,
1675
1676  /** \brief [C++ 15] C++ Throw Expression.
1677   *
1678   * This handles 'throw' and 'throw' assignment-expression. When
1679   * assignment-expression isn't present, Op will be null.
1680   */
1681  CXCursor_CXXThrowExpr                  = 133,
1682
1683  /** \brief A new expression for memory allocation and constructor calls, e.g:
1684   * "new CXXNewExpr(foo)".
1685   */
1686  CXCursor_CXXNewExpr                    = 134,
1687
1688  /** \brief A delete expression for memory deallocation and destructor calls,
1689   * e.g. "delete[] pArray".
1690   */
1691  CXCursor_CXXDeleteExpr                 = 135,
1692
1693  /** \brief A unary expression.
1694   */
1695  CXCursor_UnaryExpr                     = 136,
1696
1697  /** \brief An Objective-C string literal i.e. @"foo".
1698   */
1699  CXCursor_ObjCStringLiteral             = 137,
1700
1701  /** \brief An Objective-C @encode expression.
1702   */
1703  CXCursor_ObjCEncodeExpr                = 138,
1704
1705  /** \brief An Objective-C @selector expression.
1706   */
1707  CXCursor_ObjCSelectorExpr              = 139,
1708
1709  /** \brief An Objective-C @protocol expression.
1710   */
1711  CXCursor_ObjCProtocolExpr              = 140,
1712
1713  /** \brief An Objective-C "bridged" cast expression, which casts between
1714   * Objective-C pointers and C pointers, transferring ownership in the process.
1715   *
1716   * \code
1717   *   NSString *str = (__bridge_transfer NSString *)CFCreateString();
1718   * \endcode
1719   */
1720  CXCursor_ObjCBridgedCastExpr           = 141,
1721
1722  /** \brief Represents a C++0x pack expansion that produces a sequence of
1723   * expressions.
1724   *
1725   * A pack expansion expression contains a pattern (which itself is an
1726   * expression) followed by an ellipsis. For example:
1727   *
1728   * \code
1729   * template<typename F, typename ...Types>
1730   * void forward(F f, Types &&...args) {
1731   *  f(static_cast<Types&&>(args)...);
1732   * }
1733   * \endcode
1734   */
1735  CXCursor_PackExpansionExpr             = 142,
1736
1737  /** \brief Represents an expression that computes the length of a parameter
1738   * pack.
1739   *
1740   * \code
1741   * template<typename ...Types>
1742   * struct count {
1743   *   static const unsigned value = sizeof...(Types);
1744   * };
1745   * \endcode
1746   */
1747  CXCursor_SizeOfPackExpr                = 143,
1748
1749  CXCursor_LastExpr                      = CXCursor_SizeOfPackExpr,
1750
1751  /* Statements */
1752  CXCursor_FirstStmt                     = 200,
1753  /**
1754   * \brief A statement whose specific kind is not exposed via this
1755   * interface.
1756   *
1757   * Unexposed statements have the same operations as any other kind of
1758   * statement; one can extract their location information, spelling,
1759   * children, etc. However, the specific kind of the statement is not
1760   * reported.
1761   */
1762  CXCursor_UnexposedStmt                 = 200,
1763
1764  /** \brief A labelled statement in a function.
1765   *
1766   * This cursor kind is used to describe the "start_over:" label statement in
1767   * the following example:
1768   *
1769   * \code
1770   *   start_over:
1771   *     ++counter;
1772   * \endcode
1773   *
1774   */
1775  CXCursor_LabelStmt                     = 201,
1776
1777  /** \brief A group of statements like { stmt stmt }.
1778   *
1779   * This cursor kind is used to describe compound statements, e.g. function
1780   * bodies.
1781   */
1782  CXCursor_CompoundStmt                  = 202,
1783
1784  /** \brief A case statment.
1785   */
1786  CXCursor_CaseStmt                      = 203,
1787
1788  /** \brief A default statement.
1789   */
1790  CXCursor_DefaultStmt                   = 204,
1791
1792  /** \brief An if statement
1793   */
1794  CXCursor_IfStmt                        = 205,
1795
1796  /** \brief A switch statement.
1797   */
1798  CXCursor_SwitchStmt                    = 206,
1799
1800  /** \brief A while statement.
1801   */
1802  CXCursor_WhileStmt                     = 207,
1803
1804  /** \brief A do statement.
1805   */
1806  CXCursor_DoStmt                        = 208,
1807
1808  /** \brief A for statement.
1809   */
1810  CXCursor_ForStmt                       = 209,
1811
1812  /** \brief A goto statement.
1813   */
1814  CXCursor_GotoStmt                      = 210,
1815
1816  /** \brief An indirect goto statement.
1817   */
1818  CXCursor_IndirectGotoStmt              = 211,
1819
1820  /** \brief A continue statement.
1821   */
1822  CXCursor_ContinueStmt                  = 212,
1823
1824  /** \brief A break statement.
1825   */
1826  CXCursor_BreakStmt                     = 213,
1827
1828  /** \brief A return statement.
1829   */
1830  CXCursor_ReturnStmt                    = 214,
1831
1832  /** \brief A GNU inline assembly statement extension.
1833   */
1834  CXCursor_AsmStmt                       = 215,
1835
1836  /** \brief Objective-C's overall @try-@catch-@finally statement.
1837   */
1838  CXCursor_ObjCAtTryStmt                 = 216,
1839
1840  /** \brief Objective-C's @catch statement.
1841   */
1842  CXCursor_ObjCAtCatchStmt               = 217,
1843
1844  /** \brief Objective-C's @finally statement.
1845   */
1846  CXCursor_ObjCAtFinallyStmt             = 218,
1847
1848  /** \brief Objective-C's @throw statement.
1849   */
1850  CXCursor_ObjCAtThrowStmt               = 219,
1851
1852  /** \brief Objective-C's @synchronized statement.
1853   */
1854  CXCursor_ObjCAtSynchronizedStmt        = 220,
1855
1856  /** \brief Objective-C's autorelease pool statement.
1857   */
1858  CXCursor_ObjCAutoreleasePoolStmt       = 221,
1859
1860  /** \brief Objective-C's collection statement.
1861   */
1862  CXCursor_ObjCForCollectionStmt         = 222,
1863
1864  /** \brief C++'s catch statement.
1865   */
1866  CXCursor_CXXCatchStmt                  = 223,
1867
1868  /** \brief C++'s try statement.
1869   */
1870  CXCursor_CXXTryStmt                    = 224,
1871
1872  /** \brief C++'s for (* : *) statement.
1873   */
1874  CXCursor_CXXForRangeStmt               = 225,
1875
1876  /** \brief Windows Structured Exception Handling's try statement.
1877   */
1878  CXCursor_SEHTryStmt                    = 226,
1879
1880  /** \brief Windows Structured Exception Handling's except statement.
1881   */
1882  CXCursor_SEHExceptStmt                 = 227,
1883
1884  /** \brief Windows Structured Exception Handling's finally statement.
1885   */
1886  CXCursor_SEHFinallyStmt                = 228,
1887
1888  /** \brief The null satement ";": C99 6.8.3p3.
1889   *
1890   * This cursor kind is used to describe the null statement.
1891   */
1892  CXCursor_NullStmt                      = 230,
1893
1894  /** \brief Adaptor class for mixing declarations with statements and
1895   * expressions.
1896   */
1897  CXCursor_DeclStmt                      = 231,
1898
1899  CXCursor_LastStmt                      = CXCursor_DeclStmt,
1900
1901  /**
1902   * \brief Cursor that represents the translation unit itself.
1903   *
1904   * The translation unit cursor exists primarily to act as the root
1905   * cursor for traversing the contents of a translation unit.
1906   */
1907  CXCursor_TranslationUnit               = 300,
1908
1909  /* Attributes */
1910  CXCursor_FirstAttr                     = 400,
1911  /**
1912   * \brief An attribute whose specific kind is not exposed via this
1913   * interface.
1914   */
1915  CXCursor_UnexposedAttr                 = 400,
1916
1917  CXCursor_IBActionAttr                  = 401,
1918  CXCursor_IBOutletAttr                  = 402,
1919  CXCursor_IBOutletCollectionAttr        = 403,
1920  CXCursor_CXXFinalAttr                  = 404,
1921  CXCursor_CXXOverrideAttr               = 405,
1922  CXCursor_AnnotateAttr                  = 406,
1923  CXCursor_AsmLabelAttr                  = 407,
1924  CXCursor_LastAttr                      = CXCursor_AsmLabelAttr,
1925
1926  /* Preprocessing */
1927  CXCursor_PreprocessingDirective        = 500,
1928  CXCursor_MacroDefinition               = 501,
1929  CXCursor_MacroExpansion                = 502,
1930  CXCursor_MacroInstantiation            = CXCursor_MacroExpansion,
1931  CXCursor_InclusionDirective            = 503,
1932  CXCursor_FirstPreprocessing            = CXCursor_PreprocessingDirective,
1933  CXCursor_LastPreprocessing             = CXCursor_InclusionDirective
1934};
1935
1936/**
1937 * \brief A cursor representing some element in the abstract syntax tree for
1938 * a translation unit.
1939 *
1940 * The cursor abstraction unifies the different kinds of entities in a
1941 * program--declaration, statements, expressions, references to declarations,
1942 * etc.--under a single "cursor" abstraction with a common set of operations.
1943 * Common operation for a cursor include: getting the physical location in
1944 * a source file where the cursor points, getting the name associated with a
1945 * cursor, and retrieving cursors for any child nodes of a particular cursor.
1946 *
1947 * Cursors can be produced in two specific ways.
1948 * clang_getTranslationUnitCursor() produces a cursor for a translation unit,
1949 * from which one can use clang_visitChildren() to explore the rest of the
1950 * translation unit. clang_getCursor() maps from a physical source location
1951 * to the entity that resides at that location, allowing one to map from the
1952 * source code into the AST.
1953 */
1954typedef struct {
1955  enum CXCursorKind kind;
1956  int xdata;
1957  void *data[3];
1958} CXCursor;
1959
1960/**
1961 * \defgroup CINDEX_CURSOR_MANIP Cursor manipulations
1962 *
1963 * @{
1964 */
1965
1966/**
1967 * \brief Retrieve the NULL cursor, which represents no entity.
1968 */
1969CINDEX_LINKAGE CXCursor clang_getNullCursor(void);
1970
1971/**
1972 * \brief Retrieve the cursor that represents the given translation unit.
1973 *
1974 * The translation unit cursor can be used to start traversing the
1975 * various declarations within the given translation unit.
1976 */
1977CINDEX_LINKAGE CXCursor clang_getTranslationUnitCursor(CXTranslationUnit);
1978
1979/**
1980 * \brief Determine whether two cursors are equivalent.
1981 */
1982CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
1983
1984/**
1985 * \brief Returns non-zero if \arg cursor is null.
1986 */
1987CINDEX_LINKAGE int clang_Cursor_isNull(CXCursor);
1988
1989/**
1990 * \brief Compute a hash value for the given cursor.
1991 */
1992CINDEX_LINKAGE unsigned clang_hashCursor(CXCursor);
1993
1994/**
1995 * \brief Retrieve the kind of the given cursor.
1996 */
1997CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
1998
1999/**
2000 * \brief Determine whether the given cursor kind represents a declaration.
2001 */
2002CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2003
2004/**
2005 * \brief Determine whether the given cursor kind represents a simple
2006 * reference.
2007 *
2008 * Note that other kinds of cursors (such as expressions) can also refer to
2009 * other cursors. Use clang_getCursorReferenced() to determine whether a
2010 * particular cursor refers to another entity.
2011 */
2012CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2013
2014/**
2015 * \brief Determine whether the given cursor kind represents an expression.
2016 */
2017CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
2018
2019/**
2020 * \brief Determine whether the given cursor kind represents a statement.
2021 */
2022CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
2023
2024/**
2025 * \brief Determine whether the given cursor kind represents an attribute.
2026 */
2027CINDEX_LINKAGE unsigned clang_isAttribute(enum CXCursorKind);
2028
2029/**
2030 * \brief Determine whether the given cursor kind represents an invalid
2031 * cursor.
2032 */
2033CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
2034
2035/**
2036 * \brief Determine whether the given cursor kind represents a translation
2037 * unit.
2038 */
2039CINDEX_LINKAGE unsigned clang_isTranslationUnit(enum CXCursorKind);
2040
2041/***
2042 * \brief Determine whether the given cursor represents a preprocessing
2043 * element, such as a preprocessor directive or macro instantiation.
2044 */
2045CINDEX_LINKAGE unsigned clang_isPreprocessing(enum CXCursorKind);
2046
2047/***
2048 * \brief Determine whether the given cursor represents a currently
2049 *  unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).
2050 */
2051CINDEX_LINKAGE unsigned clang_isUnexposed(enum CXCursorKind);
2052
2053/**
2054 * \brief Describe the linkage of the entity referred to by a cursor.
2055 */
2056enum CXLinkageKind {
2057  /** \brief This value indicates that no linkage information is available
2058   * for a provided CXCursor. */
2059  CXLinkage_Invalid,
2060  /**
2061   * \brief This is the linkage for variables, parameters, and so on that
2062   *  have automatic storage.  This covers normal (non-extern) local variables.
2063   */
2064  CXLinkage_NoLinkage,
2065  /** \brief This is the linkage for static variables and static functions. */
2066  CXLinkage_Internal,
2067  /** \brief This is the linkage for entities with external linkage that live
2068   * in C++ anonymous namespaces.*/
2069  CXLinkage_UniqueExternal,
2070  /** \brief This is the linkage for entities with true, external linkage. */
2071  CXLinkage_External
2072};
2073
2074/**
2075 * \brief Determine the linkage of the entity referred to by a given cursor.
2076 */
2077CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
2078
2079/**
2080 * \brief Determine the availability of the entity that this cursor refers to.
2081 *
2082 * \param cursor The cursor to query.
2083 *
2084 * \returns The availability of the cursor.
2085 */
2086CINDEX_LINKAGE enum CXAvailabilityKind
2087clang_getCursorAvailability(CXCursor cursor);
2088
2089/**
2090 * \brief Describe the "language" of the entity referred to by a cursor.
2091 */
2092CINDEX_LINKAGE enum CXLanguageKind {
2093  CXLanguage_Invalid = 0,
2094  CXLanguage_C,
2095  CXLanguage_ObjC,
2096  CXLanguage_CPlusPlus
2097};
2098
2099/**
2100 * \brief Determine the "language" of the entity referred to by a given cursor.
2101 */
2102CINDEX_LINKAGE enum CXLanguageKind clang_getCursorLanguage(CXCursor cursor);
2103
2104/**
2105 * \brief Returns the translation unit that a cursor originated from.
2106 */
2107CINDEX_LINKAGE CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor);
2108
2109
2110/**
2111 * \brief A fast container representing a set of CXCursors.
2112 */
2113typedef struct CXCursorSetImpl *CXCursorSet;
2114
2115/**
2116 * \brief Creates an empty CXCursorSet.
2117 */
2118CINDEX_LINKAGE CXCursorSet clang_createCXCursorSet();
2119
2120/**
2121 * \brief Disposes a CXCursorSet and releases its associated memory.
2122 */
2123CINDEX_LINKAGE void clang_disposeCXCursorSet(CXCursorSet cset);
2124
2125/**
2126 * \brief Queries a CXCursorSet to see if it contains a specific CXCursor.
2127 *
2128 * \returns non-zero if the set contains the specified cursor.
2129*/
2130CINDEX_LINKAGE unsigned clang_CXCursorSet_contains(CXCursorSet cset,
2131                                                   CXCursor cursor);
2132
2133/**
2134 * \brief Inserts a CXCursor into a CXCursorSet.
2135 *
2136 * \returns zero if the CXCursor was already in the set, and non-zero otherwise.
2137*/
2138CINDEX_LINKAGE unsigned clang_CXCursorSet_insert(CXCursorSet cset,
2139                                                 CXCursor cursor);
2140
2141/**
2142 * \brief Determine the semantic parent of the given cursor.
2143 *
2144 * The semantic parent of a cursor is the cursor that semantically contains
2145 * the given \p cursor. For many declarations, the lexical and semantic parents
2146 * are equivalent (the lexical parent is returned by
2147 * \c clang_getCursorLexicalParent()). They diverge when declarations or
2148 * definitions are provided out-of-line. For example:
2149 *
2150 * \code
2151 * class C {
2152 *  void f();
2153 * };
2154 *
2155 * void C::f() { }
2156 * \endcode
2157 *
2158 * In the out-of-line definition of \c C::f, the semantic parent is the
2159 * the class \c C, of which this function is a member. The lexical parent is
2160 * the place where the declaration actually occurs in the source code; in this
2161 * case, the definition occurs in the translation unit. In general, the
2162 * lexical parent for a given entity can change without affecting the semantics
2163 * of the program, and the lexical parent of different declarations of the
2164 * same entity may be different. Changing the semantic parent of a declaration,
2165 * on the other hand, can have a major impact on semantics, and redeclarations
2166 * of a particular entity should all have the same semantic context.
2167 *
2168 * In the example above, both declarations of \c C::f have \c C as their
2169 * semantic context, while the lexical context of the first \c C::f is \c C
2170 * and the lexical context of the second \c C::f is the translation unit.
2171 *
2172 * For global declarations, the semantic parent is the translation unit.
2173 */
2174CINDEX_LINKAGE CXCursor clang_getCursorSemanticParent(CXCursor cursor);
2175
2176/**
2177 * \brief Determine the lexical parent of the given cursor.
2178 *
2179 * The lexical parent of a cursor is the cursor in which the given \p cursor
2180 * was actually written. For many declarations, the lexical and semantic parents
2181 * are equivalent (the semantic parent is returned by
2182 * \c clang_getCursorSemanticParent()). They diverge when declarations or
2183 * definitions are provided out-of-line. For example:
2184 *
2185 * \code
2186 * class C {
2187 *  void f();
2188 * };
2189 *
2190 * void C::f() { }
2191 * \endcode
2192 *
2193 * In the out-of-line definition of \c C::f, the semantic parent is the
2194 * the class \c C, of which this function is a member. The lexical parent is
2195 * the place where the declaration actually occurs in the source code; in this
2196 * case, the definition occurs in the translation unit. In general, the
2197 * lexical parent for a given entity can change without affecting the semantics
2198 * of the program, and the lexical parent of different declarations of the
2199 * same entity may be different. Changing the semantic parent of a declaration,
2200 * on the other hand, can have a major impact on semantics, and redeclarations
2201 * of a particular entity should all have the same semantic context.
2202 *
2203 * In the example above, both declarations of \c C::f have \c C as their
2204 * semantic context, while the lexical context of the first \c C::f is \c C
2205 * and the lexical context of the second \c C::f is the translation unit.
2206 *
2207 * For declarations written in the global scope, the lexical parent is
2208 * the translation unit.
2209 */
2210CINDEX_LINKAGE CXCursor clang_getCursorLexicalParent(CXCursor cursor);
2211
2212/**
2213 * \brief Determine the set of methods that are overridden by the given
2214 * method.
2215 *
2216 * In both Objective-C and C++, a method (aka virtual member function,
2217 * in C++) can override a virtual method in a base class. For
2218 * Objective-C, a method is said to override any method in the class's
2219 * interface (if we're coming from an implementation), its protocols,
2220 * or its categories, that has the same selector and is of the same
2221 * kind (class or instance). If no such method exists, the search
2222 * continues to the class's superclass, its protocols, and its
2223 * categories, and so on.
2224 *
2225 * For C++, a virtual member function overrides any virtual member
2226 * function with the same signature that occurs in its base
2227 * classes. With multiple inheritance, a virtual member function can
2228 * override several virtual member functions coming from different
2229 * base classes.
2230 *
2231 * In all cases, this function determines the immediate overridden
2232 * method, rather than all of the overridden methods. For example, if
2233 * a method is originally declared in a class A, then overridden in B
2234 * (which in inherits from A) and also in C (which inherited from B),
2235 * then the only overridden method returned from this function when
2236 * invoked on C's method will be B's method. The client may then
2237 * invoke this function again, given the previously-found overridden
2238 * methods, to map out the complete method-override set.
2239 *
2240 * \param cursor A cursor representing an Objective-C or C++
2241 * method. This routine will compute the set of methods that this
2242 * method overrides.
2243 *
2244 * \param overridden A pointer whose pointee will be replaced with a
2245 * pointer to an array of cursors, representing the set of overridden
2246 * methods. If there are no overridden methods, the pointee will be
2247 * set to NULL. The pointee must be freed via a call to
2248 * \c clang_disposeOverriddenCursors().
2249 *
2250 * \param num_overridden A pointer to the number of overridden
2251 * functions, will be set to the number of overridden functions in the
2252 * array pointed to by \p overridden.
2253 */
2254CINDEX_LINKAGE void clang_getOverriddenCursors(CXCursor cursor,
2255                                               CXCursor **overridden,
2256                                               unsigned *num_overridden);
2257
2258/**
2259 * \brief Free the set of overridden cursors returned by \c
2260 * clang_getOverriddenCursors().
2261 */
2262CINDEX_LINKAGE void clang_disposeOverriddenCursors(CXCursor *overridden);
2263
2264/**
2265 * \brief Retrieve the file that is included by the given inclusion directive
2266 * cursor.
2267 */
2268CINDEX_LINKAGE CXFile clang_getIncludedFile(CXCursor cursor);
2269
2270/**
2271 * @}
2272 */
2273
2274/**
2275 * \defgroup CINDEX_CURSOR_SOURCE Mapping between cursors and source code
2276 *
2277 * Cursors represent a location within the Abstract Syntax Tree (AST). These
2278 * routines help map between cursors and the physical locations where the
2279 * described entities occur in the source code. The mapping is provided in
2280 * both directions, so one can map from source code to the AST and back.
2281 *
2282 * @{
2283 */
2284
2285/**
2286 * \brief Map a source location to the cursor that describes the entity at that
2287 * location in the source code.
2288 *
2289 * clang_getCursor() maps an arbitrary source location within a translation
2290 * unit down to the most specific cursor that describes the entity at that
2291 * location. For example, given an expression \c x + y, invoking
2292 * clang_getCursor() with a source location pointing to "x" will return the
2293 * cursor for "x"; similarly for "y". If the cursor points anywhere between
2294 * "x" or "y" (e.g., on the + or the whitespace around it), clang_getCursor()
2295 * will return a cursor referring to the "+" expression.
2296 *
2297 * \returns a cursor representing the entity at the given source location, or
2298 * a NULL cursor if no such entity can be found.
2299 */
2300CINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, CXSourceLocation);
2301
2302/**
2303 * \brief Retrieve the physical location of the source constructor referenced
2304 * by the given cursor.
2305 *
2306 * The location of a declaration is typically the location of the name of that
2307 * declaration, where the name of that declaration would occur if it is
2308 * unnamed, or some keyword that introduces that particular declaration.
2309 * The location of a reference is where that reference occurs within the
2310 * source code.
2311 */
2312CINDEX_LINKAGE CXSourceLocation clang_getCursorLocation(CXCursor);
2313
2314/**
2315 * \brief Retrieve the physical extent of the source construct referenced by
2316 * the given cursor.
2317 *
2318 * The extent of a cursor starts with the file/line/column pointing at the
2319 * first character within the source construct that the cursor refers to and
2320 * ends with the last character withinin that source construct. For a
2321 * declaration, the extent covers the declaration itself. For a reference,
2322 * the extent covers the location of the reference (e.g., where the referenced
2323 * entity was actually used).
2324 */
2325CINDEX_LINKAGE CXSourceRange clang_getCursorExtent(CXCursor);
2326
2327/**
2328 * @}
2329 */
2330
2331/**
2332 * \defgroup CINDEX_TYPES Type information for CXCursors
2333 *
2334 * @{
2335 */
2336
2337/**
2338 * \brief Describes the kind of type
2339 */
2340enum CXTypeKind {
2341  /**
2342   * \brief Reprents an invalid type (e.g., where no type is available).
2343   */
2344  CXType_Invalid = 0,
2345
2346  /**
2347   * \brief A type whose specific kind is not exposed via this
2348   * interface.
2349   */
2350  CXType_Unexposed = 1,
2351
2352  /* Builtin types */
2353  CXType_Void = 2,
2354  CXType_Bool = 3,
2355  CXType_Char_U = 4,
2356  CXType_UChar = 5,
2357  CXType_Char16 = 6,
2358  CXType_Char32 = 7,
2359  CXType_UShort = 8,
2360  CXType_UInt = 9,
2361  CXType_ULong = 10,
2362  CXType_ULongLong = 11,
2363  CXType_UInt128 = 12,
2364  CXType_Char_S = 13,
2365  CXType_SChar = 14,
2366  CXType_WChar = 15,
2367  CXType_Short = 16,
2368  CXType_Int = 17,
2369  CXType_Long = 18,
2370  CXType_LongLong = 19,
2371  CXType_Int128 = 20,
2372  CXType_Float = 21,
2373  CXType_Double = 22,
2374  CXType_LongDouble = 23,
2375  CXType_NullPtr = 24,
2376  CXType_Overload = 25,
2377  CXType_Dependent = 26,
2378  CXType_ObjCId = 27,
2379  CXType_ObjCClass = 28,
2380  CXType_ObjCSel = 29,
2381  CXType_FirstBuiltin = CXType_Void,
2382  CXType_LastBuiltin  = CXType_ObjCSel,
2383
2384  CXType_Complex = 100,
2385  CXType_Pointer = 101,
2386  CXType_BlockPointer = 102,
2387  CXType_LValueReference = 103,
2388  CXType_RValueReference = 104,
2389  CXType_Record = 105,
2390  CXType_Enum = 106,
2391  CXType_Typedef = 107,
2392  CXType_ObjCInterface = 108,
2393  CXType_ObjCObjectPointer = 109,
2394  CXType_FunctionNoProto = 110,
2395  CXType_FunctionProto = 111,
2396  CXType_ConstantArray = 112,
2397  CXType_Vector = 113
2398};
2399
2400/**
2401 * \brief Describes the calling convention of a function type
2402 */
2403enum CXCallingConv {
2404  CXCallingConv_Default = 0,
2405  CXCallingConv_C = 1,
2406  CXCallingConv_X86StdCall = 2,
2407  CXCallingConv_X86FastCall = 3,
2408  CXCallingConv_X86ThisCall = 4,
2409  CXCallingConv_X86Pascal = 5,
2410  CXCallingConv_AAPCS = 6,
2411  CXCallingConv_AAPCS_VFP = 7,
2412
2413  CXCallingConv_Invalid = 100,
2414  CXCallingConv_Unexposed = 200
2415};
2416
2417
2418/**
2419 * \brief The type of an element in the abstract syntax tree.
2420 *
2421 */
2422typedef struct {
2423  enum CXTypeKind kind;
2424  void *data[2];
2425} CXType;
2426
2427/**
2428 * \brief Retrieve the type of a CXCursor (if any).
2429 */
2430CINDEX_LINKAGE CXType clang_getCursorType(CXCursor C);
2431
2432/**
2433 * \brief Retrieve the underlying type of a typedef declaration.
2434 *
2435 * If the cursor does not reference a typedef declaration, an invalid type is
2436 * returned.
2437 */
2438CINDEX_LINKAGE CXType clang_getTypedefDeclUnderlyingType(CXCursor C);
2439
2440/**
2441 * \brief Retrieve the integer type of an enum declaration.
2442 *
2443 * If the cursor does not reference an enum declaration, an invalid type is
2444 * returned.
2445 */
2446CINDEX_LINKAGE CXType clang_getEnumDeclIntegerType(CXCursor C);
2447
2448/**
2449 * \brief Retrieve the integer value of an enum constant declaration as a signed
2450 *  long long.
2451 *
2452 * If the cursor does not reference an enum constant declaration, LLONG_MIN is returned.
2453 * Since this is also potentially a valid constant value, the kind of the cursor
2454 * must be verified before calling this function.
2455 */
2456CINDEX_LINKAGE long long clang_getEnumConstantDeclValue(CXCursor C);
2457
2458/**
2459 * \brief Retrieve the integer value of an enum constant declaration as an unsigned
2460 *  long long.
2461 *
2462 * If the cursor does not reference an enum constant declaration, ULLONG_MAX is returned.
2463 * Since this is also potentially a valid constant value, the kind of the cursor
2464 * must be verified before calling this function.
2465 */
2466CINDEX_LINKAGE unsigned long long clang_getEnumConstantDeclUnsignedValue(CXCursor C);
2467
2468/**
2469 * \determine Determine whether two CXTypes represent the same type.
2470 *
2471 * \returns non-zero if the CXTypes represent the same type and
2472            zero otherwise.
2473 */
2474CINDEX_LINKAGE unsigned clang_equalTypes(CXType A, CXType B);
2475
2476/**
2477 * \brief Return the canonical type for a CXType.
2478 *
2479 * Clang's type system explicitly models typedefs and all the ways
2480 * a specific type can be represented.  The canonical type is the underlying
2481 * type with all the "sugar" removed.  For example, if 'T' is a typedef
2482 * for 'int', the canonical type for 'T' would be 'int'.
2483 */
2484CINDEX_LINKAGE CXType clang_getCanonicalType(CXType T);
2485
2486/**
2487 *  \determine Determine whether a CXType has the "const" qualifier set,
2488 *  without looking through typedefs that may have added "const" at a different level.
2489 */
2490CINDEX_LINKAGE unsigned clang_isConstQualifiedType(CXType T);
2491
2492/**
2493 *  \determine Determine whether a CXType has the "volatile" qualifier set,
2494 *  without looking through typedefs that may have added "volatile" at a different level.
2495 */
2496CINDEX_LINKAGE unsigned clang_isVolatileQualifiedType(CXType T);
2497
2498/**
2499 *  \determine Determine whether a CXType has the "restrict" qualifier set,
2500 *  without looking through typedefs that may have added "restrict" at a different level.
2501 */
2502CINDEX_LINKAGE unsigned clang_isRestrictQualifiedType(CXType T);
2503
2504/**
2505 * \brief For pointer types, returns the type of the pointee.
2506 *
2507 */
2508CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
2509
2510/**
2511 * \brief Return the cursor for the declaration of the given type.
2512 */
2513CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
2514
2515/**
2516 * Returns the Objective-C type encoding for the specified declaration.
2517 */
2518CINDEX_LINKAGE CXString clang_getDeclObjCTypeEncoding(CXCursor C);
2519
2520/**
2521 * \brief Retrieve the spelling of a given CXTypeKind.
2522 */
2523CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
2524
2525/**
2526 * \brief Retrieve the calling convention associated with a function type.
2527 *
2528 * If a non-function type is passed in, CXCallingConv_Invalid is returned.
2529 */
2530CINDEX_LINKAGE enum CXCallingConv clang_getFunctionTypeCallingConv(CXType T);
2531
2532/**
2533 * \brief Retrieve the result type associated with a function type.
2534 *
2535 * If a non-function type is passed in, an invalid type is returned.
2536 */
2537CINDEX_LINKAGE CXType clang_getResultType(CXType T);
2538
2539/**
2540 * \brief Retrieve the number of non-variadic arguments associated with a function type.
2541 *
2542 * If a non-function type is passed in, UINT_MAX is returned.
2543 */
2544CINDEX_LINKAGE unsigned clang_getNumArgTypes(CXType T);
2545
2546/**
2547 * \brief Retrieve the type of an argument of a function type.
2548 *
2549 * If a non-function type is passed in or the function does not have enough parameters,
2550 * an invalid type is returned.
2551 */
2552CINDEX_LINKAGE CXType clang_getArgType(CXType T, unsigned i);
2553
2554/**
2555 * \brief Return 1 if the CXType is a variadic function type, and 0 otherwise.
2556 *
2557 */
2558CINDEX_LINKAGE unsigned clang_isFunctionTypeVariadic(CXType T);
2559
2560/**
2561 * \brief Retrieve the result type associated with a given cursor.
2562 *
2563 * This only returns a valid type if the cursor refers to a function or method.
2564 */
2565CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
2566
2567/**
2568 * \brief Return 1 if the CXType is a POD (plain old data) type, and 0
2569 *  otherwise.
2570 */
2571CINDEX_LINKAGE unsigned clang_isPODType(CXType T);
2572
2573/**
2574 * \brief Return the element type of an array, complex, or vector type.
2575 *
2576 * If a type is passed in that is not an array, complex, or vector type,
2577 * an invalid type is returned.
2578 */
2579CINDEX_LINKAGE CXType clang_getElementType(CXType T);
2580
2581/**
2582 * \brief Return the number of elements of an array or vector type.
2583 *
2584 * If a type is passed in that is not an array or vector type,
2585 * -1 is returned.
2586 */
2587CINDEX_LINKAGE long long clang_getNumElements(CXType T);
2588
2589/**
2590 * \brief Return the element type of an array type.
2591 *
2592 * If a non-array type is passed in, an invalid type is returned.
2593 */
2594CINDEX_LINKAGE CXType clang_getArrayElementType(CXType T);
2595
2596/**
2597 * \brief Return the the array size of a constant array.
2598 *
2599 * If a non-array type is passed in, -1 is returned.
2600 */
2601CINDEX_LINKAGE long long clang_getArraySize(CXType T);
2602
2603/**
2604 * \brief Returns 1 if the base class specified by the cursor with kind
2605 *   CX_CXXBaseSpecifier is virtual.
2606 */
2607CINDEX_LINKAGE unsigned clang_isVirtualBase(CXCursor);
2608
2609/**
2610 * \brief Represents the C++ access control level to a base class for a
2611 * cursor with kind CX_CXXBaseSpecifier.
2612 */
2613enum CX_CXXAccessSpecifier {
2614  CX_CXXInvalidAccessSpecifier,
2615  CX_CXXPublic,
2616  CX_CXXProtected,
2617  CX_CXXPrivate
2618};
2619
2620/**
2621 * \brief Returns the access control level for the C++ base specifier
2622 * represented by a cursor with kind CXCursor_CXXBaseSpecifier or
2623 * CXCursor_AccessSpecifier.
2624 */
2625CINDEX_LINKAGE enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor);
2626
2627/**
2628 * \brief Determine the number of overloaded declarations referenced by a
2629 * \c CXCursor_OverloadedDeclRef cursor.
2630 *
2631 * \param cursor The cursor whose overloaded declarations are being queried.
2632 *
2633 * \returns The number of overloaded declarations referenced by \c cursor. If it
2634 * is not a \c CXCursor_OverloadedDeclRef cursor, returns 0.
2635 */
2636CINDEX_LINKAGE unsigned clang_getNumOverloadedDecls(CXCursor cursor);
2637
2638/**
2639 * \brief Retrieve a cursor for one of the overloaded declarations referenced
2640 * by a \c CXCursor_OverloadedDeclRef cursor.
2641 *
2642 * \param cursor The cursor whose overloaded declarations are being queried.
2643 *
2644 * \param index The zero-based index into the set of overloaded declarations in
2645 * the cursor.
2646 *
2647 * \returns A cursor representing the declaration referenced by the given
2648 * \c cursor at the specified \c index. If the cursor does not have an
2649 * associated set of overloaded declarations, or if the index is out of bounds,
2650 * returns \c clang_getNullCursor();
2651 */
2652CINDEX_LINKAGE CXCursor clang_getOverloadedDecl(CXCursor cursor,
2653                                                unsigned index);
2654
2655/**
2656 * @}
2657 */
2658
2659/**
2660 * \defgroup CINDEX_ATTRIBUTES Information for attributes
2661 *
2662 * @{
2663 */
2664
2665
2666/**
2667 * \brief For cursors representing an iboutletcollection attribute,
2668 *  this function returns the collection element type.
2669 *
2670 */
2671CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
2672
2673/**
2674 * @}
2675 */
2676
2677/**
2678 * \defgroup CINDEX_CURSOR_TRAVERSAL Traversing the AST with cursors
2679 *
2680 * These routines provide the ability to traverse the abstract syntax tree
2681 * using cursors.
2682 *
2683 * @{
2684 */
2685
2686/**
2687 * \brief Describes how the traversal of the children of a particular
2688 * cursor should proceed after visiting a particular child cursor.
2689 *
2690 * A value of this enumeration type should be returned by each
2691 * \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
2692 */
2693enum CXChildVisitResult {
2694  /**
2695   * \brief Terminates the cursor traversal.
2696   */
2697  CXChildVisit_Break,
2698  /**
2699   * \brief Continues the cursor traversal with the next sibling of
2700   * the cursor just visited, without visiting its children.
2701   */
2702  CXChildVisit_Continue,
2703  /**
2704   * \brief Recursively traverse the children of this cursor, using
2705   * the same visitor and client data.
2706   */
2707  CXChildVisit_Recurse
2708};
2709
2710/**
2711 * \brief Visitor invoked for each cursor found by a traversal.
2712 *
2713 * This visitor function will be invoked for each cursor found by
2714 * clang_visitCursorChildren(). Its first argument is the cursor being
2715 * visited, its second argument is the parent visitor for that cursor,
2716 * and its third argument is the client data provided to
2717 * clang_visitCursorChildren().
2718 *
2719 * The visitor should return one of the \c CXChildVisitResult values
2720 * to direct clang_visitCursorChildren().
2721 */
2722typedef enum CXChildVisitResult (*CXCursorVisitor)(CXCursor cursor,
2723                                                   CXCursor parent,
2724                                                   CXClientData client_data);
2725
2726/**
2727 * \brief Visit the children of a particular cursor.
2728 *
2729 * This function visits all the direct children of the given cursor,
2730 * invoking the given \p visitor function with the cursors of each
2731 * visited child. The traversal may be recursive, if the visitor returns
2732 * \c CXChildVisit_Recurse. The traversal may also be ended prematurely, if
2733 * the visitor returns \c CXChildVisit_Break.
2734 *
2735 * \param parent the cursor whose child may be visited. All kinds of
2736 * cursors can be visited, including invalid cursors (which, by
2737 * definition, have no children).
2738 *
2739 * \param visitor the visitor function that will be invoked for each
2740 * child of \p parent.
2741 *
2742 * \param client_data pointer data supplied by the client, which will
2743 * be passed to the visitor each time it is invoked.
2744 *
2745 * \returns a non-zero value if the traversal was terminated
2746 * prematurely by the visitor returning \c CXChildVisit_Break.
2747 */
2748CINDEX_LINKAGE unsigned clang_visitChildren(CXCursor parent,
2749                                            CXCursorVisitor visitor,
2750                                            CXClientData client_data);
2751#ifdef __has_feature
2752#  if __has_feature(blocks)
2753/**
2754 * \brief Visitor invoked for each cursor found by a traversal.
2755 *
2756 * This visitor block will be invoked for each cursor found by
2757 * clang_visitChildrenWithBlock(). Its first argument is the cursor being
2758 * visited, its second argument is the parent visitor for that cursor.
2759 *
2760 * The visitor should return one of the \c CXChildVisitResult values
2761 * to direct clang_visitChildrenWithBlock().
2762 */
2763typedef enum CXChildVisitResult
2764     (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
2765
2766/**
2767 * Visits the children of a cursor using the specified block.  Behaves
2768 * identically to clang_visitChildren() in all other respects.
2769 */
2770unsigned clang_visitChildrenWithBlock(CXCursor parent,
2771                                      CXCursorVisitorBlock block);
2772#  endif
2773#endif
2774
2775/**
2776 * @}
2777 */
2778
2779/**
2780 * \defgroup CINDEX_CURSOR_XREF Cross-referencing in the AST
2781 *
2782 * These routines provide the ability to determine references within and
2783 * across translation units, by providing the names of the entities referenced
2784 * by cursors, follow reference cursors to the declarations they reference,
2785 * and associate declarations with their definitions.
2786 *
2787 * @{
2788 */
2789
2790/**
2791 * \brief Retrieve a Unified Symbol Resolution (USR) for the entity referenced
2792 * by the given cursor.
2793 *
2794 * A Unified Symbol Resolution (USR) is a string that identifies a particular
2795 * entity (function, class, variable, etc.) within a program. USRs can be
2796 * compared across translation units to determine, e.g., when references in
2797 * one translation refer to an entity defined in another translation unit.
2798 */
2799CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
2800
2801/**
2802 * \brief Construct a USR for a specified Objective-C class.
2803 */
2804CINDEX_LINKAGE CXString clang_constructUSR_ObjCClass(const char *class_name);
2805
2806/**
2807 * \brief Construct a USR for a specified Objective-C category.
2808 */
2809CINDEX_LINKAGE CXString
2810  clang_constructUSR_ObjCCategory(const char *class_name,
2811                                 const char *category_name);
2812
2813/**
2814 * \brief Construct a USR for a specified Objective-C protocol.
2815 */
2816CINDEX_LINKAGE CXString
2817  clang_constructUSR_ObjCProtocol(const char *protocol_name);
2818
2819
2820/**
2821 * \brief Construct a USR for a specified Objective-C instance variable and
2822 *   the USR for its containing class.
2823 */
2824CINDEX_LINKAGE CXString clang_constructUSR_ObjCIvar(const char *name,
2825                                                    CXString classUSR);
2826
2827/**
2828 * \brief Construct a USR for a specified Objective-C method and
2829 *   the USR for its containing class.
2830 */
2831CINDEX_LINKAGE CXString clang_constructUSR_ObjCMethod(const char *name,
2832                                                      unsigned isInstanceMethod,
2833                                                      CXString classUSR);
2834
2835/**
2836 * \brief Construct a USR for a specified Objective-C property and the USR
2837 *  for its containing class.
2838 */
2839CINDEX_LINKAGE CXString clang_constructUSR_ObjCProperty(const char *property,
2840                                                        CXString classUSR);
2841
2842/**
2843 * \brief Retrieve a name for the entity referenced by this cursor.
2844 */
2845CINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
2846
2847/**
2848 * \brief Retrieve the display name for the entity referenced by this cursor.
2849 *
2850 * The display name contains extra information that helps identify the cursor,
2851 * such as the parameters of a function or template or the arguments of a
2852 * class template specialization.
2853 */
2854CINDEX_LINKAGE CXString clang_getCursorDisplayName(CXCursor);
2855
2856/** \brief For a cursor that is a reference, retrieve a cursor representing the
2857 * entity that it references.
2858 *
2859 * Reference cursors refer to other entities in the AST. For example, an
2860 * Objective-C superclass reference cursor refers to an Objective-C class.
2861 * This function produces the cursor for the Objective-C class from the
2862 * cursor for the superclass reference. If the input cursor is a declaration or
2863 * definition, it returns that declaration or definition unchanged.
2864 * Otherwise, returns the NULL cursor.
2865 */
2866CINDEX_LINKAGE CXCursor clang_getCursorReferenced(CXCursor);
2867
2868/**
2869 *  \brief For a cursor that is either a reference to or a declaration
2870 *  of some entity, retrieve a cursor that describes the definition of
2871 *  that entity.
2872 *
2873 *  Some entities can be declared multiple times within a translation
2874 *  unit, but only one of those declarations can also be a
2875 *  definition. For example, given:
2876 *
2877 *  \code
2878 *  int f(int, int);
2879 *  int g(int x, int y) { return f(x, y); }
2880 *  int f(int a, int b) { return a + b; }
2881 *  int f(int, int);
2882 *  \endcode
2883 *
2884 *  there are three declarations of the function "f", but only the
2885 *  second one is a definition. The clang_getCursorDefinition()
2886 *  function will take any cursor pointing to a declaration of "f"
2887 *  (the first or fourth lines of the example) or a cursor referenced
2888 *  that uses "f" (the call to "f' inside "g") and will return a
2889 *  declaration cursor pointing to the definition (the second "f"
2890 *  declaration).
2891 *
2892 *  If given a cursor for which there is no corresponding definition,
2893 *  e.g., because there is no definition of that entity within this
2894 *  translation unit, returns a NULL cursor.
2895 */
2896CINDEX_LINKAGE CXCursor clang_getCursorDefinition(CXCursor);
2897
2898/**
2899 * \brief Determine whether the declaration pointed to by this cursor
2900 * is also a definition of that entity.
2901 */
2902CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
2903
2904/**
2905 * \brief Retrieve the canonical cursor corresponding to the given cursor.
2906 *
2907 * In the C family of languages, many kinds of entities can be declared several
2908 * times within a single translation unit. For example, a structure type can
2909 * be forward-declared (possibly multiple times) and later defined:
2910 *
2911 * \code
2912 * struct X;
2913 * struct X;
2914 * struct X {
2915 *   int member;
2916 * };
2917 * \endcode
2918 *
2919 * The declarations and the definition of \c X are represented by three
2920 * different cursors, all of which are declarations of the same underlying
2921 * entity. One of these cursor is considered the "canonical" cursor, which
2922 * is effectively the representative for the underlying entity. One can
2923 * determine if two cursors are declarations of the same underlying entity by
2924 * comparing their canonical cursors.
2925 *
2926 * \returns The canonical cursor for the entity referred to by the given cursor.
2927 */
2928CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
2929
2930/**
2931 * @}
2932 */
2933
2934/**
2935 * \defgroup CINDEX_CPP C++ AST introspection
2936 *
2937 * The routines in this group provide access information in the ASTs specific
2938 * to C++ language features.
2939 *
2940 * @{
2941 */
2942
2943/**
2944 * \brief Determine if a C++ member function or member function template is
2945 * declared 'static'.
2946 */
2947CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
2948
2949/**
2950 * \brief Determine if a C++ member function or member function template is
2951 * explicitly declared 'virtual' or if it overrides a virtual method from
2952 * one of the base classes.
2953 */
2954CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
2955
2956/**
2957 * \brief Given a cursor that represents a template, determine
2958 * the cursor kind of the specializations would be generated by instantiating
2959 * the template.
2960 *
2961 * This routine can be used to determine what flavor of function template,
2962 * class template, or class template partial specialization is stored in the
2963 * cursor. For example, it can describe whether a class template cursor is
2964 * declared with "struct", "class" or "union".
2965 *
2966 * \param C The cursor to query. This cursor should represent a template
2967 * declaration.
2968 *
2969 * \returns The cursor kind of the specializations that would be generated
2970 * by instantiating the template \p C. If \p C is not a template, returns
2971 * \c CXCursor_NoDeclFound.
2972 */
2973CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
2974
2975/**
2976 * \brief Given a cursor that may represent a specialization or instantiation
2977 * of a template, retrieve the cursor that represents the template that it
2978 * specializes or from which it was instantiated.
2979 *
2980 * This routine determines the template involved both for explicit
2981 * specializations of templates and for implicit instantiations of the template,
2982 * both of which are referred to as "specializations". For a class template
2983 * specialization (e.g., \c std::vector<bool>), this routine will return
2984 * either the primary template (\c std::vector) or, if the specialization was
2985 * instantiated from a class template partial specialization, the class template
2986 * partial specialization. For a class template partial specialization and a
2987 * function template specialization (including instantiations), this
2988 * this routine will return the specialized template.
2989 *
2990 * For members of a class template (e.g., member functions, member classes, or
2991 * static data members), returns the specialized or instantiated member.
2992 * Although not strictly "templates" in the C++ language, members of class
2993 * templates have the same notions of specializations and instantiations that
2994 * templates do, so this routine treats them similarly.
2995 *
2996 * \param C A cursor that may be a specialization of a template or a member
2997 * of a template.
2998 *
2999 * \returns If the given cursor is a specialization or instantiation of a
3000 * template or a member thereof, the template or member that it specializes or
3001 * from which it was instantiated. Otherwise, returns a NULL cursor.
3002 */
3003CINDEX_LINKAGE CXCursor clang_getSpecializedCursorTemplate(CXCursor C);
3004
3005/**
3006 * \brief Given a cursor that references something else, return the source range
3007 * covering that reference.
3008 *
3009 * \param C A cursor pointing to a member reference, a declaration reference, or
3010 * an operator call.
3011 * \param NameFlags A bitset with three independent flags:
3012 * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
3013 * CXNameRange_WantSinglePiece.
3014 * \param PieceIndex For contiguous names or when passing the flag
3015 * CXNameRange_WantSinglePiece, only one piece with index 0 is
3016 * available. When the CXNameRange_WantSinglePiece flag is not passed for a
3017 * non-contiguous names, this index can be used to retreive the individual
3018 * pieces of the name. See also CXNameRange_WantSinglePiece.
3019 *
3020 * \returns The piece of the name pointed to by the given cursor. If there is no
3021 * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
3022 */
3023CINDEX_LINKAGE CXSourceRange clang_getCursorReferenceNameRange(CXCursor C,
3024                                                unsigned NameFlags,
3025                                                unsigned PieceIndex);
3026
3027enum CXNameRefFlags {
3028  /**
3029   * \brief Include the nested-name-specifier, e.g. Foo:: in x.Foo::y, in the
3030   * range.
3031   */
3032  CXNameRange_WantQualifier = 0x1,
3033
3034  /**
3035   * \brief Include the explicit template arguments, e.g. <int> in x.f<int>, in
3036   * the range.
3037   */
3038  CXNameRange_WantTemplateArgs = 0x2,
3039
3040  /**
3041   * \brief If the name is non-contiguous, return the full spanning range.
3042   *
3043   * Non-contiguous names occur in Objective-C when a selector with two or more
3044   * parameters is used, or in C++ when using an operator:
3045   * \code
3046   * [object doSomething:here withValue:there]; // ObjC
3047   * return some_vector[1]; // C++
3048   * \endcode
3049   */
3050  CXNameRange_WantSinglePiece = 0x4
3051};
3052
3053/**
3054 * @}
3055 */
3056
3057/**
3058 * \defgroup CINDEX_LEX Token extraction and manipulation
3059 *
3060 * The routines in this group provide access to the tokens within a
3061 * translation unit, along with a semantic mapping of those tokens to
3062 * their corresponding cursors.
3063 *
3064 * @{
3065 */
3066
3067/**
3068 * \brief Describes a kind of token.
3069 */
3070typedef enum CXTokenKind {
3071  /**
3072   * \brief A token that contains some kind of punctuation.
3073   */
3074  CXToken_Punctuation,
3075
3076  /**
3077   * \brief A language keyword.
3078   */
3079  CXToken_Keyword,
3080
3081  /**
3082   * \brief An identifier (that is not a keyword).
3083   */
3084  CXToken_Identifier,
3085
3086  /**
3087   * \brief A numeric, string, or character literal.
3088   */
3089  CXToken_Literal,
3090
3091  /**
3092   * \brief A comment.
3093   */
3094  CXToken_Comment
3095} CXTokenKind;
3096
3097/**
3098 * \brief Describes a single preprocessing token.
3099 */
3100typedef struct {
3101  unsigned int_data[4];
3102  void *ptr_data;
3103} CXToken;
3104
3105/**
3106 * \brief Determine the kind of the given token.
3107 */
3108CINDEX_LINKAGE CXTokenKind clang_getTokenKind(CXToken);
3109
3110/**
3111 * \brief Determine the spelling of the given token.
3112 *
3113 * The spelling of a token is the textual representation of that token, e.g.,
3114 * the text of an identifier or keyword.
3115 */
3116CINDEX_LINKAGE CXString clang_getTokenSpelling(CXTranslationUnit, CXToken);
3117
3118/**
3119 * \brief Retrieve the source location of the given token.
3120 */
3121CINDEX_LINKAGE CXSourceLocation clang_getTokenLocation(CXTranslationUnit,
3122                                                       CXToken);
3123
3124/**
3125 * \brief Retrieve a source range that covers the given token.
3126 */
3127CINDEX_LINKAGE CXSourceRange clang_getTokenExtent(CXTranslationUnit, CXToken);
3128
3129/**
3130 * \brief Tokenize the source code described by the given range into raw
3131 * lexical tokens.
3132 *
3133 * \param TU the translation unit whose text is being tokenized.
3134 *
3135 * \param Range the source range in which text should be tokenized. All of the
3136 * tokens produced by tokenization will fall within this source range,
3137 *
3138 * \param Tokens this pointer will be set to point to the array of tokens
3139 * that occur within the given source range. The returned pointer must be
3140 * freed with clang_disposeTokens() before the translation unit is destroyed.
3141 *
3142 * \param NumTokens will be set to the number of tokens in the \c *Tokens
3143 * array.
3144 *
3145 */
3146CINDEX_LINKAGE void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
3147                                   CXToken **Tokens, unsigned *NumTokens);
3148
3149/**
3150 * \brief Annotate the given set of tokens by providing cursors for each token
3151 * that can be mapped to a specific entity within the abstract syntax tree.
3152 *
3153 * This token-annotation routine is equivalent to invoking
3154 * clang_getCursor() for the source locations of each of the
3155 * tokens. The cursors provided are filtered, so that only those
3156 * cursors that have a direct correspondence to the token are
3157 * accepted. For example, given a function call \c f(x),
3158 * clang_getCursor() would provide the following cursors:
3159 *
3160 *   * when the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
3161 *   * when the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
3162 *   * when the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.
3163 *
3164 * Only the first and last of these cursors will occur within the
3165 * annotate, since the tokens "f" and "x' directly refer to a function
3166 * and a variable, respectively, but the parentheses are just a small
3167 * part of the full syntax of the function call expression, which is
3168 * not provided as an annotation.
3169 *
3170 * \param TU the translation unit that owns the given tokens.
3171 *
3172 * \param Tokens the set of tokens to annotate.
3173 *
3174 * \param NumTokens the number of tokens in \p Tokens.
3175 *
3176 * \param Cursors an array of \p NumTokens cursors, whose contents will be
3177 * replaced with the cursors corresponding to each token.
3178 */
3179CINDEX_LINKAGE void clang_annotateTokens(CXTranslationUnit TU,
3180                                         CXToken *Tokens, unsigned NumTokens,
3181                                         CXCursor *Cursors);
3182
3183/**
3184 * \brief Free the given set of tokens.
3185 */
3186CINDEX_LINKAGE void clang_disposeTokens(CXTranslationUnit TU,
3187                                        CXToken *Tokens, unsigned NumTokens);
3188
3189/**
3190 * @}
3191 */
3192
3193/**
3194 * \defgroup CINDEX_DEBUG Debugging facilities
3195 *
3196 * These routines are used for testing and debugging, only, and should not
3197 * be relied upon.
3198 *
3199 * @{
3200 */
3201
3202/* for debug/testing */
3203CINDEX_LINKAGE CXString clang_getCursorKindSpelling(enum CXCursorKind Kind);
3204CINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3205                                          const char **startBuf,
3206                                          const char **endBuf,
3207                                          unsigned *startLine,
3208                                          unsigned *startColumn,
3209                                          unsigned *endLine,
3210                                          unsigned *endColumn);
3211CINDEX_LINKAGE void clang_enableStackTraces(void);
3212CINDEX_LINKAGE void clang_executeOnThread(void (*fn)(void*), void *user_data,
3213                                          unsigned stack_size);
3214
3215/**
3216 * @}
3217 */
3218
3219/**
3220 * \defgroup CINDEX_CODE_COMPLET Code completion
3221 *
3222 * Code completion involves taking an (incomplete) source file, along with
3223 * knowledge of where the user is actively editing that file, and suggesting
3224 * syntactically- and semantically-valid constructs that the user might want to
3225 * use at that particular point in the source code. These data structures and
3226 * routines provide support for code completion.
3227 *
3228 * @{
3229 */
3230
3231/**
3232 * \brief A semantic string that describes a code-completion result.
3233 *
3234 * A semantic string that describes the formatting of a code-completion
3235 * result as a single "template" of text that should be inserted into the
3236 * source buffer when a particular code-completion result is selected.
3237 * Each semantic string is made up of some number of "chunks", each of which
3238 * contains some text along with a description of what that text means, e.g.,
3239 * the name of the entity being referenced, whether the text chunk is part of
3240 * the template, or whether it is a "placeholder" that the user should replace
3241 * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
3242 * description of the different kinds of chunks.
3243 */
3244typedef void *CXCompletionString;
3245
3246/**
3247 * \brief A single result of code completion.
3248 */
3249typedef struct {
3250  /**
3251   * \brief The kind of entity that this completion refers to.
3252   *
3253   * The cursor kind will be a macro, keyword, or a declaration (one of the
3254   * *Decl cursor kinds), describing the entity that the completion is
3255   * referring to.
3256   *
3257   * \todo In the future, we would like to provide a full cursor, to allow
3258   * the client to extract additional information from declaration.
3259   */
3260  enum CXCursorKind CursorKind;
3261
3262  /**
3263   * \brief The code-completion string that describes how to insert this
3264   * code-completion result into the editing buffer.
3265   */
3266  CXCompletionString CompletionString;
3267} CXCompletionResult;
3268
3269/**
3270 * \brief Describes a single piece of text within a code-completion string.
3271 *
3272 * Each "chunk" within a code-completion string (\c CXCompletionString) is
3273 * either a piece of text with a specific "kind" that describes how that text
3274 * should be interpreted by the client or is another completion string.
3275 */
3276enum CXCompletionChunkKind {
3277  /**
3278   * \brief A code-completion string that describes "optional" text that
3279   * could be a part of the template (but is not required).
3280   *
3281   * The Optional chunk is the only kind of chunk that has a code-completion
3282   * string for its representation, which is accessible via
3283   * \c clang_getCompletionChunkCompletionString(). The code-completion string
3284   * describes an additional part of the template that is completely optional.
3285   * For example, optional chunks can be used to describe the placeholders for
3286   * arguments that match up with defaulted function parameters, e.g. given:
3287   *
3288   * \code
3289   * void f(int x, float y = 3.14, double z = 2.71828);
3290   * \endcode
3291   *
3292   * The code-completion string for this function would contain:
3293   *   - a TypedText chunk for "f".
3294   *   - a LeftParen chunk for "(".
3295   *   - a Placeholder chunk for "int x"
3296   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
3297   *       - a Comma chunk for ","
3298   *       - a Placeholder chunk for "float y"
3299   *       - an Optional chunk containing the last defaulted argument:
3300   *           - a Comma chunk for ","
3301   *           - a Placeholder chunk for "double z"
3302   *   - a RightParen chunk for ")"
3303   *
3304   * There are many ways to handle Optional chunks. Two simple approaches are:
3305   *   - Completely ignore optional chunks, in which case the template for the
3306   *     function "f" would only include the first parameter ("int x").
3307   *   - Fully expand all optional chunks, in which case the template for the
3308   *     function "f" would have all of the parameters.
3309   */
3310  CXCompletionChunk_Optional,
3311  /**
3312   * \brief Text that a user would be expected to type to get this
3313   * code-completion result.
3314   *
3315   * There will be exactly one "typed text" chunk in a semantic string, which
3316   * will typically provide the spelling of a keyword or the name of a
3317   * declaration that could be used at the current code point. Clients are
3318   * expected to filter the code-completion results based on the text in this
3319   * chunk.
3320   */
3321  CXCompletionChunk_TypedText,
3322  /**
3323   * \brief Text that should be inserted as part of a code-completion result.
3324   *
3325   * A "text" chunk represents text that is part of the template to be
3326   * inserted into user code should this particular code-completion result
3327   * be selected.
3328   */
3329  CXCompletionChunk_Text,
3330  /**
3331   * \brief Placeholder text that should be replaced by the user.
3332   *
3333   * A "placeholder" chunk marks a place where the user should insert text
3334   * into the code-completion template. For example, placeholders might mark
3335   * the function parameters for a function declaration, to indicate that the
3336   * user should provide arguments for each of those parameters. The actual
3337   * text in a placeholder is a suggestion for the text to display before
3338   * the user replaces the placeholder with real code.
3339   */
3340  CXCompletionChunk_Placeholder,
3341  /**
3342   * \brief Informative text that should be displayed but never inserted as
3343   * part of the template.
3344   *
3345   * An "informative" chunk contains annotations that can be displayed to
3346   * help the user decide whether a particular code-completion result is the
3347   * right option, but which is not part of the actual template to be inserted
3348   * by code completion.
3349   */
3350  CXCompletionChunk_Informative,
3351  /**
3352   * \brief Text that describes the current parameter when code-completion is
3353   * referring to function call, message send, or template specialization.
3354   *
3355   * A "current parameter" chunk occurs when code-completion is providing
3356   * information about a parameter corresponding to the argument at the
3357   * code-completion point. For example, given a function
3358   *
3359   * \code
3360   * int add(int x, int y);
3361   * \endcode
3362   *
3363   * and the source code \c add(, where the code-completion point is after the
3364   * "(", the code-completion string will contain a "current parameter" chunk
3365   * for "int x", indicating that the current argument will initialize that
3366   * parameter. After typing further, to \c add(17, (where the code-completion
3367   * point is after the ","), the code-completion string will contain a
3368   * "current paremeter" chunk to "int y".
3369   */
3370  CXCompletionChunk_CurrentParameter,
3371  /**
3372   * \brief A left parenthesis ('('), used to initiate a function call or
3373   * signal the beginning of a function parameter list.
3374   */
3375  CXCompletionChunk_LeftParen,
3376  /**
3377   * \brief A right parenthesis (')'), used to finish a function call or
3378   * signal the end of a function parameter list.
3379   */
3380  CXCompletionChunk_RightParen,
3381  /**
3382   * \brief A left bracket ('[').
3383   */
3384  CXCompletionChunk_LeftBracket,
3385  /**
3386   * \brief A right bracket (']').
3387   */
3388  CXCompletionChunk_RightBracket,
3389  /**
3390   * \brief A left brace ('{').
3391   */
3392  CXCompletionChunk_LeftBrace,
3393  /**
3394   * \brief A right brace ('}').
3395   */
3396  CXCompletionChunk_RightBrace,
3397  /**
3398   * \brief A left angle bracket ('<').
3399   */
3400  CXCompletionChunk_LeftAngle,
3401  /**
3402   * \brief A right angle bracket ('>').
3403   */
3404  CXCompletionChunk_RightAngle,
3405  /**
3406   * \brief A comma separator (',').
3407   */
3408  CXCompletionChunk_Comma,
3409  /**
3410   * \brief Text that specifies the result type of a given result.
3411   *
3412   * This special kind of informative chunk is not meant to be inserted into
3413   * the text buffer. Rather, it is meant to illustrate the type that an
3414   * expression using the given completion string would have.
3415   */
3416  CXCompletionChunk_ResultType,
3417  /**
3418   * \brief A colon (':').
3419   */
3420  CXCompletionChunk_Colon,
3421  /**
3422   * \brief A semicolon (';').
3423   */
3424  CXCompletionChunk_SemiColon,
3425  /**
3426   * \brief An '=' sign.
3427   */
3428  CXCompletionChunk_Equal,
3429  /**
3430   * Horizontal space (' ').
3431   */
3432  CXCompletionChunk_HorizontalSpace,
3433  /**
3434   * Vertical space ('\n'), after which it is generally a good idea to
3435   * perform indentation.
3436   */
3437  CXCompletionChunk_VerticalSpace
3438};
3439
3440/**
3441 * \brief Determine the kind of a particular chunk within a completion string.
3442 *
3443 * \param completion_string the completion string to query.
3444 *
3445 * \param chunk_number the 0-based index of the chunk in the completion string.
3446 *
3447 * \returns the kind of the chunk at the index \c chunk_number.
3448 */
3449CINDEX_LINKAGE enum CXCompletionChunkKind
3450clang_getCompletionChunkKind(CXCompletionString completion_string,
3451                             unsigned chunk_number);
3452
3453/**
3454 * \brief Retrieve the text associated with a particular chunk within a
3455 * completion string.
3456 *
3457 * \param completion_string the completion string to query.
3458 *
3459 * \param chunk_number the 0-based index of the chunk in the completion string.
3460 *
3461 * \returns the text associated with the chunk at index \c chunk_number.
3462 */
3463CINDEX_LINKAGE CXString
3464clang_getCompletionChunkText(CXCompletionString completion_string,
3465                             unsigned chunk_number);
3466
3467/**
3468 * \brief Retrieve the completion string associated with a particular chunk
3469 * within a completion string.
3470 *
3471 * \param completion_string the completion string to query.
3472 *
3473 * \param chunk_number the 0-based index of the chunk in the completion string.
3474 *
3475 * \returns the completion string associated with the chunk at index
3476 * \c chunk_number.
3477 */
3478CINDEX_LINKAGE CXCompletionString
3479clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
3480                                         unsigned chunk_number);
3481
3482/**
3483 * \brief Retrieve the number of chunks in the given code-completion string.
3484 */
3485CINDEX_LINKAGE unsigned
3486clang_getNumCompletionChunks(CXCompletionString completion_string);
3487
3488/**
3489 * \brief Determine the priority of this code completion.
3490 *
3491 * The priority of a code completion indicates how likely it is that this
3492 * particular completion is the completion that the user will select. The
3493 * priority is selected by various internal heuristics.
3494 *
3495 * \param completion_string The completion string to query.
3496 *
3497 * \returns The priority of this completion string. Smaller values indicate
3498 * higher-priority (more likely) completions.
3499 */
3500CINDEX_LINKAGE unsigned
3501clang_getCompletionPriority(CXCompletionString completion_string);
3502
3503/**
3504 * \brief Determine the availability of the entity that this code-completion
3505 * string refers to.
3506 *
3507 * \param completion_string The completion string to query.
3508 *
3509 * \returns The availability of the completion string.
3510 */
3511CINDEX_LINKAGE enum CXAvailabilityKind
3512clang_getCompletionAvailability(CXCompletionString completion_string);
3513
3514/**
3515 * \brief Retrieve the number of annotations associated with the given
3516 * completion string.
3517 *
3518 * \param completion_string the completion string to query.
3519 *
3520 * \returns the number of annotations associated with the given completion
3521 * string.
3522 */
3523CINDEX_LINKAGE unsigned
3524clang_getCompletionNumAnnotations(CXCompletionString completion_string);
3525
3526/**
3527 * \brief Retrieve the annotation associated with the given completion string.
3528 *
3529 * \param completion_string the completion string to query.
3530 *
3531 * \param annotation_number the 0-based index of the annotation of the
3532 * completion string.
3533 *
3534 * \returns annotation string associated with the completion at index
3535 * \c annotation_number, or a NULL string if that annotation is not available.
3536 */
3537CINDEX_LINKAGE CXString
3538clang_getCompletionAnnotation(CXCompletionString completion_string,
3539                              unsigned annotation_number);
3540
3541/**
3542 * \brief Retrieve a completion string for an arbitrary declaration or macro
3543 * definition cursor.
3544 *
3545 * \param cursor The cursor to query.
3546 *
3547 * \returns A non-context-sensitive completion string for declaration and macro
3548 * definition cursors, or NULL for other kinds of cursors.
3549 */
3550CINDEX_LINKAGE CXCompletionString
3551clang_getCursorCompletionString(CXCursor cursor);
3552
3553/**
3554 * \brief Contains the results of code-completion.
3555 *
3556 * This data structure contains the results of code completion, as
3557 * produced by \c clang_codeCompleteAt(). Its contents must be freed by
3558 * \c clang_disposeCodeCompleteResults.
3559 */
3560typedef struct {
3561  /**
3562   * \brief The code-completion results.
3563   */
3564  CXCompletionResult *Results;
3565
3566  /**
3567   * \brief The number of code-completion results stored in the
3568   * \c Results array.
3569   */
3570  unsigned NumResults;
3571} CXCodeCompleteResults;
3572
3573/**
3574 * \brief Flags that can be passed to \c clang_codeCompleteAt() to
3575 * modify its behavior.
3576 *
3577 * The enumerators in this enumeration can be bitwise-OR'd together to
3578 * provide multiple options to \c clang_codeCompleteAt().
3579 */
3580enum CXCodeComplete_Flags {
3581  /**
3582   * \brief Whether to include macros within the set of code
3583   * completions returned.
3584   */
3585  CXCodeComplete_IncludeMacros = 0x01,
3586
3587  /**
3588   * \brief Whether to include code patterns for language constructs
3589   * within the set of code completions, e.g., for loops.
3590   */
3591  CXCodeComplete_IncludeCodePatterns = 0x02
3592};
3593
3594/**
3595 * \brief Bits that represent the context under which completion is occurring.
3596 *
3597 * The enumerators in this enumeration may be bitwise-OR'd together if multiple
3598 * contexts are occurring simultaneously.
3599 */
3600enum CXCompletionContext {
3601  /**
3602   * \brief The context for completions is unexposed, as only Clang results
3603   * should be included. (This is equivalent to having no context bits set.)
3604   */
3605  CXCompletionContext_Unexposed = 0,
3606
3607  /**
3608   * \brief Completions for any possible type should be included in the results.
3609   */
3610  CXCompletionContext_AnyType = 1 << 0,
3611
3612  /**
3613   * \brief Completions for any possible value (variables, function calls, etc.)
3614   * should be included in the results.
3615   */
3616  CXCompletionContext_AnyValue = 1 << 1,
3617  /**
3618   * \brief Completions for values that resolve to an Objective-C object should
3619   * be included in the results.
3620   */
3621  CXCompletionContext_ObjCObjectValue = 1 << 2,
3622  /**
3623   * \brief Completions for values that resolve to an Objective-C selector
3624   * should be included in the results.
3625   */
3626  CXCompletionContext_ObjCSelectorValue = 1 << 3,
3627  /**
3628   * \brief Completions for values that resolve to a C++ class type should be
3629   * included in the results.
3630   */
3631  CXCompletionContext_CXXClassTypeValue = 1 << 4,
3632
3633  /**
3634   * \brief Completions for fields of the member being accessed using the dot
3635   * operator should be included in the results.
3636   */
3637  CXCompletionContext_DotMemberAccess = 1 << 5,
3638  /**
3639   * \brief Completions for fields of the member being accessed using the arrow
3640   * operator should be included in the results.
3641   */
3642  CXCompletionContext_ArrowMemberAccess = 1 << 6,
3643  /**
3644   * \brief Completions for properties of the Objective-C object being accessed
3645   * using the dot operator should be included in the results.
3646   */
3647  CXCompletionContext_ObjCPropertyAccess = 1 << 7,
3648
3649  /**
3650   * \brief Completions for enum tags should be included in the results.
3651   */
3652  CXCompletionContext_EnumTag = 1 << 8,
3653  /**
3654   * \brief Completions for union tags should be included in the results.
3655   */
3656  CXCompletionContext_UnionTag = 1 << 9,
3657  /**
3658   * \brief Completions for struct tags should be included in the results.
3659   */
3660  CXCompletionContext_StructTag = 1 << 10,
3661
3662  /**
3663   * \brief Completions for C++ class names should be included in the results.
3664   */
3665  CXCompletionContext_ClassTag = 1 << 11,
3666  /**
3667   * \brief Completions for C++ namespaces and namespace aliases should be
3668   * included in the results.
3669   */
3670  CXCompletionContext_Namespace = 1 << 12,
3671  /**
3672   * \brief Completions for C++ nested name specifiers should be included in
3673   * the results.
3674   */
3675  CXCompletionContext_NestedNameSpecifier = 1 << 13,
3676
3677  /**
3678   * \brief Completions for Objective-C interfaces (classes) should be included
3679   * in the results.
3680   */
3681  CXCompletionContext_ObjCInterface = 1 << 14,
3682  /**
3683   * \brief Completions for Objective-C protocols should be included in
3684   * the results.
3685   */
3686  CXCompletionContext_ObjCProtocol = 1 << 15,
3687  /**
3688   * \brief Completions for Objective-C categories should be included in
3689   * the results.
3690   */
3691  CXCompletionContext_ObjCCategory = 1 << 16,
3692  /**
3693   * \brief Completions for Objective-C instance messages should be included
3694   * in the results.
3695   */
3696  CXCompletionContext_ObjCInstanceMessage = 1 << 17,
3697  /**
3698   * \brief Completions for Objective-C class messages should be included in
3699   * the results.
3700   */
3701  CXCompletionContext_ObjCClassMessage = 1 << 18,
3702  /**
3703   * \brief Completions for Objective-C selector names should be included in
3704   * the results.
3705   */
3706  CXCompletionContext_ObjCSelectorName = 1 << 19,
3707
3708  /**
3709   * \brief Completions for preprocessor macro names should be included in
3710   * the results.
3711   */
3712  CXCompletionContext_MacroName = 1 << 20,
3713
3714  /**
3715   * \brief Natural language completions should be included in the results.
3716   */
3717  CXCompletionContext_NaturalLanguage = 1 << 21,
3718
3719  /**
3720   * \brief The current context is unknown, so set all contexts.
3721   */
3722  CXCompletionContext_Unknown = ((1 << 22) - 1)
3723};
3724
3725/**
3726 * \brief Returns a default set of code-completion options that can be
3727 * passed to\c clang_codeCompleteAt().
3728 */
3729CINDEX_LINKAGE unsigned clang_defaultCodeCompleteOptions(void);
3730
3731/**
3732 * \brief Perform code completion at a given location in a translation unit.
3733 *
3734 * This function performs code completion at a particular file, line, and
3735 * column within source code, providing results that suggest potential
3736 * code snippets based on the context of the completion. The basic model
3737 * for code completion is that Clang will parse a complete source file,
3738 * performing syntax checking up to the location where code-completion has
3739 * been requested. At that point, a special code-completion token is passed
3740 * to the parser, which recognizes this token and determines, based on the
3741 * current location in the C/Objective-C/C++ grammar and the state of
3742 * semantic analysis, what completions to provide. These completions are
3743 * returned via a new \c CXCodeCompleteResults structure.
3744 *
3745 * Code completion itself is meant to be triggered by the client when the
3746 * user types punctuation characters or whitespace, at which point the
3747 * code-completion location will coincide with the cursor. For example, if \c p
3748 * is a pointer, code-completion might be triggered after the "-" and then
3749 * after the ">" in \c p->. When the code-completion location is afer the ">",
3750 * the completion results will provide, e.g., the members of the struct that
3751 * "p" points to. The client is responsible for placing the cursor at the
3752 * beginning of the token currently being typed, then filtering the results
3753 * based on the contents of the token. For example, when code-completing for
3754 * the expression \c p->get, the client should provide the location just after
3755 * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
3756 * client can filter the results based on the current token text ("get"), only
3757 * showing those results that start with "get". The intent of this interface
3758 * is to separate the relatively high-latency acquisition of code-completion
3759 * results from the filtering of results on a per-character basis, which must
3760 * have a lower latency.
3761 *
3762 * \param TU The translation unit in which code-completion should
3763 * occur. The source files for this translation unit need not be
3764 * completely up-to-date (and the contents of those source files may
3765 * be overridden via \p unsaved_files). Cursors referring into the
3766 * translation unit may be invalidated by this invocation.
3767 *
3768 * \param complete_filename The name of the source file where code
3769 * completion should be performed. This filename may be any file
3770 * included in the translation unit.
3771 *
3772 * \param complete_line The line at which code-completion should occur.
3773 *
3774 * \param complete_column The column at which code-completion should occur.
3775 * Note that the column should point just after the syntactic construct that
3776 * initiated code completion, and not in the middle of a lexical token.
3777 *
3778 * \param unsaved_files the Tiles that have not yet been saved to disk
3779 * but may be required for parsing or code completion, including the
3780 * contents of those files.  The contents and name of these files (as
3781 * specified by CXUnsavedFile) are copied when necessary, so the
3782 * client only needs to guarantee their validity until the call to
3783 * this function returns.
3784 *
3785 * \param num_unsaved_files The number of unsaved file entries in \p
3786 * unsaved_files.
3787 *
3788 * \param options Extra options that control the behavior of code
3789 * completion, expressed as a bitwise OR of the enumerators of the
3790 * CXCodeComplete_Flags enumeration. The
3791 * \c clang_defaultCodeCompleteOptions() function returns a default set
3792 * of code-completion options.
3793 *
3794 * \returns If successful, a new \c CXCodeCompleteResults structure
3795 * containing code-completion results, which should eventually be
3796 * freed with \c clang_disposeCodeCompleteResults(). If code
3797 * completion fails, returns NULL.
3798 */
3799CINDEX_LINKAGE
3800CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
3801                                            const char *complete_filename,
3802                                            unsigned complete_line,
3803                                            unsigned complete_column,
3804                                            struct CXUnsavedFile *unsaved_files,
3805                                            unsigned num_unsaved_files,
3806                                            unsigned options);
3807
3808/**
3809 * \brief Sort the code-completion results in case-insensitive alphabetical
3810 * order.
3811 *
3812 * \param Results The set of results to sort.
3813 * \param NumResults The number of results in \p Results.
3814 */
3815CINDEX_LINKAGE
3816void clang_sortCodeCompletionResults(CXCompletionResult *Results,
3817                                     unsigned NumResults);
3818
3819/**
3820 * \brief Free the given set of code-completion results.
3821 */
3822CINDEX_LINKAGE
3823void clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
3824
3825/**
3826 * \brief Determine the number of diagnostics produced prior to the
3827 * location where code completion was performed.
3828 */
3829CINDEX_LINKAGE
3830unsigned clang_codeCompleteGetNumDiagnostics(CXCodeCompleteResults *Results);
3831
3832/**
3833 * \brief Retrieve a diagnostic associated with the given code completion.
3834 *
3835 * \param Result the code completion results to query.
3836 * \param Index the zero-based diagnostic number to retrieve.
3837 *
3838 * \returns the requested diagnostic. This diagnostic must be freed
3839 * via a call to \c clang_disposeDiagnostic().
3840 */
3841CINDEX_LINKAGE
3842CXDiagnostic clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *Results,
3843                                             unsigned Index);
3844
3845/**
3846 * \brief Determines what compeltions are appropriate for the context
3847 * the given code completion.
3848 *
3849 * \param Results the code completion results to query
3850 *
3851 * \returns the kinds of completions that are appropriate for use
3852 * along with the given code completion results.
3853 */
3854CINDEX_LINKAGE
3855unsigned long long clang_codeCompleteGetContexts(
3856                                                CXCodeCompleteResults *Results);
3857
3858/**
3859 * \brief Returns the cursor kind for the container for the current code
3860 * completion context. The container is only guaranteed to be set for
3861 * contexts where a container exists (i.e. member accesses or Objective-C
3862 * message sends); if there is not a container, this function will return
3863 * CXCursor_InvalidCode.
3864 *
3865 * \param Results the code completion results to query
3866 *
3867 * \param IsIncomplete on return, this value will be false if Clang has complete
3868 * information about the container. If Clang does not have complete
3869 * information, this value will be true.
3870 *
3871 * \returns the container kind, or CXCursor_InvalidCode if there is not a
3872 * container
3873 */
3874CINDEX_LINKAGE
3875enum CXCursorKind clang_codeCompleteGetContainerKind(
3876                                                 CXCodeCompleteResults *Results,
3877                                                     unsigned *IsIncomplete);
3878
3879/**
3880 * \brief Returns the USR for the container for the current code completion
3881 * context. If there is not a container for the current context, this
3882 * function will return the empty string.
3883 *
3884 * \param Results the code completion results to query
3885 *
3886 * \returns the USR for the container
3887 */
3888CINDEX_LINKAGE
3889CXString clang_codeCompleteGetContainerUSR(CXCodeCompleteResults *Results);
3890
3891
3892/**
3893 * \brief Returns the currently-entered selector for an Objective-C message
3894 * send, formatted like "initWithFoo:bar:". Only guaranteed to return a
3895 * non-empty string for CXCompletionContext_ObjCInstanceMessage and
3896 * CXCompletionContext_ObjCClassMessage.
3897 *
3898 * \param Results the code completion results to query
3899 *
3900 * \returns the selector (or partial selector) that has been entered thus far
3901 * for an Objective-C message send.
3902 */
3903CINDEX_LINKAGE
3904CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *Results);
3905
3906/**
3907 * @}
3908 */
3909
3910
3911/**
3912 * \defgroup CINDEX_MISC Miscellaneous utility functions
3913 *
3914 * @{
3915 */
3916
3917/**
3918 * \brief Return a version string, suitable for showing to a user, but not
3919 *        intended to be parsed (the format is not guaranteed to be stable).
3920 */
3921CINDEX_LINKAGE CXString clang_getClangVersion();
3922
3923
3924/**
3925 * \brief Enable/disable crash recovery.
3926 *
3927 * \param Flag to indicate if crash recovery is enabled.  A non-zero value
3928 *        enables crash recovery, while 0 disables it.
3929 */
3930CINDEX_LINKAGE void clang_toggleCrashRecovery(unsigned isEnabled);
3931
3932 /**
3933  * \brief Visitor invoked for each file in a translation unit
3934  *        (used with clang_getInclusions()).
3935  *
3936  * This visitor function will be invoked by clang_getInclusions() for each
3937  * file included (either at the top-level or by #include directives) within
3938  * a translation unit.  The first argument is the file being included, and
3939  * the second and third arguments provide the inclusion stack.  The
3940  * array is sorted in order of immediate inclusion.  For example,
3941  * the first element refers to the location that included 'included_file'.
3942  */
3943typedef void (*CXInclusionVisitor)(CXFile included_file,
3944                                   CXSourceLocation* inclusion_stack,
3945                                   unsigned include_len,
3946                                   CXClientData client_data);
3947
3948/**
3949 * \brief Visit the set of preprocessor inclusions in a translation unit.
3950 *   The visitor function is called with the provided data for every included
3951 *   file.  This does not include headers included by the PCH file (unless one
3952 *   is inspecting the inclusions in the PCH file itself).
3953 */
3954CINDEX_LINKAGE void clang_getInclusions(CXTranslationUnit tu,
3955                                        CXInclusionVisitor visitor,
3956                                        CXClientData client_data);
3957
3958/**
3959 * @}
3960 */
3961
3962/** \defgroup CINDEX_REMAPPING Remapping functions
3963 *
3964 * @{
3965 */
3966
3967/**
3968 * \brief A remapping of original source files and their translated files.
3969 */
3970typedef void *CXRemapping;
3971
3972/**
3973 * \brief Retrieve a remapping.
3974 *
3975 * \param path the path that contains metadata about remappings.
3976 *
3977 * \returns the requested remapping. This remapping must be freed
3978 * via a call to \c clang_remap_dispose(). Can return NULL if an error occurred.
3979 */
3980CINDEX_LINKAGE CXRemapping clang_getRemappings(const char *path);
3981
3982/**
3983 * \brief Determine the number of remappings.
3984 */
3985CINDEX_LINKAGE unsigned clang_remap_getNumFiles(CXRemapping);
3986
3987/**
3988 * \brief Get the original and the associated filename from the remapping.
3989 *
3990 * \param original If non-NULL, will be set to the original filename.
3991 *
3992 * \param transformed If non-NULL, will be set to the filename that the original
3993 * is associated with.
3994 */
3995CINDEX_LINKAGE void clang_remap_getFilenames(CXRemapping, unsigned index,
3996                                     CXString *original, CXString *transformed);
3997
3998/**
3999 * \brief Dispose the remapping.
4000 */
4001CINDEX_LINKAGE void clang_remap_dispose(CXRemapping);
4002
4003/**
4004 * @}
4005 */
4006
4007/** \defgroup CINDEX_HIGH Higher level API functions
4008 *
4009 * @{
4010 */
4011
4012enum CXVisitorResult {
4013  CXVisit_Break,
4014  CXVisit_Continue
4015};
4016
4017typedef struct {
4018  void *context;
4019  enum CXVisitorResult (*visit)(void *context, CXCursor, CXSourceRange);
4020} CXCursorAndRangeVisitor;
4021
4022/**
4023 * \brief Find references of a declaration in a specific file.
4024 *
4025 * \param cursor pointing to a declaration or a reference of one.
4026 *
4027 * \param file to search for references.
4028 *
4029 * \param visitor callback that will receive pairs of CXCursor/CXSourceRange for
4030 * each reference found.
4031 * The CXSourceRange will point inside the file; if the reference is inside
4032 * a macro (and not a macro argument) the CXSourceRange will be invalid.
4033 */
4034CINDEX_LINKAGE void clang_findReferencesInFile(CXCursor cursor, CXFile file,
4035                                               CXCursorAndRangeVisitor visitor);
4036
4037#ifdef __has_feature
4038#  if __has_feature(blocks)
4039
4040typedef enum CXVisitorResult
4041    (^CXCursorAndRangeVisitorBlock)(CXCursor, CXSourceRange);
4042
4043CINDEX_LINKAGE
4044void clang_findReferencesInFileWithBlock(CXCursor, CXFile,
4045                                         CXCursorAndRangeVisitorBlock);
4046
4047#  endif
4048#endif
4049
4050/**
4051 * \brief The client's data object that is associated with a CXFile.
4052 */
4053typedef void *CXIdxClientFile;
4054
4055/**
4056 * \brief The client's data object that is associated with a semantic entity.
4057 */
4058typedef void *CXIdxClientEntity;
4059
4060/**
4061 * \brief The client's data object that is associated with a semantic container
4062 * of entities.
4063 */
4064typedef void *CXIdxClientContainer;
4065
4066/**
4067 * \brief The client's data object that is associated with an AST file (PCH
4068 * or module).
4069 */
4070typedef void *CXIdxClientASTFile;
4071
4072/**
4073 * \brief Source location passed to index callbacks.
4074 */
4075typedef struct {
4076  void *ptr_data[2];
4077  unsigned int_data;
4078} CXIdxLoc;
4079
4080/**
4081 * \brief Data for \see ppIncludedFile callback.
4082 */
4083typedef struct {
4084  /**
4085   * \brief Location of '#' in the #include/#import directive.
4086   */
4087  CXIdxLoc hashLoc;
4088  /**
4089   * \brief Filename as written in the #include/#import directive.
4090   */
4091  const char *filename;
4092  /**
4093   * \brief The actual file that the #include/#import directive resolved to.
4094   */
4095  CXFile file;
4096  int isImport;
4097  int isAngled;
4098} CXIdxIncludedFileInfo;
4099
4100/**
4101 * \brief Data for \see importedASTFile callback.
4102 */
4103typedef struct {
4104  CXFile file;
4105  /**
4106   * \brief Location where the file is imported. It is useful mostly for
4107   * modules.
4108   */
4109  CXIdxLoc loc;
4110  /**
4111   * \brief Non-zero if the AST file is a module otherwise it's a PCH.
4112   */
4113  int isModule;
4114} CXIdxImportedASTFileInfo;
4115
4116typedef enum {
4117  CXIdxEntity_Unexposed     = 0,
4118  CXIdxEntity_Typedef       = 1,
4119  CXIdxEntity_Function      = 2,
4120  CXIdxEntity_Variable      = 3,
4121  CXIdxEntity_Field         = 4,
4122  CXIdxEntity_EnumConstant  = 5,
4123
4124  CXIdxEntity_ObjCClass     = 6,
4125  CXIdxEntity_ObjCProtocol  = 7,
4126  CXIdxEntity_ObjCCategory  = 8,
4127
4128  CXIdxEntity_ObjCInstanceMethod = 9,
4129  CXIdxEntity_ObjCClassMethod    = 10,
4130  CXIdxEntity_ObjCProperty  = 11,
4131  CXIdxEntity_ObjCIvar      = 12,
4132
4133  CXIdxEntity_Enum          = 13,
4134  CXIdxEntity_Struct        = 14,
4135  CXIdxEntity_Union         = 15,
4136
4137  CXIdxEntity_CXXClass              = 16,
4138  CXIdxEntity_CXXNamespace          = 17,
4139  CXIdxEntity_CXXNamespaceAlias     = 18,
4140  CXIdxEntity_CXXStaticVariable     = 19,
4141  CXIdxEntity_CXXStaticMethod       = 20,
4142  CXIdxEntity_CXXInstanceMethod     = 21,
4143  CXIdxEntity_CXXConstructor        = 22,
4144  CXIdxEntity_CXXDestructor         = 23,
4145  CXIdxEntity_CXXConversionFunction = 24,
4146  CXIdxEntity_CXXTypeAlias          = 25
4147
4148} CXIdxEntityKind;
4149
4150typedef enum {
4151  CXIdxEntityLang_None = 0,
4152  CXIdxEntityLang_C    = 1,
4153  CXIdxEntityLang_ObjC = 2,
4154  CXIdxEntityLang_CXX  = 3
4155} CXIdxEntityLanguage;
4156
4157/**
4158 * \brief Extra C++ template information for an entity. This can apply to:
4159 * CXIdxEntity_Function
4160 * CXIdxEntity_CXXClass
4161 * CXIdxEntity_CXXStaticMethod
4162 * CXIdxEntity_CXXInstanceMethod
4163 * CXIdxEntity_CXXConstructor
4164 * CXIdxEntity_CXXConversionFunction
4165 * CXIdxEntity_CXXTypeAlias
4166 */
4167typedef enum {
4168  CXIdxEntity_NonTemplate   = 0,
4169  CXIdxEntity_Template      = 1,
4170  CXIdxEntity_TemplatePartialSpecialization = 2,
4171  CXIdxEntity_TemplateSpecialization = 3
4172} CXIdxEntityCXXTemplateKind;
4173
4174typedef enum {
4175  CXIdxAttr_Unexposed     = 0,
4176  CXIdxAttr_IBAction      = 1,
4177  CXIdxAttr_IBOutlet      = 2,
4178  CXIdxAttr_IBOutletCollection = 3
4179} CXIdxAttrKind;
4180
4181typedef struct {
4182  CXIdxAttrKind kind;
4183  CXCursor cursor;
4184  CXIdxLoc loc;
4185} CXIdxAttrInfo;
4186
4187typedef struct {
4188  CXIdxEntityKind kind;
4189  CXIdxEntityCXXTemplateKind templateKind;
4190  CXIdxEntityLanguage lang;
4191  const char *name;
4192  const char *USR;
4193  CXCursor cursor;
4194  const CXIdxAttrInfo *const *attributes;
4195  unsigned numAttributes;
4196} CXIdxEntityInfo;
4197
4198typedef struct {
4199  CXCursor cursor;
4200} CXIdxContainerInfo;
4201
4202typedef struct {
4203  const CXIdxAttrInfo *attrInfo;
4204  const CXIdxEntityInfo *objcClass;
4205  CXCursor classCursor;
4206  CXIdxLoc classLoc;
4207} CXIdxIBOutletCollectionAttrInfo;
4208
4209typedef struct {
4210  const CXIdxEntityInfo *entityInfo;
4211  CXCursor cursor;
4212  CXIdxLoc loc;
4213  const CXIdxContainerInfo *semanticContainer;
4214  /**
4215   * \brief Generally same as \see semanticContainer but can be different in
4216   * cases like out-of-line C++ member functions.
4217   */
4218  const CXIdxContainerInfo *lexicalContainer;
4219  int isRedeclaration;
4220  int isDefinition;
4221  int isContainer;
4222  const CXIdxContainerInfo *declAsContainer;
4223  /**
4224   * \brief Whether the declaration exists in code or was created implicitly
4225   * by the compiler, e.g. implicit objc methods for properties.
4226   */
4227  int isImplicit;
4228  const CXIdxAttrInfo *const *attributes;
4229  unsigned numAttributes;
4230} CXIdxDeclInfo;
4231
4232typedef enum {
4233  CXIdxObjCContainer_ForwardRef = 0,
4234  CXIdxObjCContainer_Interface = 1,
4235  CXIdxObjCContainer_Implementation = 2
4236} CXIdxObjCContainerKind;
4237
4238typedef struct {
4239  const CXIdxDeclInfo *declInfo;
4240  CXIdxObjCContainerKind kind;
4241} CXIdxObjCContainerDeclInfo;
4242
4243typedef struct {
4244  const CXIdxEntityInfo *base;
4245  CXCursor cursor;
4246  CXIdxLoc loc;
4247} CXIdxBaseClassInfo;
4248
4249typedef struct {
4250  const CXIdxEntityInfo *protocol;
4251  CXCursor cursor;
4252  CXIdxLoc loc;
4253} CXIdxObjCProtocolRefInfo;
4254
4255typedef struct {
4256  const CXIdxObjCProtocolRefInfo *const *protocols;
4257  unsigned numProtocols;
4258} CXIdxObjCProtocolRefListInfo;
4259
4260typedef struct {
4261  const CXIdxObjCContainerDeclInfo *containerInfo;
4262  const CXIdxBaseClassInfo *superInfo;
4263  const CXIdxObjCProtocolRefListInfo *protocols;
4264} CXIdxObjCInterfaceDeclInfo;
4265
4266typedef struct {
4267  const CXIdxObjCContainerDeclInfo *containerInfo;
4268  const CXIdxEntityInfo *objcClass;
4269  CXCursor classCursor;
4270  CXIdxLoc classLoc;
4271  const CXIdxObjCProtocolRefListInfo *protocols;
4272} CXIdxObjCCategoryDeclInfo;
4273
4274typedef struct {
4275  const CXIdxDeclInfo *declInfo;
4276  const CXIdxBaseClassInfo *const *bases;
4277  unsigned numBases;
4278} CXIdxCXXClassDeclInfo;
4279
4280/**
4281 * \brief Data for \see indexEntityReference callback.
4282 */
4283typedef enum {
4284  /**
4285   * \brief The entity is referenced directly in user's code.
4286   */
4287  CXIdxEntityRef_Direct = 1,
4288  /**
4289   * \brief An implicit reference, e.g. a reference of an ObjC method via the
4290   * dot syntax.
4291   */
4292  CXIdxEntityRef_Implicit = 2
4293} CXIdxEntityRefKind;
4294
4295/**
4296 * \brief Data for \see indexEntityReference callback.
4297 */
4298typedef struct {
4299  CXIdxEntityRefKind kind;
4300  /**
4301   * \brief Reference cursor.
4302   */
4303  CXCursor cursor;
4304  CXIdxLoc loc;
4305  /**
4306   * \brief The entity that gets referenced.
4307   */
4308  const CXIdxEntityInfo *referencedEntity;
4309  /**
4310   * \brief Immediate "parent" of the reference. For example:
4311   *
4312   * \code
4313   * Foo *var;
4314   * \endcode
4315   *
4316   * The parent of reference of type 'Foo' is the variable 'var'.
4317   * For references inside statement bodies of functions/methods,
4318   * the parentEntity will be the function/method.
4319   */
4320  const CXIdxEntityInfo *parentEntity;
4321  /**
4322   * \brief Lexical container context of the reference.
4323   */
4324  const CXIdxContainerInfo *container;
4325} CXIdxEntityRefInfo;
4326
4327typedef struct {
4328  /**
4329   * \brief Called periodically to check whether indexing should be aborted.
4330   * Should return 0 to continue, and non-zero to abort.
4331   */
4332  int (*abortQuery)(CXClientData client_data, void *reserved);
4333
4334  /**
4335   * \brief Called at the end of indexing; passes the complete diagnostic set.
4336   */
4337  void (*diagnostic)(CXClientData client_data,
4338                     CXDiagnosticSet, void *reserved);
4339
4340  CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
4341                               CXFile mainFile, void *reserved);
4342
4343  /**
4344   * \brief Called when a file gets #included/#imported.
4345   */
4346  CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
4347                                    const CXIdxIncludedFileInfo *);
4348
4349  /**
4350   * \brief Called when a AST file (PCH or module) gets imported.
4351   *
4352   * AST files will not get indexed (there will not be callbacks to index all
4353   * the entities in an AST file). The recommended action is that, if the AST
4354   * file is not already indexed, to block further indexing and initiate a new
4355   * indexing job specific to the AST file.
4356   */
4357  CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
4358                                        const CXIdxImportedASTFileInfo *);
4359
4360  /**
4361   * \brief Called at the beginning of indexing a translation unit.
4362   */
4363  CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
4364                                                 void *reserved);
4365
4366  void (*indexDeclaration)(CXClientData client_data,
4367                           const CXIdxDeclInfo *);
4368
4369  /**
4370   * \brief Called to index a reference of an entity.
4371   */
4372  void (*indexEntityReference)(CXClientData client_data,
4373                               const CXIdxEntityRefInfo *);
4374
4375} IndexerCallbacks;
4376
4377CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
4378CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
4379clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
4380
4381CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
4382clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
4383
4384CINDEX_LINKAGE
4385const CXIdxObjCCategoryDeclInfo *
4386clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
4387
4388CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
4389clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
4390
4391CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
4392clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
4393
4394CINDEX_LINKAGE const CXIdxCXXClassDeclInfo *
4395clang_index_getCXXClassDeclInfo(const CXIdxDeclInfo *);
4396
4397/**
4398 * \brief For retrieving a custom CXIdxClientContainer attached to a
4399 * container.
4400 */
4401CINDEX_LINKAGE CXIdxClientContainer
4402clang_index_getClientContainer(const CXIdxContainerInfo *);
4403
4404/**
4405 * \brief For setting a custom CXIdxClientContainer attached to a
4406 * container.
4407 */
4408CINDEX_LINKAGE void
4409clang_index_setClientContainer(const CXIdxContainerInfo *,CXIdxClientContainer);
4410
4411/**
4412 * \brief For retrieving a custom CXIdxClientEntity attached to an entity.
4413 */
4414CINDEX_LINKAGE CXIdxClientEntity
4415clang_index_getClientEntity(const CXIdxEntityInfo *);
4416
4417/**
4418 * \brief For setting a custom CXIdxClientEntity attached to an entity.
4419 */
4420CINDEX_LINKAGE void
4421clang_index_setClientEntity(const CXIdxEntityInfo *, CXIdxClientEntity);
4422
4423/**
4424 * \brief An indexing action, to be applied to one or multiple translation units
4425 * but not on concurrent threads. If there are threads doing indexing
4426 * concurrently, they should use different CXIndexAction objects.
4427 */
4428typedef void *CXIndexAction;
4429
4430/**
4431 * \brief An indexing action, to be applied to one or multiple translation units
4432 * but not on concurrent threads. If there are threads doing indexing
4433 * concurrently, they should use different CXIndexAction objects.
4434 *
4435 * \param CIdx The index object with which the index action will be associated.
4436 */
4437CINDEX_LINKAGE CXIndexAction clang_IndexAction_create(CXIndex CIdx);
4438
4439/**
4440 * \brief Destroy the given index action.
4441 *
4442 * The index action must not be destroyed until all of the translation units
4443 * created within that index action have been destroyed.
4444 */
4445CINDEX_LINKAGE void clang_IndexAction_dispose(CXIndexAction);
4446
4447typedef enum {
4448  /**
4449   * \brief Used to indicate that no special indexing options are needed.
4450   */
4451  CXIndexOpt_None = 0x0,
4452
4453  /**
4454   * \brief Used to indicate that \see indexEntityReference should be invoked
4455   * for only one reference of an entity per source file that does not also
4456   * include a declaration/definition of the entity.
4457   */
4458  CXIndexOpt_SuppressRedundantRefs = 0x1,
4459
4460  /**
4461   * \brief Function-local symbols should be indexed. If this is not set
4462   * function-local symbols will be ignored.
4463   */
4464  CXIndexOpt_IndexFunctionLocalSymbols = 0x2
4465} CXIndexOptFlags;
4466
4467/**
4468 * \brief Index the given source file and the translation unit corresponding
4469 * to that file via callbacks implemented through \see IndexerCallbacks.
4470 *
4471 * \param client_data pointer data supplied by the client, which will
4472 * be passed to the invoked callbacks.
4473 *
4474 * \param index_callbacks Pointer to indexing callbacks that the client
4475 * implements.
4476 *
4477 * \param index_callbacks_size Size of \see IndexerCallbacks structure that gets
4478 * passed in index_callbacks.
4479 *
4480 * \param index_options A bitmask of options that affects how indexing is
4481 * performed. This should be a bitwise OR of the CXIndexOpt_XXX flags.
4482 *
4483 * \param out_TU [out] pointer to store a CXTranslationUnit that can be reused
4484 * after indexing is finished. Set to NULL if you do not require it.
4485 *
4486 * \returns If there is a failure from which the there is no recovery, returns
4487 * non-zero, otherwise returns 0.
4488 *
4489 * The rest of the parameters are the same as \see clang_parseTranslationUnit.
4490 */
4491CINDEX_LINKAGE int clang_indexSourceFile(CXIndexAction,
4492                                         CXClientData client_data,
4493                                         IndexerCallbacks *index_callbacks,
4494                                         unsigned index_callbacks_size,
4495                                         unsigned index_options,
4496                                         const char *source_filename,
4497                                         const char * const *command_line_args,
4498                                         int num_command_line_args,
4499                                         struct CXUnsavedFile *unsaved_files,
4500                                         unsigned num_unsaved_files,
4501                                         CXTranslationUnit *out_TU,
4502                                         unsigned TU_options);
4503
4504/**
4505 * \brief Index the given translation unit via callbacks implemented through
4506 * \see IndexerCallbacks.
4507 *
4508 * The order of callback invocations is not guaranteed to be the same as
4509 * when indexing a source file. The high level order will be:
4510 *
4511 *   -Preprocessor callbacks invocations
4512 *   -Declaration/reference callbacks invocations
4513 *   -Diagnostic callback invocations
4514 *
4515 * The parameters are the same as \see clang_indexSourceFile.
4516 *
4517 * \returns If there is a failure from which the there is no recovery, returns
4518 * non-zero, otherwise returns 0.
4519 */
4520CINDEX_LINKAGE int clang_indexTranslationUnit(CXIndexAction,
4521                                              CXClientData client_data,
4522                                              IndexerCallbacks *index_callbacks,
4523                                              unsigned index_callbacks_size,
4524                                              unsigned index_options,
4525                                              CXTranslationUnit);
4526
4527/**
4528 * \brief Retrieve the CXIdxFile, file, line, column, and offset represented by
4529 * the given CXIdxLoc.
4530 *
4531 * If the location refers into a macro expansion, retrieves the
4532 * location of the macro expansion and if it refers into a macro argument
4533 * retrieves the location of the argument.
4534 */
4535CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
4536                                                   CXIdxClientFile *indexFile,
4537                                                   CXFile *file,
4538                                                   unsigned *line,
4539                                                   unsigned *column,
4540                                                   unsigned *offset);
4541
4542/**
4543 * \brief Retrieve the CXSourceLocation represented by the given CXIdxLoc.
4544 */
4545CINDEX_LINKAGE
4546CXSourceLocation clang_indexLoc_getCXSourceLocation(CXIdxLoc loc);
4547
4548/**
4549 * @}
4550 */
4551
4552/**
4553 * @}
4554 */
4555
4556#ifdef __cplusplus
4557}
4558#endif
4559#endif
4560
4561