2010-02-14 09:47:29 +08:00
|
|
|
//===- CXSourceLocation.h - CXSourceLocations Utilities ---------*- C++ -*-===//
|
2010-01-26 06:34:44 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines routines for manipulating CXSourceLocations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H
|
|
|
|
#define LLVM_CLANG_TOOLS_LIBCLANG_CXSOURCELOCATION_H
|
2010-01-26 06:34:44 +08:00
|
|
|
|
|
|
|
#include "clang-c/Index.h"
|
2010-01-28 08:27:43 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2012-12-04 17:25:21 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2010-01-26 06:34:44 +08:00
|
|
|
|
|
|
|
namespace clang {
|
2010-04-13 03:45:50 +08:00
|
|
|
|
|
|
|
class SourceManager;
|
2010-01-26 06:34:44 +08:00
|
|
|
|
|
|
|
namespace cxloc {
|
|
|
|
|
2010-01-28 08:27:43 +08:00
|
|
|
/// \brief Translate a Clang source location into a CIndex source location.
|
|
|
|
static inline CXSourceLocation
|
|
|
|
translateSourceLocation(const SourceManager &SM, const LangOptions &LangOpts,
|
2010-02-14 09:47:36 +08:00
|
|
|
SourceLocation Loc) {
|
2010-06-29 07:54:17 +08:00
|
|
|
if (Loc.isInvalid())
|
|
|
|
clang_getNullLocation();
|
|
|
|
|
2013-01-12 06:29:47 +08:00
|
|
|
CXSourceLocation Result = { { &SM, &LangOpts, },
|
2010-01-28 08:27:43 +08:00
|
|
|
Loc.getRawEncoding() };
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-01-26 06:34:44 +08:00
|
|
|
/// \brief Translate a Clang source location into a CIndex source location.
|
|
|
|
static inline CXSourceLocation translateSourceLocation(ASTContext &Context,
|
2010-02-14 09:47:36 +08:00
|
|
|
SourceLocation Loc) {
|
|
|
|
return translateSourceLocation(Context.getSourceManager(),
|
2012-03-11 15:00:24 +08:00
|
|
|
Context.getLangOpts(),
|
2010-02-14 09:47:36 +08:00
|
|
|
Loc);
|
2010-01-26 06:34:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Translate a Clang source range into a CIndex source range.
|
2010-02-14 09:47:29 +08:00
|
|
|
///
|
|
|
|
/// Clang internally represents ranges where the end location points to the
|
|
|
|
/// start of the token at the end. However, for external clients it is more
|
|
|
|
/// useful to have a CXSourceRange be a proper half-open interval. This routine
|
|
|
|
/// does the appropriate translation.
|
|
|
|
CXSourceRange translateSourceRange(const SourceManager &SM,
|
|
|
|
const LangOptions &LangOpts,
|
2010-06-19 06:45:06 +08:00
|
|
|
const CharSourceRange &R);
|
2010-01-28 08:27:43 +08:00
|
|
|
|
|
|
|
/// \brief Translate a Clang source range into a CIndex source range.
|
|
|
|
static inline CXSourceRange translateSourceRange(ASTContext &Context,
|
|
|
|
SourceRange R) {
|
|
|
|
return translateSourceRange(Context.getSourceManager(),
|
2012-03-11 15:00:24 +08:00
|
|
|
Context.getLangOpts(),
|
2010-06-19 06:45:06 +08:00
|
|
|
CharSourceRange::getTokenRange(R));
|
2010-01-28 08:27:43 +08:00
|
|
|
}
|
2010-01-26 06:34:44 +08:00
|
|
|
|
|
|
|
static inline SourceLocation translateSourceLocation(CXSourceLocation L) {
|
|
|
|
return SourceLocation::getFromRawEncoding(L.int_data);
|
|
|
|
}
|
|
|
|
|
2010-02-14 16:31:57 +08:00
|
|
|
static inline SourceRange translateCXSourceRange(CXSourceRange R) {
|
2010-01-26 06:34:44 +08:00
|
|
|
return SourceRange(SourceLocation::getFromRawEncoding(R.begin_int_data),
|
|
|
|
SourceLocation::getFromRawEncoding(R.end_int_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}} // end namespace: clang::cxloc
|
|
|
|
|
|
|
|
#endif
|