From b2cf6aea6c31af921b591e5c81613212c2fb2f5b Mon Sep 17 00:00:00 2001 From: Julien FAUCHER Date: Sun, 15 Sep 2024 21:22:22 +0200 Subject: [PATCH] Implements getFullyOriginalRange (#1107) --- include/slang/text/SourceManager.h | 5 +++++ source/text/SourceManager.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/include/slang/text/SourceManager.h b/include/slang/text/SourceManager.h index 8b9813223..e392db812 100644 --- a/include/slang/text/SourceManager.h +++ b/include/slang/text/SourceManager.h @@ -120,6 +120,11 @@ class SLANG_EXPORT SourceManager { /// inside a macro. Otherwise just returns the location itself. SourceLocation getFullyOriginalLoc(SourceLocation location) const; + /// Build the original location range where source is written. + /// If there is a mismatch between resulting start and end files, + /// returns the original range instead. + SourceRange getFullyOriginalRange(SourceRange range) const; + /// If the given location is a macro location, fully expands it out to its actual /// file expansion location. Otherwise just returns the location itself. SourceLocation getFullyExpandedLoc(SourceLocation location) const; diff --git a/source/text/SourceManager.cpp b/source/text/SourceManager.cpp index a129a61f2..730dce558 100644 --- a/source/text/SourceManager.cpp +++ b/source/text/SourceManager.cpp @@ -199,6 +199,12 @@ SourceLocation SourceManager::getFullyOriginalLoc(SourceLocation location) const return location; } +SourceRange SourceManager::getFullyOriginalRange(SourceRange range) const { + SourceLocation start(getFullyOriginalLoc(range.start())); + SourceLocation end(getFullyOriginalLoc(range.end())); + return SourceRange(start, end); +} + SourceLocation SourceManager::getFullyExpandedLoc(SourceLocation location) const { std::shared_lock lock(mutex); return getFullyExpandedLocImpl(location, lock);