[libclang] Add translateCXRangeToCharRange conversion
authorJan Korous <jkorous@apple.com>
Wed, 2 Sep 2020 20:11:35 +0000 (13:11 -0700)
committerJan Korous <jkorous@apple.com>
Fri, 4 Sep 2020 16:41:22 +0000 (09:41 -0700)
Add new conversion with clearly specified semantics.

https://reviews.llvm.org/D86990

clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXSourceLocation.h

index 93f9797..683b517 100644 (file)
@@ -164,6 +164,12 @@ CXSourceRange cxloc::translateSourceRange(const SourceManager &SM,
   return Result;
 }
 
+CharSourceRange cxloc::translateCXRangeToCharRange(CXSourceRange R) {
+  return CharSourceRange::getCharRange(
+      SourceLocation::getFromRawEncoding(R.begin_int_data),
+      SourceLocation::getFromRawEncoding(R.end_int_data));
+}
+
 //===----------------------------------------------------------------------===//
 // Cursor visitor.
 //===----------------------------------------------------------------------===//
index 6702d0c..ce3d09e 100644 (file)
@@ -71,7 +71,11 @@ static inline SourceRange translateCXSourceRange(CXSourceRange R) {
                      SourceLocation::getFromRawEncoding(R.end_int_data));
 }
 
-
+/// Translates CXSourceRange to CharSourceRange.
+/// The semantics of \p R are:
+/// R.begin_int_data is first character of the range.
+/// R.end_int_data is one character past the end of the range.
+CharSourceRange translateCXRangeToCharRange(CXSourceRange R);
 }} // end namespace: clang::cxloc
 
 #endif