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