CXFile file,
unsigned line,
unsigned column);
+/**
+ * \brief Retrieves the source location associated with a given character offset
+ * in a particular translation unit.
+ */
+CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu,
+ CXFile file,
+ unsigned offset);
/**
* \brief Retrieve a NULL (invalid) source range.
= 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);
}