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 | 47751d6c21302720b62fcba3aaa8e7e4e6e34ab4 (patch) | |
| tree | ccfc0c4a3e6c5e44f5400dc46809b09ebc01ad6e | |
| parent | cd9441015293eab2f9718d85ca20628569588e72 (diff) | |
| download | bcm5719-llvm-47751d6c21302720b62fcba3aaa8e7e4e6e34ab4.tar.gz bcm5719-llvm-47751d6c21302720b62fcba3aaa8e7e4e6e34ab4.zip | |
Introduce clang_getInstantiationLocationOffset(), which decomposes a
source location in file + offset.
llvm-svn: 94497
| -rw-r--r-- | clang/include/clang-c/Index.h | 18 | ||||
| -rw-r--r-- | clang/tools/CIndex/CIndex.cpp | 56 | ||||
| -rw-r--r-- | clang/tools/CIndex/CIndex.exports | 1 |
3 files changed, 61 insertions, 14 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index b38e5178512..ab7e55bcb61 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -373,6 +373,24 @@ CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, unsigned *column); /** + * \brief Retrieve the file and offset within that file represented by + * the given source location. + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param file [out] if non-NULL, will be set to the file to which the + * given source location points. + * + * \param offset [out] if non-NULL, will be set to the offset into the + * \p file to which the given source location points. + */ +CINDEX_LINKAGE void clang_getInstantiationLocationOffset( + CXSourceLocation location, + CXFile *File, + unsigned *Offset); + +/** * \brief Retrieve a source location representing the first character within a * source range. */ diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index fee5b74b49c..03519adc0a3 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/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; diff --git a/clang/tools/CIndex/CIndex.exports b/clang/tools/CIndex/CIndex.exports index d349086b9c1..b2ec58e5b9c 100644 --- a/clang/tools/CIndex/CIndex.exports +++ b/clang/tools/CIndex/CIndex.exports @@ -27,6 +27,7 @@ _clang_getFile _clang_getFileName _clang_getFileTime _clang_getInstantiationLocation +_clang_getInstantiationLocationOffset _clang_getLocation _clang_getNullCursor _clang_getNullLocation |

