| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H |
| 14 | #define LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H |
| 15 | |
| 16 | #include "clang-c/Index.h" |
| 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/Basic/LangOptions.h" |
| 19 | #include "clang/Basic/SourceLocation.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | |
| 23 | class SourceManager; |
| 24 | |
| 25 | namespace cxloc { |
| 26 | |
| 27 | |
| 28 | static inline CXSourceLocation |
| 29 | translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts, |
| 30 | SourceLocation Loc) { |
| 31 | if (Loc.isInvalid()) |
| 32 | clang_getNullLocation(); |
| 33 | |
| 34 | CXSourceLocation Result = { { &SM, &LangOpts, }, |
| 35 | Loc.getRawEncoding() }; |
| 36 | return Result; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | static inline CXSourceLocation translateSourceLocation(ASTContext &Context, |
| 41 | SourceLocation Loc) { |
| 42 | return translateSourceLocation(Context.getSourceManager(), |
| 43 | Context.getLangOpts(), |
| 44 | Loc); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | CXSourceRange translateSourceRange(const SourceManager &SM, |
| 54 | const LangOptions &LangOpts, |
| 55 | const CharSourceRange &R); |
| 56 | |
| 57 | |
| 58 | static inline CXSourceRange translateSourceRange(ASTContext &Context, |
| 59 | SourceRange R) { |
| 60 | return translateSourceRange(Context.getSourceManager(), |
| 61 | Context.getLangOpts(), |
| 62 | CharSourceRange::getTokenRange(R)); |
| 63 | } |
| 64 | |
| 65 | static inline SourceLocation translateSourceLocation(CXSourceLocation L) { |
| 66 | return SourceLocation::getFromRawEncoding(L.int_data); |
| 67 | } |
| 68 | |
| 69 | static inline SourceRange translateCXSourceRange(CXSourceRange R) { |
| 70 | return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data), |
| 71 | SourceLocation::getFromRawEncoding(R.end_int_data)); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | }} |
| 76 | |
| 77 | #endif |
| 78 | |