summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact-handler-impl.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-04-19 17:06:56 -0400
committerGitHub <noreply@github.com>2023-04-19 17:06:56 -0400
commit588991f6df3d6813378721166a7260990835817e (patch)
treefca8c57fedb1967af20ca2da50bbd7dc8afc6a07 /source/compiler-core/slang-artifact-handler-impl.cpp
parent520a3c064c42e8cd50ef4fde21539870d5b19cb7 (diff)
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
Diffstat (limited to 'source/compiler-core/slang-artifact-handler-impl.cpp')
-rw-r--r--source/compiler-core/slang-artifact-handler-impl.cpp35
1 files changed, 15 insertions, 20 deletions
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<SourceMap>& 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<ISlangBlob> blob;
SLANG_RETURN_ON_FAIL(artifact->loadBlob(intermediateKeep, blob.writeRef()));
- RefPtr<SourceMap> 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> sourceMap;
- SLANG_RETURN_ON_FAIL(_loadSourceMap(artifact, getIntermediateKeep(keep), sourceMap));
- ComPtr<IObjectCastableAdapter> castable(new ObjectCastableAdapter(sourceMap));
- return _addRepresentation(artifact, keep, castable, outCastable);
+ ComPtr<IBoxValue<SourceMap>> sourceMap(new BoxValue<SourceMap>);
+ 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<SourceMap>(rep))
- {
- // SourceMap -> Blob
- ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::write(sourceMap, blob));
- // Add the rep
- return _addRepresentation(artifact, keep, blob, outCastable);
- }
+ if (auto sourceMap = findRepresentation<SourceMap>(artifact))
+ {
+ // SourceMap -> Blob
+ ComPtr<ISlangBlob> blob;
+ SLANG_RETURN_ON_FAIL(JSONSourceMapUtil::write(*sourceMap, blob));
+ // Add the rep
+ return _addRepresentation(artifact, keep, blob, outCastable);
}
}