CXSourceLocation.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. /*===-- clang-c/CXSourceLocation.h - C Index Source Location ------*- C -*-===*\
  7. |* *|
  8. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
  9. |* Exceptions. *|
  10. |* See https://llvm.org/LICENSE.txt for license information. *|
  11. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
  12. |* *|
  13. |*===----------------------------------------------------------------------===*|
  14. |* *|
  15. |* This header provides the interface to C Index source locations. *|
  16. |* *|
  17. \*===----------------------------------------------------------------------===*/
  18. #ifndef LLVM_CLANG_C_CXSOURCE_LOCATION_H
  19. #define LLVM_CLANG_C_CXSOURCE_LOCATION_H
  20. #include "clang-c/CXFile.h"
  21. #include "clang-c/CXString.h"
  22. #include "clang-c/ExternC.h"
  23. #include "clang-c/Platform.h"
  24. LLVM_CLANG_C_EXTERN_C_BEGIN
  25. /**
  26. * \defgroup CINDEX_LOCATIONS Physical source locations
  27. *
  28. * Clang represents physical source locations in its abstract syntax tree in
  29. * great detail, with file, line, and column information for the majority of
  30. * the tokens parsed in the source code. These data types and functions are
  31. * used to represent source location information, either for a particular
  32. * point in the program or for a range of points in the program, and extract
  33. * specific location information from those data types.
  34. *
  35. * @{
  36. */
  37. /**
  38. * Identifies a specific source location within a translation
  39. * unit.
  40. *
  41. * Use clang_getExpansionLocation() or clang_getSpellingLocation()
  42. * to map a source location to a particular file, line, and column.
  43. */
  44. typedef struct {
  45. const void *ptr_data[2];
  46. unsigned int_data;
  47. } CXSourceLocation;
  48. /**
  49. * Identifies a half-open character range in the source code.
  50. *
  51. * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
  52. * starting and end locations from a source range, respectively.
  53. */
  54. typedef struct {
  55. const void *ptr_data[2];
  56. unsigned begin_int_data;
  57. unsigned end_int_data;
  58. } CXSourceRange;
  59. /**
  60. * Retrieve a NULL (invalid) source location.
  61. */
  62. CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
  63. /**
  64. * Determine whether two source locations, which must refer into
  65. * the same translation unit, refer to exactly the same point in the source
  66. * code.
  67. *
  68. * \returns non-zero if the source locations refer to the same location, zero
  69. * if they refer to different locations.
  70. */
  71. CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
  72. CXSourceLocation loc2);
  73. /**
  74. * Returns non-zero if the given source location is in a system header.
  75. */
  76. CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
  77. /**
  78. * Returns non-zero if the given source location is in the main file of
  79. * the corresponding translation unit.
  80. */
  81. CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
  82. /**
  83. * Retrieve a NULL (invalid) source range.
  84. */
  85. CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
  86. /**
  87. * Retrieve a source range given the beginning and ending source
  88. * locations.
  89. */
  90. CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
  91. CXSourceLocation end);
  92. /**
  93. * Determine whether two ranges are equivalent.
  94. *
  95. * \returns non-zero if the ranges are the same, zero if they differ.
  96. */
  97. CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
  98. CXSourceRange range2);
  99. /**
  100. * Returns non-zero if \p range is null.
  101. */
  102. CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
  103. /**
  104. * Retrieve the file, line, column, and offset represented by
  105. * the given source location.
  106. *
  107. * If the location refers into a macro expansion, retrieves the
  108. * location of the macro expansion.
  109. *
  110. * \param location the location within a source file that will be decomposed
  111. * into its parts.
  112. *
  113. * \param file [out] if non-NULL, will be set to the file to which the given
  114. * source location points.
  115. *
  116. * \param line [out] if non-NULL, will be set to the line to which the given
  117. * source location points.
  118. *
  119. * \param column [out] if non-NULL, will be set to the column to which the given
  120. * source location points.
  121. *
  122. * \param offset [out] if non-NULL, will be set to the offset into the
  123. * buffer to which the given source location points.
  124. */
  125. CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
  126. CXFile *file, unsigned *line,
  127. unsigned *column,
  128. unsigned *offset);
  129. /**
  130. * Retrieve the file, line and column represented by the given source
  131. * location, as specified in a # line directive.
  132. *
  133. * Example: given the following source code in a file somefile.c
  134. *
  135. * \code
  136. * #123 "dummy.c" 1
  137. *
  138. * static int func(void)
  139. * {
  140. * return 0;
  141. * }
  142. * \endcode
  143. *
  144. * the location information returned by this function would be
  145. *
  146. * File: dummy.c Line: 124 Column: 12
  147. *
  148. * whereas clang_getExpansionLocation would have returned
  149. *
  150. * File: somefile.c Line: 3 Column: 12
  151. *
  152. * \param location the location within a source file that will be decomposed
  153. * into its parts.
  154. *
  155. * \param filename [out] if non-NULL, will be set to the filename of the
  156. * source location. Note that filenames returned will be for "virtual" files,
  157. * which don't necessarily exist on the machine running clang - e.g. when
  158. * parsing preprocessed output obtained from a different environment. If
  159. * a non-NULL value is passed in, remember to dispose of the returned value
  160. * using \c clang_disposeString() once you've finished with it. For an invalid
  161. * source location, an empty string is returned.
  162. *
  163. * \param line [out] if non-NULL, will be set to the line number of the
  164. * source location. For an invalid source location, zero is returned.
  165. *
  166. * \param column [out] if non-NULL, will be set to the column number of the
  167. * source location. For an invalid source location, zero is returned.
  168. */
  169. CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
  170. CXString *filename,
  171. unsigned *line, unsigned *column);
  172. /**
  173. * Legacy API to retrieve the file, line, column, and offset represented
  174. * by the given source location.
  175. *
  176. * This interface has been replaced by the newer interface
  177. * #clang_getExpansionLocation(). See that interface's documentation for
  178. * details.
  179. */
  180. CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
  181. CXFile *file, unsigned *line,
  182. unsigned *column,
  183. unsigned *offset);
  184. /**
  185. * Retrieve the file, line, column, and offset represented by
  186. * the given source location.
  187. *
  188. * If the location refers into a macro instantiation, return where the
  189. * location was originally spelled in the source file.
  190. *
  191. * \param location the location within a source file that will be decomposed
  192. * into its parts.
  193. *
  194. * \param file [out] if non-NULL, will be set to the file to which the given
  195. * source location points.
  196. *
  197. * \param line [out] if non-NULL, will be set to the line to which the given
  198. * source location points.
  199. *
  200. * \param column [out] if non-NULL, will be set to the column to which the given
  201. * source location points.
  202. *
  203. * \param offset [out] if non-NULL, will be set to the offset into the
  204. * buffer to which the given source location points.
  205. */
  206. CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
  207. CXFile *file, unsigned *line,
  208. unsigned *column,
  209. unsigned *offset);
  210. /**
  211. * Retrieve the file, line, column, and offset represented by
  212. * the given source location.
  213. *
  214. * If the location refers into a macro expansion, return where the macro was
  215. * expanded or where the macro argument was written, if the location points at
  216. * a macro argument.
  217. *
  218. * \param location the location within a source file that will be decomposed
  219. * into its parts.
  220. *
  221. * \param file [out] if non-NULL, will be set to the file to which the given
  222. * source location points.
  223. *
  224. * \param line [out] if non-NULL, will be set to the line to which the given
  225. * source location points.
  226. *
  227. * \param column [out] if non-NULL, will be set to the column to which the given
  228. * source location points.
  229. *
  230. * \param offset [out] if non-NULL, will be set to the offset into the
  231. * buffer to which the given source location points.
  232. */
  233. CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
  234. CXFile *file, unsigned *line,
  235. unsigned *column, unsigned *offset);
  236. /**
  237. * Retrieve a source location representing the first character within a
  238. * source range.
  239. */
  240. CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
  241. /**
  242. * Retrieve a source location representing the last character within a
  243. * source range.
  244. */
  245. CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
  246. /**
  247. * Identifies an array of ranges.
  248. */
  249. typedef struct {
  250. /** The number of ranges in the \c ranges array. */
  251. unsigned count;
  252. /**
  253. * An array of \c CXSourceRanges.
  254. */
  255. CXSourceRange *ranges;
  256. } CXSourceRangeList;
  257. /**
  258. * Destroy the given \c CXSourceRangeList.
  259. */
  260. CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
  261. /**
  262. * @}
  263. */
  264. LLVM_CLANG_C_EXTERN_C_END
  265. #endif
  266. #ifdef __GNUC__
  267. #pragma GCC diagnostic pop
  268. #endif