[DFAJumpThreading] Remove incoming StartBlock from all phis when unfolding select...
[llvm-project.git] / clang / tools / libclang / CXSourceLocation.h
blobc86f6850375bb66dd3ad18fb50c4112893328e58
1 //===- CXSourceLocation.h - CXSourceLocations Utilities ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 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 file defines routines for manipulating CXSourceLocations.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H
14 #define LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H
16 #include "clang-c/Index.h"
17 #include "clang/AST/ASTContext.h"
18 #include "clang/Basic/LangOptions.h"
19 #include "clang/Basic/SourceLocation.h"
21 namespace clang {
23 class SourceManager;
25 namespace cxloc {
27 /// Translate a Clang source location into a CIndex source location.
28 static inline CXSourceLocation
29 translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
30 SourceLocation Loc) {
31 if (Loc.isInvalid())
32 return clang_getNullLocation();
34 CXSourceLocation Result = { { &SM, &LangOpts, },
35 Loc.getRawEncoding() };
36 return Result;
39 /// Translate a Clang source location into a CIndex source location.
40 static inline CXSourceLocation translateSourceLocation(ASTContext &Context,
41 SourceLocation Loc) {
42 return translateSourceLocation(Context.getSourceManager(),
43 Context.getLangOpts(),
44 Loc);
47 /// Translate a Clang source range into a CIndex source range.
48 ///
49 /// Clang internally represents ranges where the end location points to the
50 /// start of the token at the end. However, for external clients it is more
51 /// useful to have a CXSourceRange be a proper half-open interval. This routine
52 /// does the appropriate translation.
53 CXSourceRange translateSourceRange(const SourceManager &SM,
54 const LangOptions &LangOpts,
55 const CharSourceRange &R);
57 /// Translate a Clang source range into a CIndex source range.
58 static inline CXSourceRange translateSourceRange(ASTContext &Context,
59 SourceRange R) {
60 return translateSourceRange(Context.getSourceManager(),
61 Context.getLangOpts(),
62 CharSourceRange::getTokenRange(R));
65 static inline SourceLocation translateSourceLocation(CXSourceLocation L) {
66 return SourceLocation::getFromRawEncoding(L.int_data);
69 static inline SourceRange translateCXSourceRange(CXSourceRange R) {
70 return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data),
71 SourceLocation::getFromRawEncoding(R.end_int_data));
74 /// Translates CXSourceRange to CharSourceRange.
75 /// The semantics of \p R are:
76 /// R.begin_int_data is first character of the range.
77 /// R.end_int_data is one character past the end of the range.
78 CharSourceRange translateCXRangeToCharRange(CXSourceRange R);
79 }} // end namespace: clang::cxloc
81 #endif