diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-22 12:04:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-22 12:04:33 -0400 |
| commit | d4f99c8bac8b28f18c864a717d8833db6a1c872d (patch) | |
| tree | ebea06c019130d8248d5e4f6bccf5e4b2649e3cb /source/slang/slang-emit-source-writer.cpp | |
| parent | d8a40abba5223fbcb56c52b04ccb88c02bbaf79f (diff) | |
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.
Diffstat (limited to 'source/slang/slang-emit-source-writer.cpp')
| -rw-r--r-- | source/slang/slang-emit-source-writer.cpp | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/source/slang/slang-emit-source-writer.cpp b/source/slang/slang-emit-source-writer.cpp index b27e0f8b4..f66f36758 100644 --- a/source/slang/slang-emit-source-writer.cpp +++ b/source/slang/slang-emit-source-writer.cpp @@ -1,6 +1,8 @@ // slang-emit-source-writer.cpp #include "slang-emit-source-writer.h" +#include "../core/slang-char-encode.h" + // Disable warnings about sprintf #ifdef _WIN32 # pragma warning(disable:4996) @@ -516,61 +518,60 @@ void SourceWriter::_emitLineDirective(const HumaneSourceLoc& sourceLocation) void SourceWriter::_calcLocation(Index& outLineIndex, Index& outColumnIndex) { - // If we are at the end, then we are done. - if (m_currentOutputOffset == m_builder.getLength()) - { - outLineIndex = m_currentLineIndex; - outColumnIndex = m_currentColumnIndex; - return; - } - - const char* cur = m_builder.getBuffer() + m_currentOutputOffset; - const char* end = m_builder.end(); - - const char* start = cur; - - while (cur < end) + // If there are move chars we need to update + if (m_currentOutputOffset < m_builder.getLength()) { - // Reset start - start = cur; + const char* cur = m_builder.getBuffer() + m_currentOutputOffset; + const char* end = m_builder.end(); - // Look for the end of the line - while (*cur != '\n' && *cur != '\r' && cur < end) - { - cur++; - } + const char* start = cur; - // If we are not at the total end then we must have hit a \n or \r - if (cur < end) + while (cur < end) { - const auto c = *cur++; + // Reset start + start = cur; - ++m_currentLineIndex; - // Reset the column - m_currentColumnIndex = 0; + // Look for the end of the line + while (*cur != '\n' && *cur != '\r' && cur < end) + { + cur++; + } - // Check the next char to see if it's part of a CR/LF combination + // If we are not at the total end then we must have hit a \n or \r if (cur < end) { - const auto d = *cur; - // If it is combination skip the next byte - cur += ((c ^ d) == ('\r' ^ '\n')); + const auto c = *cur++; + + // Next line + ++m_currentLineIndex; + + // Check the next char to see if it's part of a CR/LF combination + if (cur < end) + { + const auto d = *cur; + // If it is combination skip the next byte + cur += ((c ^ d) == ('\r' ^ '\n')); + } + + // Calculate the offset to the start of this line + m_currentColumnIndex = 0; + start = cur; } } - } - // Fix up the current index. - // TODO(JS): - // NOTE! This isn't strictly correct because it assumes one byte is a *column* which isn't actually the case with utf8 - // encoding... - m_currentColumnIndex += Index(cur - start); + // Set the current offset to the end + m_currentOutputOffset = m_builder.getLength(); - // Set the current offset is the end - m_currentOutputOffset = m_builder.getLength(); + // Get the bytes remaining on this line (which may not be complete) + const UnownedStringSlice lineRemaining(start, m_builder.end()); - // Output the values - outLineIndex = m_currentLineIndex; + // Offset the column index in codepoints + m_currentColumnIndex += UTF8Util::calcCodePointCount(lineRemaining); + } + + // Output the position outColumnIndex = m_currentColumnIndex; + outLineIndex = m_currentLineIndex; } } // namespace Slang |
