blob: 0eab273c35a023d21c8eb551874b4203a6c5675e [file] [log] [blame]
Ted Kremeneka297de22010-01-25 22:34:44 +00001//===- 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
20namespace clang {
21
22class ASTContext;
23
24namespace cxloc {
25
26typedef llvm::PointerIntPair<ASTContext *, 1, bool> CXSourceLocationPtr;
27
28/// \brief Translate a Clang source location into a CIndex source location.
29static 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.
38static 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
46static inline SourceLocation translateSourceLocation(CXSourceLocation L) {
47 return SourceLocation::getFromRawEncoding(L.int_data);
48}
49
50static 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