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);