diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-26 03:07:15 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-26 03:07:15 +0000 |
commit | e69517ce61638f12c9abe4605753a45275ac4e37 (patch) | |
tree | ba843b8422eadd0e64d5c6950b68f62a345d329d /tools/CIndex/CIndex.cpp | |
parent | 816bc31ed45002de2547d6679b44f31eb85ec491 (diff) |
Introduce clang_getInstantiationLocationOffset(), which decomposes a
source location in file + offset.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/CIndex/CIndex.cpp')
-rw-r--r-- | tools/CIndex/CIndex.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index fee5b74b49..03519adc0a 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1108,24 +1108,11 @@ CXSourceRange clang_getRange(CXSourceLocation begin, CXSourceLocation end) { return Result; } -void clang_getInstantiationLocation(CXSourceLocation location, - CXFile *file, - unsigned *line, - unsigned *column) { +static SourceLocation getAdjustedSourceLocation(CXSourceLocation location) { 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; - } - // 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. @@ -1157,6 +1144,30 @@ void clang_getInstantiationLocation(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) @@ -1165,6 +1176,23 @@ void clang_getInstantiationLocation(CXSourceLocation location, *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; +} + CXSourceLocation clang_getRangeStart(CXSourceRange range) { CXSourceLocation Result = { range.ptr_data, range.begin_int_data }; return Result; |