summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-artifact-handler-impl.cpp
diff options
context:
space:
mode:
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);
}
}