summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-source-map.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-03-17 01:13:59 -0400
committerGitHub <noreply@github.com>2023-03-16 22:13:59 -0700
commit2fd1ac6c85230d47c008e45fefcc1c49400e96bd (patch)
tree125dc743c472c243cbc84e7d2a600804a3737733 /source/compiler-core/slang-source-map.h
parent4cb899f824ee5e4421f36506e4c77f682b238b09 (diff)
SourceMap encoding (#2706)
* #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.
Diffstat (limited to 'source/compiler-core/slang-source-map.h')
-rw-r--r--source/compiler-core/slang-source-map.h69
1 files changed, 18 insertions, 51 deletions
diff --git a/source/compiler-core/slang-source-map.h b/source/compiler-core/slang-source-map.h
index 0f84878fe..7fd64510a 100644
--- a/source/compiler-core/slang-source-map.h
+++ b/source/compiler-core/slang-source-map.h
@@ -15,73 +15,37 @@
namespace Slang {
-/*
-Support for source maps. Source maps provide a standardized mechanism to associate a location in one output file
-with another.
-
-* [Source Map Proposal](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?hl=en_US&pli=1&pli=1)
-* [Chrome Source Map post](https://developer.chrome.com/blog/sourcemaps/)
-* [Base64 VLQs in Source Maps](https://www.lucidchart.com/techblog/2019/08/22/decode-encoding-base64-vlqs-source-maps/)
-
-Example...
-
-{
-"version" : 3,
-"file": "out.js",
-"sourceRoot": "",
-"sources": ["foo.js", "bar.js"],
-"sourcesContent": [null, null],
-"names": ["src", "maps", "are", "fun"],
-"mappings": "A,AAAB;;ABCDE;"
-}
-*/
-
-struct JSONSourceMap
-{
- /// File version (always the first entry in the object) and must be a positive integer.
- int32_t version = 3;
- /// An optional name of the generated code that this source map is associated with.
- String file;
- /// An optional source root, useful for relocating source files on a server or removing repeated values in
- /// the “sources” entry. This value is prepended to the individual entries in the “source” field.
- String sourceRoot;
- /// A list of original sources used by the “mappings” entry.
- List<UnownedStringSlice> sources;
- /// An optional list of source content, useful when the “source” can’t be hosted. The contents are listed in the same order as the sources in line 5.
- /// “null” may be used if some original sources should be retrieved by name.
- /// Because could be a string or nullptr, we use JSONValue to hold value.
- List<JSONValue> sourcesContent;
- /// A list of symbol names used by the “mappings” entry.
- List<UnownedStringSlice> names;
- /// A string with the encoded mapping data.
- UnownedStringSlice mappings;
-
- static const StructRttiInfo g_rttiInfo;
-};
-
struct SourceMap
{
struct Entry
{
// Note! All column/line are zero indexed
-
- Index generatedColumn; ///< The generated column
- Index sourceFileIndex; ///< The index into the source name/contents
- Index sourceLine; ///< The line number in the originating source
- Index sourceColumn; ///< The column number in the originating source
+ Index generatedColumn; ///< The generated column
+ Index sourceFileIndex; ///< The index into the source name/contents
+ Index sourceLine; ///< The line number in the originating source
+ Index sourceColumn; ///< The column number in the originating source
+ Index nameIndex; ///< Name index
};
- SlangResult decode(JSONContainer* container, const JSONSourceMap& src);
+ /// Decode from root into the source map
+ SlangResult decode(JSONContainer* container, JSONValue root, DiagnosticSink* sink);
+
+ /// Converts the source map contents into JSON
+ SlangResult encode(JSONContainer* container, DiagnosticSink* sink, JSONValue& outValue);
/// Get the total number of generated lines
Count getGeneratedLineCount() const { return m_lineStarts.getCount() - 1; }
/// Get the entries on the line
SLANG_FORCE_INLINE ConstArrayView<Entry> getEntriesForLine(Index generatedLine) const;
+ /// Clear the contents of the source map
+ void clear();
+
/// Ctor
SourceMap():
m_slicePool(StringSlicePool::Style::Default)
{
+ clear();
}
String m_file;
@@ -92,6 +56,9 @@ struct SourceMap
/// Storage for the contents. Can be unset null to indicate not set.
List<StringSlicePool::Handle> m_sourcesContent;
+ /// The names
+ List<StringSlicePool::Handle> m_names;
+
List<Index> m_lineStarts;
List<Entry> m_lineEntries;
@@ -107,7 +74,7 @@ SLANG_FORCE_INLINE ConstArrayView<SourceMap::Entry> SourceMap::getEntriesForLine
const auto entries = m_lineEntries.begin();
SLANG_ASSERT(start >= 0 && start < m_lineEntries.getCount());
- SLANG_ASSERT(end >= start && end >= 0 && end < m_lineEntries.getCount());
+ SLANG_ASSERT(end >= start && end >= 0 && end <= m_lineEntries.getCount());
return ConstArrayView<SourceMap::Entry>(entries + start, end - start);
}