Ted Kremenek | a297de2 | 2010-01-25 22:34:44 +0000 | [diff] [blame^] | 1 | //===- CXSourceLocation.h - Routines for manipulating CXSourceLocations ---===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines routines for manipulating CXSourceLocations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_CXSOURCELOCATION_H |
| 15 | #define LLVM_CLANG_CXSOURCELOCATION_H |
| 16 | |
| 17 | #include "clang-c/Index.h" |
| 18 | #include "clang/Basic/SourceLocation.h" |
| 19 | |
| 20 | namespace clang { |
| 21 | |
| 22 | class ASTContext; |
| 23 | |
| 24 | namespace cxloc { |
| 25 | |
| 26 | typedef llvm::PointerIntPair<ASTContext *, 1, bool> CXSourceLocationPtr; |
| 27 | |
| 28 | /// \brief Translate a Clang source location into a CIndex source location. |
| 29 | static inline CXSourceLocation translateSourceLocation(ASTContext &Context, |
| 30 | SourceLocation Loc, |
| 31 | bool AtEnd = false) { |
| 32 | CXSourceLocationPtr Ptr(&Context, AtEnd); |
| 33 | CXSourceLocation Result = { Ptr.getOpaqueValue(), Loc.getRawEncoding() }; |
| 34 | return Result; |
| 35 | } |
| 36 | |
| 37 | /// \brief Translate a Clang source range into a CIndex source range. |
| 38 | static inline CXSourceRange translateSourceRange(ASTContext &Context, |
| 39 | SourceRange R) { |
| 40 | CXSourceRange Result = { &Context, |
| 41 | R.getBegin().getRawEncoding(), |
| 42 | R.getEnd().getRawEncoding() }; |
| 43 | return Result; |
| 44 | } |
| 45 | |
| 46 | static inline SourceLocation translateSourceLocation(CXSourceLocation L) { |
| 47 | return SourceLocation::getFromRawEncoding(L.int_data); |
| 48 | } |
| 49 | |
| 50 | static inline SourceRange translateSourceRange(CXSourceRange R) { |
| 51 | return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data), |
| 52 | SourceLocation::getFromRawEncoding(R.end_int_data)); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | }} // end namespace: clang::cxloc |
| 57 | |
| 58 | #endif |