From e794de0d63e6de9be564c971fd40486ecf631293 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 24 Mar 2023 09:56:59 -0400 Subject: Obfuscated source map writing (#2727) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP produce obfuscated source map and write when container is specified. * Make the sourcemap generated name stable. --- source/compiler-core/slang-source-map.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source/compiler-core/slang-source-map.h') diff --git a/source/compiler-core/slang-source-map.h b/source/compiler-core/slang-source-map.h index 739cf1992..accd2473f 100644 --- a/source/compiler-core/slang-source-map.h +++ b/source/compiler-core/slang-source-map.h @@ -43,7 +43,7 @@ struct SourceMap : public RefObject SlangResult encode(JSONContainer* container, DiagnosticSink* sink, JSONValue& outValue); /// Get the total number of generated lines - Count getGeneratedLineCount() const { return m_lineStarts.getCount() - 1; } + Count getGeneratedLineCount() const { return m_lineStarts.getCount(); } /// Get the entries on the line SLANG_FORCE_INLINE ConstArrayView getEntriesForLine(Index generatedLine) const; @@ -53,7 +53,7 @@ struct SourceMap : public RefObject void advanceToLine(Index lineIndex); /// Add an entry to the current line - void addEntry(const Entry& entry); + void addEntry(const Entry& entry) { m_lineEntries.add(entry); } /// Given the slice returns the index Index getSourceFileIndex(const UnownedStringSlice& slice); @@ -91,18 +91,20 @@ struct SourceMap : public RefObject // ------------------------------------------------------------- SLANG_FORCE_INLINE ConstArrayView SourceMap::getEntriesForLine(Index generatedLine) const { + SLANG_ASSERT(generatedLine >= 0 && generatedLine < m_lineStarts.getCount()); + const Index start = m_lineStarts[generatedLine]; - const Index end = m_lineStarts[generatedLine + 1]; - + + const Index end = (generatedLine + 1 >= m_lineStarts.getCount()) ? m_lineEntries.getCount() : m_lineStarts[generatedLine + 1]; + const auto entries = m_lineEntries.begin(); - SLANG_ASSERT(start >= 0 && start < m_lineEntries.getCount()); + SLANG_ASSERT(start >= 0 && start <= m_lineEntries.getCount()); SLANG_ASSERT(end >= start && end >= 0 && end <= m_lineEntries.getCount()); return ConstArrayView(entries + start, end - start); } - } // namespace Slang #endif // SLANG_COMPILER_CORE_SOURCE_MAP_H -- cgit v1.2.3