diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-27 13:57:42 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-27 10:57:42 -0700 |
| commit | ca1f93a916ce6b984cba402c8d3710988f2b618f (patch) | |
| tree | f39b638210d38efdc7e2bb746c06b881323d0f53 /source/compiler-core/slang-source-loc.cpp | |
| parent | 2179480e28bdd46c71cec269a8f55ba93aa54f53 (diff) | |
Using SourceMap for location output (#2736)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP using SourceMap with SourceManager.
* Add a test to check obfuscation map is working.
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/compiler-core/slang-source-loc.cpp')
| -rw-r--r-- | source/compiler-core/slang-source-loc.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp index 1314d8066..951f7feec 100644 --- a/source/compiler-core/slang-source-loc.cpp +++ b/source/compiler-core/slang-source-loc.cpp @@ -191,6 +191,29 @@ void SourceView::addDefaultLineDirective(SourceLoc directiveLoc) HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type) { + auto obfuscatedSourceMap = getSourceFile()->getObfuscatedSourceMap(); + if (obfuscatedSourceMap) + { + const Index col = getRange().getOffset(loc); + + const Index entryIndex = obfuscatedSourceMap->findEntry(0, col); + if (entryIndex >= 0) + { + const auto& entry = obfuscatedSourceMap->getEntryByIndex(entryIndex); + + // Generate the HandleSourceLoc + + HandleSourceLoc handleLoc; + handleLoc.line = entry.sourceLine + 1; + handleLoc.column = entry.sourceColumn + 1; + + auto& managerPool = getSourceManager()->getStringSlicePool(); + + handleLoc.pathHandle = managerPool.add(obfuscatedSourceMap->getSourceFileName(entry.sourceFileIndex)); + return handleLoc; + } + } + const int offset = m_range.getOffset(loc); // We need the line index from the original source file |
