summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/diagnostics.cpp2
-rw-r--r--source/slang/source-loc.cpp14
-rw-r--r--source/slang/source-loc.h6
3 files changed, 15 insertions, 7 deletions
diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp
index 18e5f9a4d..4f4a33e60 100644
--- a/source/slang/diagnostics.cpp
+++ b/source/slang/diagnostics.cpp
@@ -155,7 +155,7 @@ static void formatDiagnostic(
auto sourceManager = sink->sourceManager;
auto expandedLoc = sourceManager->expandSourceLoc(diagnostic.loc);
- auto humaneLoc = expandedLoc.sourceManager->getHumaneLoc(expandedLoc);
+ auto humaneLoc = getHumaneLoc(expandedLoc);
sb << humaneLoc.getPath();
sb << "(";
diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp
index cea8441e6..80556ac37 100644
--- a/source/slang/source-loc.cpp
+++ b/source/slang/source-loc.cpp
@@ -197,14 +197,16 @@ ExpandedSourceLoc SourceManager::expandSourceLoc(SourceLoc const& loc)
return Slang::expandSourceLoc(this, loc);
}
-HumaneSourceLoc SourceManager::getHumaneLoc(ExpandedSourceLoc const& loc)
+HumaneSourceLoc getHumaneLoc(ExpandedSourceLoc const& loc)
{
// First check if this location maps to an actual file.
SourceFile* sourceFile = loc.getSourceFile();
if(!sourceFile)
return HumaneSourceLoc();
- auto& entry = sourceFiles[loc.entryIndex];
+ auto sourceManager = loc.sourceManager;
+
+ auto& entry = sourceManager->sourceFiles[loc.entryIndex];
UInt offset = loc.getRaw() - entry.startLoc.getRaw();
// We now have a raw input file that we can search for line breaks.
@@ -297,10 +299,14 @@ HumaneSourceLoc SourceManager::getHumaneLoc(ExpandedSourceLoc const& loc)
return humaneLoc;
}
-HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc const& loc)
+HumaneSourceLoc ExpandedSourceLoc::getHumaneLoc()
{
- return getHumaneLoc(expandSourceLoc(loc));
+ return Slang::getHumaneLoc(*this);
+}
+HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc const& loc)
+{
+ return expandSourceLoc(loc).getHumaneLoc();
}
SourceLoc SourceManager::getSpellingLoc(ExpandedSourceLoc const& loc)
diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h
index 8bb89c645..83ad87633 100644
--- a/source/slang/source-loc.h
+++ b/source/slang/source-loc.h
@@ -117,9 +117,12 @@ struct ExpandedSourceLoc : public SourceLoc
// Get the original source file that holds this location
SourceFile* getSourceFile() const;
-};
+ // Get a "humane" version of a source location
+ HumaneSourceLoc getHumaneLoc();
+};
+HumaneSourceLoc getHumaneLoc(ExpandedSourceLoc const& loc);
struct SourceManager
{
@@ -142,7 +145,6 @@ struct SourceManager
ExpandedSourceLoc expandSourceLoc(SourceLoc const& loc);
// Get a "humane" version of a source location
- HumaneSourceLoc getHumaneLoc(ExpandedSourceLoc const& loc);
HumaneSourceLoc getHumaneLoc(SourceLoc const& loc);