diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-17 01:13:59 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-16 22:13:59 -0700 |
| commit | 2fd1ac6c85230d47c008e45fefcc1c49400e96bd (patch) | |
| tree | 125dc743c472c243cbc84e7d2a600804a3737733 /tools | |
| parent | 4cb899f824ee5e4421f36506e4c77f682b238b09 (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 'tools')
| -rw-r--r-- | tools/slang-unit-test/unit-test-source-map.cpp | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/tools/slang-unit-test/unit-test-source-map.cpp b/tools/slang-unit-test/unit-test-source-map.cpp index 1b48980f8..b973a9c62 100644 --- a/tools/slang-unit-test/unit-test-source-map.cpp +++ b/tools/slang-unit-test/unit-test-source-map.cpp @@ -20,7 +20,7 @@ static SlangResult _check() sourceManager.initialize(nullptr, nullptr); DiagnosticSink sink(&sourceManager, nullptr); - const char json[] = R"( + const char jsonSource[] = R"( { "version" : 3, "file" : "out.js", @@ -28,18 +28,16 @@ static SlangResult _check() "sources" : ["foo.js", "bar.js"], "sourcesContent" : [null, null], "names" : ["src", "maps", "are", "fun"], - "mappings" : "A,AAAB;;ABCEG;" + "mappings" : "A,AAAB;;ABCEG;" } )"; RefPtr<JSONContainer> container = new JSONContainer(&sourceManager); - RttiTypeFuncsMap typeMap = JSONNativeUtil::getTypeFuncsMap(); - - JSONValue readValue; + JSONValue rootValue; { // Now need to parse as JSON - String contents(json); + String contents(jsonSource); SourceFile* sourceFile = sourceManager.createSourceFileWithString(PathInfo::makeUnknown(), contents); SourceView* sourceView = sourceManager.createSourceView(sourceFile, nullptr, SourceLoc()); @@ -51,40 +49,27 @@ static SlangResult _check() JSONParser parser; SLANG_RETURN_ON_FAIL(parser.parse(&lexer, sourceView, &builder, &sink)); - readValue = builder.getRootValue(); - } - - // Convert to native - JSONSourceMap readS; - { - JSONToNativeConverter converter(container, &typeMap, &sink); - - // Read it back - SLANG_RETURN_ON_FAIL(converter.convert(readValue, GetRttiInfo<JSONSourceMap>::get(), &readS)); + rootValue = builder.getRootValue(); } + SourceMap sourceMap; + + SLANG_RETURN_ON_FAIL(sourceMap.decode(container, rootValue, &sink)); + // Write it out + String json; { - String json; - - NativeToJSONConverter converter(container, &typeMap, &sink); - - JSONValue value; - SLANG_RETURN_ON_FAIL(converter.convert(GetRttiInfo<JSONSourceMap>::get(), &readS, value)); + JSONValue jsonValue; + SLANG_RETURN_ON_FAIL(sourceMap.encode(container, &sink, jsonValue)); + // Convert into a string JSONWriter writer(JSONWriter::IndentationStyle::Allman); - container->traverseRecursively(value, &writer); + container->traverseRecursively(jsonValue, &writer); json = writer.getBuilder(); } - { - SourceMap sourceMap; - - SLANG_RETURN_ON_FAIL(sourceMap.decode(container, readS)); - } - return SLANG_OK; } |
