[cfe-commits] r94497 - in /cfe/trunk: include/clang-c/Index.h tools/CIndex/CIndex.cpp tools/CIndex/CIndex.exports
Douglas Gregor
dgregor at apple.com
Mon Jan 25 19:07:16 PST 2010
Author: dgregor
Date: Mon Jan 25 21:07:15 2010
New Revision: 94497
URL: http://llvm.org/viewvc/llvm-project?rev=94497&view=rev
Log:
Introduce clang_getInstantiationLocationOffset(), which decomposes a
source location in file + offset.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/CIndex/CIndex.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=94497&r1=94496&r2=94497&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Jan 25 21:07:15 2010
@@ -373,6 +373,24 @@
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.
*/
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=94497&r1=94496&r2=94497&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Mon Jan 25 21:07:15 2010
@@ -1108,24 +1108,11 @@
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 @@
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 @@
*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;
Modified: cfe/trunk/tools/CIndex/CIndex.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.exports?rev=94497&r1=94496&r2=94497&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.exports (original)
+++ cfe/trunk/tools/CIndex/CIndex.exports Mon Jan 25 21:07:15 2010
@@ -27,6 +27,7 @@
_clang_getFileName
_clang_getFileTime
_clang_getInstantiationLocation
+_clang_getInstantiationLocationOffset
_clang_getLocation
_clang_getNullCursor
_clang_getNullLocation
More information about the cfe-commits
mailing list