[lldb] Fix warning: 'sprintf' is deprecated in RNBSocketTest
[llvm-project.git] / clang / include / clang-c / CXSourceLocation.h
blob421802151d02ab8c3c342e358a90a0305cf945db
1 /*===-- clang-c/CXSourceLocation.h - C Index Source Location ------*- C -*-===*\
2 |* *|
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
4 |* Exceptions. *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This header provides the interface to C Index source locations. *|
11 |* *|
12 \*===----------------------------------------------------------------------===*/
14 #ifndef LLVM_CLANG_C_CXSOURCE_LOCATION_H
15 #define LLVM_CLANG_C_CXSOURCE_LOCATION_H
17 #include "clang-c/CXFile.h"
18 #include "clang-c/CXString.h"
19 #include "clang-c/ExternC.h"
20 #include "clang-c/Platform.h"
22 LLVM_CLANG_C_EXTERN_C_BEGIN
24 /**
25 * \defgroup CINDEX_LOCATIONS Physical source locations
27 * Clang represents physical source locations in its abstract syntax tree in
28 * great detail, with file, line, and column information for the majority of
29 * the tokens parsed in the source code. These data types and functions are
30 * used to represent source location information, either for a particular
31 * point in the program or for a range of points in the program, and extract
32 * specific location information from those data types.
34 * @{
37 /**
38 * Identifies a specific source location within a translation
39 * unit.
41 * Use clang_getExpansionLocation() or clang_getSpellingLocation()
42 * to map a source location to a particular file, line, and column.
44 typedef struct {
45 const void *ptr_data[2];
46 unsigned int_data;
47 } CXSourceLocation;
49 /**
50 * Identifies a half-open character range in the source code.
52 * Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the
53 * starting and end locations from a source range, respectively.
55 typedef struct {
56 const void *ptr_data[2];
57 unsigned begin_int_data;
58 unsigned end_int_data;
59 } CXSourceRange;
61 /**
62 * Retrieve a NULL (invalid) source location.
64 CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);
66 /**
67 * Determine whether two source locations, which must refer into
68 * the same translation unit, refer to exactly the same point in the source
69 * code.
71 * \returns non-zero if the source locations refer to the same location, zero
72 * if they refer to different locations.
74 CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,
75 CXSourceLocation loc2);
77 /**
78 * Determine for two source locations if the first comes
79 * strictly before the second one in the source code.
81 * \returns non-zero if the first source location comes
82 * strictly before the second one, zero otherwise.
84 CINDEX_LINKAGE unsigned clang_isBeforeInTranslationUnit(CXSourceLocation loc1,
85 CXSourceLocation loc2);
87 /**
88 * Returns non-zero if the given source location is in a system header.
90 CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
92 /**
93 * Returns non-zero if the given source location is in the main file of
94 * the corresponding translation unit.
96 CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
98 /**
99 * Retrieve a NULL (invalid) source range.
101 CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
104 * Retrieve a source range given the beginning and ending source
105 * locations.
107 CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
108 CXSourceLocation end);
111 * Determine whether two ranges are equivalent.
113 * \returns non-zero if the ranges are the same, zero if they differ.
115 CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
116 CXSourceRange range2);
119 * Returns non-zero if \p range is null.
121 CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
124 * Retrieve the file, line, column, and offset represented by
125 * the given source location.
127 * If the location refers into a macro expansion, retrieves the
128 * location of the macro expansion.
130 * \param location the location within a source file that will be decomposed
131 * into its parts.
133 * \param file [out] if non-NULL, will be set to the file to which the given
134 * source location points.
136 * \param line [out] if non-NULL, will be set to the line to which the given
137 * source location points.
139 * \param column [out] if non-NULL, will be set to the column to which the given
140 * source location points.
142 * \param offset [out] if non-NULL, will be set to the offset into the
143 * buffer to which the given source location points.
145 CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
146 CXFile *file, unsigned *line,
147 unsigned *column,
148 unsigned *offset);
151 * Retrieve the file, line and column represented by the given source
152 * location, as specified in a # line directive.
154 * Example: given the following source code in a file somefile.c
156 * \code
157 * #123 "dummy.c" 1
159 * static int func(void)
161 * return 0;
163 * \endcode
165 * the location information returned by this function would be
167 * File: dummy.c Line: 124 Column: 12
169 * whereas clang_getExpansionLocation would have returned
171 * File: somefile.c Line: 3 Column: 12
173 * \param location the location within a source file that will be decomposed
174 * into its parts.
176 * \param filename [out] if non-NULL, will be set to the filename of the
177 * source location. Note that filenames returned will be for "virtual" files,
178 * which don't necessarily exist on the machine running clang - e.g. when
179 * parsing preprocessed output obtained from a different environment. If
180 * a non-NULL value is passed in, remember to dispose of the returned value
181 * using \c clang_disposeString() once you've finished with it. For an invalid
182 * source location, an empty string is returned.
184 * \param line [out] if non-NULL, will be set to the line number of the
185 * source location. For an invalid source location, zero is returned.
187 * \param column [out] if non-NULL, will be set to the column number of the
188 * source location. For an invalid source location, zero is returned.
190 CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
191 CXString *filename,
192 unsigned *line, unsigned *column);
195 * Legacy API to retrieve the file, line, column, and offset represented
196 * by the given source location.
198 * This interface has been replaced by the newer interface
199 * #clang_getExpansionLocation(). See that interface's documentation for
200 * details.
202 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
203 CXFile *file, unsigned *line,
204 unsigned *column,
205 unsigned *offset);
208 * Retrieve the file, line, column, and offset represented by
209 * the given source location.
211 * If the location refers into a macro instantiation, return where the
212 * location was originally spelled in the source file.
214 * \param location the location within a source file that will be decomposed
215 * into its parts.
217 * \param file [out] if non-NULL, will be set to the file to which the given
218 * source location points.
220 * \param line [out] if non-NULL, will be set to the line to which the given
221 * source location points.
223 * \param column [out] if non-NULL, will be set to the column to which the given
224 * source location points.
226 * \param offset [out] if non-NULL, will be set to the offset into the
227 * buffer to which the given source location points.
229 CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
230 CXFile *file, unsigned *line,
231 unsigned *column,
232 unsigned *offset);
235 * Retrieve the file, line, column, and offset represented by
236 * the given source location.
238 * If the location refers into a macro expansion, return where the macro was
239 * expanded or where the macro argument was written, if the location points at
240 * a macro argument.
242 * \param location the location within a source file that will be decomposed
243 * into its parts.
245 * \param file [out] if non-NULL, will be set to the file to which the given
246 * source location points.
248 * \param line [out] if non-NULL, will be set to the line to which the given
249 * source location points.
251 * \param column [out] if non-NULL, will be set to the column to which the given
252 * source location points.
254 * \param offset [out] if non-NULL, will be set to the offset into the
255 * buffer to which the given source location points.
257 CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
258 CXFile *file, unsigned *line,
259 unsigned *column, unsigned *offset);
262 * Retrieve a source location representing the first character within a
263 * source range.
265 CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
268 * Retrieve a source location representing the last character within a
269 * source range.
271 CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
274 * Identifies an array of ranges.
276 typedef struct {
277 /** The number of ranges in the \c ranges array. */
278 unsigned count;
280 * An array of \c CXSourceRanges.
282 CXSourceRange *ranges;
283 } CXSourceRangeList;
286 * Destroy the given \c CXSourceRangeList.
288 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
291 * @}
294 LLVM_CLANG_C_EXTERN_C_END
296 #endif