Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5784 lines
187 KiB

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