diff options
Diffstat (limited to 'source/compiler-core/slang-artifact-handler-impl.cpp')
| -rw-r--r-- | source/compiler-core/slang-artifact-handler-impl.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/source/compiler-core/slang-artifact-handler-impl.cpp b/source/compiler-core/slang-artifact-handler-impl.cpp index 985aa2337..1a8e8374d 100644 --- a/source/compiler-core/slang-artifact-handler-impl.cpp +++ b/source/compiler-core/slang-artifact-handler-impl.cpp @@ -17,6 +17,10 @@ #include "../core/slang-io.h" #include "../core/slang-shared-library.h" +#include "slang-source-map.h" + +#include "slang-json-source-map-util.h" + namespace Slang { /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! DefaultArtifactHandler !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -126,6 +130,25 @@ SlangResult DefaultArtifactHandler::expandChildren(IArtifact* container) return SLANG_OK; } +static SlangResult _loadSourceMap(IArtifact* artifact, ArtifactKeep intermediateKeep, RefPtr<SourceMap>& outSourceMap) +{ + const auto desc = artifact->getDesc(); + if (isDerivedFrom(desc.kind, ArtifactKind::Json) && + isDerivedFrom(desc.payload, ArtifactPayload::SourceMap)) + { + 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; + return SLANG_OK; + } + + return SLANG_FAIL; +} + SlangResult DefaultArtifactHandler::getOrCreateRepresentation(IArtifact* artifact, const Guid& guid, ArtifactKeep keep, ICastable** outCastable) { const auto reps = artifact->getRepresentations(); @@ -156,8 +179,16 @@ SlangResult DefaultArtifactHandler::getOrCreateRepresentation(IArtifact* artifac } } - // Special case shared library - if (guid == ISlangSharedLibrary::getTypeGuid()) + // Special cases + 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); + } + else if (guid == ISlangSharedLibrary::getTypeGuid()) { ComPtr<ISlangSharedLibrary> sharedLib; SLANG_RETURN_ON_FAIL(_loadSharedLibrary(artifact, sharedLib.writeRef())); @@ -169,6 +200,20 @@ 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()) + { + 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); + } + } + } return SLANG_E_NOT_AVAILABLE; } |
