From 588991f6df3d6813378721166a7260990835817e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 19 Apr 2023 17:06:56 -0400 Subject: Make SourceMap a value type (#2812) * #include an absolute path didn't work - because paths were taken to always be relative. * Moved JSON source map writing logic to JSONSourceMapUtil. * Use ArtifactHandler to read/write SourceMaps. Use ObjectCastableAdapter to hold SourceMap Only serialize SourceMap <-> JSON on demand. * Make some types swappable. * BoxValue impl. * Added asBoxValue. * Remove const get funcs. * Fix typo in asBoxValue. * Fix another typo in asBoxValue. * Slightly simplify conversion to blob of SourceMap. * Small fix for asBoxValue --- .../compiler-core/slang-artifact-handler-impl.cpp | 35 ++++++++++------------ 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'source/compiler-core/slang-artifact-handler-impl.cpp') diff --git a/source/compiler-core/slang-artifact-handler-impl.cpp b/source/compiler-core/slang-artifact-handler-impl.cpp index 1a8e8374d..5d2a74036 100644 --- a/source/compiler-core/slang-artifact-handler-impl.cpp +++ b/source/compiler-core/slang-artifact-handler-impl.cpp @@ -130,7 +130,7 @@ SlangResult DefaultArtifactHandler::expandChildren(IArtifact* container) return SLANG_OK; } -static SlangResult _loadSourceMap(IArtifact* artifact, ArtifactKeep intermediateKeep, RefPtr& outSourceMap) +static SlangResult _loadSourceMap(IArtifact* artifact, ArtifactKeep intermediateKeep, SourceMap& outSourceMap) { const auto desc = artifact->getDesc(); if (isDerivedFrom(desc.kind, ArtifactKind::Json) && @@ -139,10 +139,7 @@ static SlangResult _loadSourceMap(IArtifact* artifact, ArtifactKeep intermediate ComPtr blob; SLANG_RETURN_ON_FAIL(artifact->loadBlob(intermediateKeep, blob.writeRef())); - RefPtr sourceMap; - SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::read(blob, sourceMap)); - - outSourceMap = sourceMap; + SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::read(blob, outSourceMap)); return SLANG_OK; } @@ -183,10 +180,9 @@ SlangResult DefaultArtifactHandler::getOrCreateRepresentation(IArtifact* artifac if (guid == SourceMap::getTypeGuid()) { // Blob -> SourceMap - RefPtr sourceMap; - SLANG_RETURN_ON_FAIL(_loadSourceMap(artifact, getIntermediateKeep(keep), sourceMap)); - ComPtr castable(new ObjectCastableAdapter(sourceMap)); - return _addRepresentation(artifact, keep, castable, outCastable); + ComPtr> sourceMap(new BoxValue); + SLANG_RETURN_ON_FAIL(_loadSourceMap(artifact, getIntermediateKeep(keep), sourceMap->get())); + return _addRepresentation(artifact, keep, sourceMap, outCastable); } else if (guid == ISlangSharedLibrary::getTypeGuid()) { @@ -200,18 +196,17 @@ SlangResult DefaultArtifactHandler::getOrCreateRepresentation(IArtifact* artifac SLANG_RETURN_ON_FAIL(_createOSFile(artifact, getIntermediateKeep(keep), fileRep.writeRef())); return _addRepresentation(artifact, keep, fileRep, outCastable); } - else if (guid == ISlangBlob::getTypeGuid()) + + // Handle known conversion to blobs + if (guid == ISlangBlob::getTypeGuid()) { - for (ICastable* rep : reps) - { - if (SourceMap* sourceMap = as(rep)) - { - // SourceMap -> Blob - ComPtr blob; - SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::write(sourceMap, blob)); - // Add the rep - return _addRepresentation(artifact, keep, blob, outCastable); - } + if (auto sourceMap = findRepresentation(artifact)) + { + // SourceMap -> Blob + ComPtr blob; + SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::write(*sourceMap, blob)); + // Add the rep + return _addRepresentation(artifact, keep, blob, outCastable); } } -- cgit v1.2.3