Path: blob/main/contrib/llvm-project/clang/include/clang-c/CXSourceLocation.h
35233 views
/*===-- clang-c/CXSourceLocation.h - C Index Source Location ------*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header provides the interface to C Index source locations. *|10|* *|11\*===----------------------------------------------------------------------===*/1213#ifndef LLVM_CLANG_C_CXSOURCE_LOCATION_H14#define LLVM_CLANG_C_CXSOURCE_LOCATION_H1516#include "clang-c/CXFile.h"17#include "clang-c/CXString.h"18#include "clang-c/ExternC.h"19#include "clang-c/Platform.h"2021LLVM_CLANG_C_EXTERN_C_BEGIN2223/**24* \defgroup CINDEX_LOCATIONS Physical source locations25*26* Clang represents physical source locations in its abstract syntax tree in27* great detail, with file, line, and column information for the majority of28* the tokens parsed in the source code. These data types and functions are29* used to represent source location information, either for a particular30* point in the program or for a range of points in the program, and extract31* specific location information from those data types.32*33* @{34*/3536/**37* Identifies a specific source location within a translation38* unit.39*40* Use clang_getExpansionLocation() or clang_getSpellingLocation()41* to map a source location to a particular file, line, and column.42*/43typedef struct {44const void *ptr_data[2];45unsigned int_data;46} CXSourceLocation;4748/**49* Identifies a half-open character range in the source code.50*51* Use clang_getRangeStart() and clang_getRangeEnd() to retrieve the52* starting and end locations from a source range, respectively.53*/54typedef struct {55const void *ptr_data[2];56unsigned begin_int_data;57unsigned end_int_data;58} CXSourceRange;5960/**61* Retrieve a NULL (invalid) source location.62*/63CINDEX_LINKAGE CXSourceLocation clang_getNullLocation(void);6465/**66* Determine whether two source locations, which must refer into67* the same translation unit, refer to exactly the same point in the source68* code.69*70* \returns non-zero if the source locations refer to the same location, zero71* if they refer to different locations.72*/73CINDEX_LINKAGE unsigned clang_equalLocations(CXSourceLocation loc1,74CXSourceLocation loc2);7576/**77* Returns non-zero if the given source location is in a system header.78*/79CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location);8081/**82* Returns non-zero if the given source location is in the main file of83* the corresponding translation unit.84*/85CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location);8687/**88* Retrieve a NULL (invalid) source range.89*/90CINDEX_LINKAGE CXSourceRange clang_getNullRange(void);9192/**93* Retrieve a source range given the beginning and ending source94* locations.95*/96CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin,97CXSourceLocation end);9899/**100* Determine whether two ranges are equivalent.101*102* \returns non-zero if the ranges are the same, zero if they differ.103*/104CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1,105CXSourceRange range2);106107/**108* Returns non-zero if \p range is null.109*/110CINDEX_LINKAGE int clang_Range_isNull(CXSourceRange range);111112/**113* Retrieve the file, line, column, and offset represented by114* the given source location.115*116* If the location refers into a macro expansion, retrieves the117* location of the macro expansion.118*119* \param location the location within a source file that will be decomposed120* into its parts.121*122* \param file [out] if non-NULL, will be set to the file to which the given123* source location points.124*125* \param line [out] if non-NULL, will be set to the line to which the given126* source location points.127*128* \param column [out] if non-NULL, will be set to the column to which the given129* source location points.130*131* \param offset [out] if non-NULL, will be set to the offset into the132* buffer to which the given source location points.133*/134CINDEX_LINKAGE void clang_getExpansionLocation(CXSourceLocation location,135CXFile *file, unsigned *line,136unsigned *column,137unsigned *offset);138139/**140* Retrieve the file, line and column represented by the given source141* location, as specified in a # line directive.142*143* Example: given the following source code in a file somefile.c144*145* \code146* #123 "dummy.c" 1147*148* static int func(void)149* {150* return 0;151* }152* \endcode153*154* the location information returned by this function would be155*156* File: dummy.c Line: 124 Column: 12157*158* whereas clang_getExpansionLocation would have returned159*160* File: somefile.c Line: 3 Column: 12161*162* \param location the location within a source file that will be decomposed163* into its parts.164*165* \param filename [out] if non-NULL, will be set to the filename of the166* source location. Note that filenames returned will be for "virtual" files,167* which don't necessarily exist on the machine running clang - e.g. when168* parsing preprocessed output obtained from a different environment. If169* a non-NULL value is passed in, remember to dispose of the returned value170* using \c clang_disposeString() once you've finished with it. For an invalid171* source location, an empty string is returned.172*173* \param line [out] if non-NULL, will be set to the line number of the174* source location. For an invalid source location, zero is returned.175*176* \param column [out] if non-NULL, will be set to the column number of the177* source location. For an invalid source location, zero is returned.178*/179CINDEX_LINKAGE void clang_getPresumedLocation(CXSourceLocation location,180CXString *filename,181unsigned *line, unsigned *column);182183/**184* Legacy API to retrieve the file, line, column, and offset represented185* by the given source location.186*187* This interface has been replaced by the newer interface188* #clang_getExpansionLocation(). See that interface's documentation for189* details.190*/191CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,192CXFile *file, unsigned *line,193unsigned *column,194unsigned *offset);195196/**197* Retrieve the file, line, column, and offset represented by198* the given source location.199*200* If the location refers into a macro instantiation, return where the201* location was originally spelled in the source file.202*203* \param location the location within a source file that will be decomposed204* into its parts.205*206* \param file [out] if non-NULL, will be set to the file to which the given207* source location points.208*209* \param line [out] if non-NULL, will be set to the line to which the given210* source location points.211*212* \param column [out] if non-NULL, will be set to the column to which the given213* source location points.214*215* \param offset [out] if non-NULL, will be set to the offset into the216* buffer to which the given source location points.217*/218CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location,219CXFile *file, unsigned *line,220unsigned *column,221unsigned *offset);222223/**224* Retrieve the file, line, column, and offset represented by225* the given source location.226*227* If the location refers into a macro expansion, return where the macro was228* expanded or where the macro argument was written, if the location points at229* a macro argument.230*231* \param location the location within a source file that will be decomposed232* into its parts.233*234* \param file [out] if non-NULL, will be set to the file to which the given235* source location points.236*237* \param line [out] if non-NULL, will be set to the line to which the given238* source location points.239*240* \param column [out] if non-NULL, will be set to the column to which the given241* source location points.242*243* \param offset [out] if non-NULL, will be set to the offset into the244* buffer to which the given source location points.245*/246CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location,247CXFile *file, unsigned *line,248unsigned *column, unsigned *offset);249250/**251* Retrieve a source location representing the first character within a252* source range.253*/254CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range);255256/**257* Retrieve a source location representing the last character within a258* source range.259*/260CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range);261262/**263* Identifies an array of ranges.264*/265typedef struct {266/** The number of ranges in the \c ranges array. */267unsigned count;268/**269* An array of \c CXSourceRanges.270*/271CXSourceRange *ranges;272} CXSourceRangeList;273274/**275* Destroy the given \c CXSourceRangeList.276*/277CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);278279/**280* @}281*/282283LLVM_CLANG_C_EXTERN_C_END284285#endif286287288