From d4f99c8bac8b28f18c864a717d8833db6a1c872d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 22 Mar 2023 12:04:33 -0400 Subject: Source map obfuscation (#2717) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP source map. * Split out handling of RttiTypeFuncs to a map type. * Make RttiTypeFuncsMap hold default impls. * Slightly more sophisticated RttiTypeFuncsMap * Source map decoding. * Fix tabs. * Fix asserts due to negative values. * Use less obscure mechanisms in SourceMap. * Source map decoding. Simplifying SourceMap usage. * First attempt at ouputting a source map as part of emit. * Added support for -source-map option. SourceMap is added to the artifact. * Small improvements around column calculation in SourceWriter. * Source Loc obuscation WIP. * Fix some issues around SourceMap obfuscation. * Split out obfuscation into its own file. * Keep obfuscated SourceMap even through serialization bottleneck. --- source/compiler-core/slang-source-loc.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'source/compiler-core/slang-source-loc.cpp') diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp index 95c6f5db3..1314d8066 100644 --- a/source/compiler-core/slang-source-loc.cpp +++ b/source/compiler-core/slang-source-loc.cpp @@ -189,7 +189,7 @@ void SourceView::addDefaultLineDirective(SourceLoc directiveLoc) m_entries.add(entry); } -HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type) +HandleSourceLoc SourceView::getHandleLoc(SourceLoc loc, SourceLocType type) { const int offset = m_range.getOffset(loc); @@ -206,9 +206,9 @@ HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type) // that an IDE expects us to use when reporting locations?) const int columnIndex = m_sourceFile->calcColumnIndex(lineIndex, offset); - HumaneSourceLoc humaneLoc; - humaneLoc.column = columnIndex + 1; - humaneLoc.line = lineIndex + 1; + HandleSourceLoc handleLoc; + handleLoc.column = columnIndex + 1; + handleLoc.line = lineIndex + 1; // Make up a default entry StringSlicePool::Handle pathHandle = StringSlicePool::Handle(0); @@ -219,16 +219,27 @@ HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type) { const Entry& entry = m_entries[entryIndex]; // Adjust the line - humaneLoc.line += entry.m_lineAdjust; + handleLoc.line += entry.m_lineAdjust; // Get the pathHandle.. pathHandle = entry.m_pathHandle; } - humaneLoc.pathInfo = _getPathInfoFromHandle(pathHandle); + handleLoc.pathHandle = pathHandle; + return handleLoc; +} + +HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type) +{ + HandleSourceLoc handleLoc = getHandleLoc(loc, type); + + HumaneSourceLoc humaneLoc; + humaneLoc.column = handleLoc.column; + humaneLoc.line = handleLoc.line; + humaneLoc.pathInfo = _getPathInfoFromHandle(handleLoc.pathHandle); return humaneLoc; } -PathInfo SourceView::_getPathInfo() const +PathInfo SourceView::getViewPathInfo() const { if (m_viewPath.getLength()) { @@ -247,7 +258,7 @@ PathInfo SourceView::_getPathInfoFromHandle(StringSlicePool::Handle pathHandle) // If there is no override path, then just the source files path if (pathHandle == StringSlicePool::Handle(0)) { - return _getPathInfo(); + return getViewPathInfo(); } else { @@ -259,7 +270,7 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type) { if (type == SourceLocType::Actual) { - return _getPathInfo(); + return getViewPathInfo(); } const int entryIndex = findEntryIndex(loc); -- cgit v1.2.3