diff options
author | David Chisnall <csdavec@swan.ac.uk> | 2010-10-15 17:07:39 +0000 |
---|---|---|
committer | David Chisnall <csdavec@swan.ac.uk> | 2010-10-15 17:07:39 +0000 |
commit | 83889a7f1f338e343ef72aeeef9c27f7b62c0f0f (patch) | |
tree | aa09afe34003ec073f32270324889535fbd28e77 /tools/libclang/CIndex.cpp | |
parent | 6eaac8b3e68177f56090ddb0fcfc8fbfd49150a6 (diff) |
Add clang_getLocationForOffset() to libclang, for gives a source location from a character index into a file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116587 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CIndex.cpp')
-rw-r--r-- | tools/libclang/CIndex.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 1d7efe4208..722e2cb738 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2266,6 +2266,27 @@ CXSourceLocation clang_getLocation(CXTranslationUnit tu, = CXXUnit->getSourceManager().getLocation( static_cast<const FileEntry *>(file), line, column); + if (SLoc.isInvalid()) return clang_getNullLocation(); + + return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc); +} + +CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, + CXFile file, + unsigned offset) { + if (!tu || !file) + return clang_getNullLocation(); + + ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu); + SourceLocation Start + = CXXUnit->getSourceManager().getLocation( + static_cast<const FileEntry *>(file), + 1, 1); + if (Start.isInvalid()) return clang_getNullLocation(); + + SourceLocation SLoc = Start.getFileLocWithOffset(offset); + + if (SLoc.isInvalid()) return clang_getNullLocation(); return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc); } |