diff options
Diffstat (limited to 'source/compiler-core/slang-source-map.cpp')
| -rw-r--r-- | source/compiler-core/slang-source-map.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/source/compiler-core/slang-source-map.cpp b/source/compiler-core/slang-source-map.cpp index 413c32108..830314008 100644 --- a/source/compiler-core/slang-source-map.cpp +++ b/source/compiler-core/slang-source-map.cpp @@ -199,6 +199,86 @@ void SourceMap::clear() m_slicePool.clear(); } +void SourceMap::advanceToLine(Index nextLineIndex) +{ + const Count currentLineIndex = getGeneratedLineCount(); + + SLANG_ASSERT(nextLineIndex >= currentLineIndex); + + if (nextLineIndex <= currentLineIndex) + { + return; + } + + const auto lastEntryIndex = m_lineEntries.getCount(); + + // For all the new entries they will need to point to the end + m_lineStarts.setCount(nextLineIndex + 1); + + Index* starts = m_lineStarts.getBuffer() + currentLineIndex; + const Count startsCount = nextLineIndex + 1 - currentLineIndex; + + for (Index i = 0; i < startsCount; ++i) + { + starts[i] = lastEntryIndex; + } +} + +void SourceMap::addEntry(const Entry& entry) +{ + m_lineEntries.add(entry); + ++m_lineStarts.getLast(); + + // Check things seem normal... + SLANG_ASSERT(m_lineStarts.getLast() == m_lineEntries.getCount()); +} + +Index SourceMap::getNameIndex(const UnownedStringSlice& slice) +{ + StringSlicePool::Handle handle; + + if (!m_slicePool.findOrAdd(slice, handle)) + { + // We know it can't possibly be used, so must be new (!) + + m_names.add(handle); + return m_names.getCount() - 1; + } + + // Okay, could already be in the list + const auto index = m_names.indexOf(handle); + if (index >= 0) + { + return index; + } + + m_names.add(handle); + return m_names.getCount() - 1; +} + +Index SourceMap::getSourceFileIndex(const UnownedStringSlice& slice) +{ + StringSlicePool::Handle handle; + + if (!m_slicePool.findOrAdd(slice, handle)) + { + // We know it can't possibly be used, so must be new (!) + + m_sources.add(handle); + return m_sources.getCount() - 1; + } + + // Okay, could already be in the list + const auto index = m_sources.indexOf(handle); + if (index >= 0) + { + return index; + } + + m_sources.add(handle); + return m_sources.getCount() - 1; +} + SlangResult SourceMap::decode(JSONContainer* container, JSONValue root, DiagnosticSink* sink) { clear(); |
