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