Hi folks,
I'm new to this, but I've made a patch to libclang that allows it to
properly get the range for a translation unit cursor (which I needed for a
project I'm working on). It's pretty straightforward.
Thanks,
Clint
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp (revision 152526)
+++ tools/libclang/CIndex.cpp (working copy)
@@ -3869,6 +3869,15 @@
return TU->mapRangeFromPreamble(Range);
}
+ if (C.kind == CXCursor_TranslationUnit) {
+ ASTUnit *TU = getCursorASTUnit(C);
+ FileID MainID = TU->getSourceManager().getMainFileID();
+ SourceLocation Start =
TU->getSourceManager().getLocForStartOfFile(MainID);
+ SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID);
+ SourceRange Range(Start, End);
+ return TU->mapRangeFromPreamble(Range);
+ }
+
if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) {
Decl *D = cxcursor::getCursorDecl(C);
if (!D)
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp (revision 152526)
+++ tools/libclang/CIndex.cpp (working copy)
@@ -3869,6 +3869,15 @@
return TU->mapRangeFromPreamble(Range);
}
+ if (C.kind == CXCursor_TranslationUnit) {
+ ASTUnit *TU = getCursorASTUnit(C);
+ FileID MainID = TU->getSourceManager().getMainFileID();
+ SourceLocation Start = TU->getSourceManager().getLocForStartOfFile(MainID);
+ SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID);
+ SourceRange Range(Start, End);
+ return TU->mapRangeFromPreamble(Range);
+ }
+
if (C.kind >= CXCursor_FirstDecl && C.kind <= CXCursor_LastDecl) {
Decl *D = cxcursor::getCursorDecl(C);
if (!D)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits