Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / include / clang-c / CXSourceLocation.h
blobdcb13ba273173fdb9c141e34f932ff575b312738
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 * Returns non-zero if the given source location is in a system header.
80 CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);
82 /**
83 * Returns non-zero if the given source location is in the main file of
84 * the corresponding translation unit.
86 CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);
88 /**
89 * Retrieve a NULL (invalid) source range.
91 CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);
93 /**
94 * Retrieve a source range given the beginning and ending source
95 * locations.
97 CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,
98 CXSourceLocation end);
101 * Determine whether two ranges are equivalent.
103 * \returns non-zero if the ranges are the same, zero if they differ.
105 CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,
106 CXSourceRange range2);
109 * Returns non-zero if \p range is null.
111 CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);
114 * Retrieve the file, line, column, and offset represented by
115 * the given source location.
117 * If the location refers into a macro expansion, retrieves the
118 * location of the macro expansion.
120 * \param location the location within a source file that will be decomposed
121 * into its parts.
123 * \param file [out] if non-NULL, will be set to the file to which the given
124 * source location points.
126 * \param line [out] if non-NULL, will be set to the line to which the given
127 * source location points.
129 * \param column [out] if non-NULL, will be set to the column to which the given
130 * source location points.
132 * \param offset [out] if non-NULL, will be set to the offset into the
133 * buffer to which the given source location points.
135 CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,
136 CXFile *file, unsigned *line,
137 unsigned *column,
138 unsigned *offset);
141 * Retrieve the file, line and column represented by the given source
142 * location, as specified in a # line directive.
144 * Example: given the following source code in a file somefile.c
146 * \code
147 * #123 "dummy.c" 1
149 * static int func(void)
151 * return 0;
153 * \endcode
155 * the location information returned by this function would be
157 * File: dummy.c Line: 124 Column: 12
159 * whereas clang_getExpansionLocation would have returned
161 * File: somefile.c Line: 3 Column: 12
163 * \param location the location within a source file that will be decomposed
164 * into its parts.
166 * \param filename [out] if non-NULL, will be set to the filename of the
167 * source location. Note that filenames returned will be for "virtual" files,
168 * which don't necessarily exist on the machine running clang - e.g. when
169 * parsing preprocessed output obtained from a different environment. If
170 * a non-NULL value is passed in, remember to dispose of the returned value
171 * using \c clang_disposeString() once you've finished with it. For an invalid
172 * source location, an empty string is returned.
174 * \param line [out] if non-NULL, will be set to the line number of the
175 * source location. For an invalid source location, zero is returned.
177 * \param column [out] if non-NULL, will be set to the column number of the
178 * source location. For an invalid source location, zero is returned.
180 CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,
181 CXString *filename,
182 unsigned *line, unsigned *column);
185 * Legacy API to retrieve the file, line, column, and offset represented
186 * by the given source location.
188 * This interface has been replaced by the newer interface
189 * #clang_getExpansionLocation(). See that interface's documentation for
190 * details.
192 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
193 CXFile *file, unsigned *line,
194 unsigned *column,
195 unsigned *offset);
198 * Retrieve the file, line, column, and offset represented by
199 * the given source location.
201 * If the location refers into a macro instantiation, return where the
202 * location was originally spelled in the source file.
204 * \param location the location within a source file that will be decomposed
205 * into its parts.
207 * \param file [out] if non-NULL, will be set to the file to which the given
208 * source location points.
210 * \param line [out] if non-NULL, will be set to the line to which the given
211 * source location points.
213 * \param column [out] if non-NULL, will be set to the column to which the given
214 * source location points.
216 * \param offset [out] if non-NULL, will be set to the offset into the
217 * buffer to which the given source location points.
219 CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,
220 CXFile *file, unsigned *line,
221 unsigned *column,
222 unsigned *offset);
225 * Retrieve the file, line, column, and offset represented by
226 * the given source location.
228 * If the location refers into a macro expansion, return where the macro was
229 * expanded or where the macro argument was written, if the location points at
230 * a macro argument.
232 * \param location the location within a source file that will be decomposed
233 * into its parts.
235 * \param file [out] if non-NULL, will be set to the file to which the given
236 * source location points.
238 * \param line [out] if non-NULL, will be set to the line to which the given
239 * source location points.
241 * \param column [out] if non-NULL, will be set to the column to which the given
242 * source location points.
244 * \param offset [out] if non-NULL, will be set to the offset into the
245 * buffer to which the given source location points.
247 CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,
248 CXFile *file, unsigned *line,
249 unsigned *column, unsigned *offset);
252 * Retrieve a source location representing the first character within a
253 * source range.
255 CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);
258 * Retrieve a source location representing the last character within a
259 * source range.
261 CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);
264 * Identifies an array of ranges.
266 typedef struct {
267 /** The number of ranges in the \c ranges array. */
268 unsigned count;
270 * An array of \c CXSourceRanges.
272 CXSourceRange *ranges;
273 } CXSourceRangeList;
276 * Destroy the given \c CXSourceRangeList.
278 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
281 * @}
284 LLVM_CLANG_C_EXTERN_C_END
286 #endif