Add C API hook 'clang_getDeclExtent()', which returns the source extent of a declaration. This implements <rdar://problem/7280072>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 7b624e6..fb359c9 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -569,6 +569,25 @@
SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
return SourceMgr.getSpellingColumnNumber(ND->getLocation());
}
+
+CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) {
+ assert(AnonDecl && "Passed null CXDecl");
+ NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
+ SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
+ SourceRange R = ND->getSourceRange();
+
+ CXDeclExtent extent;
+
+ SourceLocation L = SourceMgr.getSpellingLoc(R.getBegin());
+ extent.begin.line = SourceMgr.getSpellingLineNumber(L);
+ extent.begin.column = SourceMgr.getSpellingColumnNumber(L);
+
+ L = SourceMgr.getSpellingLoc(R.getEnd());
+ extent.end.line = SourceMgr.getSpellingLineNumber(L);
+ extent.end.column = SourceMgr.getSpellingColumnNumber(L);
+
+ return extent;
+}
const char *clang_getDeclSource(CXDecl AnonDecl) {
assert(AnonDecl && "Passed null CXDecl");