summaryrefslogtreecommitdiffstats
path: root/clang/tools/CIndex/CIndex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/tools/CIndex/CIndex.cpp')
-rw-r--r--clang/tools/CIndex/CIndex.cpp59
1 files changed, 18 insertions, 41 deletions
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index 3a5977970a4..10099ef0aa9 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -1123,11 +1123,27 @@ CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) {
return Result;
}
-static SourceLocation getAdjustedSourceLocation(CXSourceLocation location) {
+void clang_getInstantiationLocation(CXSourceLocation location,
+ CXFile *file,
+ unsigned *line,
+ unsigned *column,
+ unsigned *offset) {
cxloc::CXSourceLocationPtr Ptr
= cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
+ if (!Ptr.getPointer() || Loc.isInvalid()) {
+ if (file)
+ *file = 0;
+ if (line)
+ *line = 0;
+ if (column)
+ *column = 0;
+ if (offset)
+ *offset = 0;
+ return;
+ }
+
// FIXME: This is largely copy-paste from
///TextDiagnosticPrinter::HighlightRange. When it is clear that this is
// what we want the two routines should be refactored.
@@ -1159,53 +1175,14 @@ static SourceLocation getAdjustedSourceLocation(CXSourceLocation location) {
InstLoc = InstLoc.getFileLocWithOffset(Length - 1);
}
- return InstLoc;
-}
-
-void clang_getInstantiationLocation(CXSourceLocation location,
- CXFile *file,
- unsigned *line,
- unsigned *column) {
- cxloc::CXSourceLocationPtr Ptr
- = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
- SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
-
- if (!Ptr.getPointer() || Loc.isInvalid()) {
- if (file)
- *file = 0;
- if (line)
- *line = 0;
- if (column)
- *column = 0;
- return;
- }
-
- SourceLocation InstLoc = getAdjustedSourceLocation(location);
- ASTContext &Context = *Ptr.getPointer();
- SourceManager &SM = Context.getSourceManager();
if (file)
*file = (void *)SM.getFileEntryForID(SM.getFileID(InstLoc));
if (line)
*line = SM.getInstantiationLineNumber(InstLoc);
if (column)
*column = SM.getInstantiationColumnNumber(InstLoc);
-}
-
-void clang_getInstantiationLocationOffset(CXSourceLocation location,
- CXFile *file,
- unsigned *offset) {
- cxloc::CXSourceLocationPtr Ptr
- = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
- SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
-
- ASTContext &Context = *Ptr.getPointer();
- SourceManager &SM = Context.getSourceManager();
- SourceLocation InstLoc = getAdjustedSourceLocation(location);
- std::pair<FileID, unsigned> Decomposed = SM.getDecomposedLoc(InstLoc);
- if (file)
- *file = (void *)SM.getFileEntryForID(Decomposed.first);
if (offset)
- *offset = Decomposed.second;
+ *offset = SM.getDecomposedLoc(InstLoc).second;
}
CXSourceLocation clang_getRangeStart(CXSourceRange range) {
OpenPOWER on IntegriCloud