diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-28 15:09:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-28 15:09:19 -0800 |
| commit | f7db44a236bb867003395d1a91d6907901653528 (patch) | |
| tree | 84d65caea539337bf19fb4435a1fe6fa5de589fb /source/compiler-core | |
| parent | f23e36243e9c59c02f66ec2e18b80ba4ea540f45 (diff) | |
Add `SourceBlobWithPathInfoArtifactRepresentation`. (#2682)
Diffstat (limited to 'source/compiler-core')
| -rw-r--r-- | source/compiler-core/slang-artifact-representation-impl.cpp | 46 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-representation-impl.h | 39 |
2 files changed, 85 insertions, 0 deletions
diff --git a/source/compiler-core/slang-artifact-representation-impl.cpp b/source/compiler-core/slang-artifact-representation-impl.cpp index 950ce5d7d..3fae154bb 100644 --- a/source/compiler-core/slang-artifact-representation-impl.cpp +++ b/source/compiler-core/slang-artifact-representation-impl.cpp @@ -67,6 +67,52 @@ bool ExtFileArtifactRepresentation::exists() return SLANG_SUCCEEDED(res) && pathType == getPathType(); } +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SourceBlobWithPathArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* SourceBlobWithPathInfoArtifactRepresentation::getInterface(const Guid& guid) +{ + if (guid == ISlangUnknown::getTypeGuid() || + guid == ICastable::getTypeGuid() || + guid == IArtifactRepresentation::getTypeGuid() || + guid == IPathArtifactRepresentation::getTypeGuid()) + { + return static_cast<IPathArtifactRepresentation*>(this); + } + return nullptr; +} + +void* SourceBlobWithPathInfoArtifactRepresentation::getObject(const Guid& guid) +{ + SLANG_UNUSED(guid); + return nullptr; +} + +void* SourceBlobWithPathInfoArtifactRepresentation::castAs(const Guid& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + return getObject(guid); +} + +SlangResult SourceBlobWithPathInfoArtifactRepresentation::createRepresentation(const Guid& typeGuid, ICastable** outCastable) +{ + // We can convert into a blob only. + if (typeGuid != ISlangBlob::getTypeGuid()) + { + return SLANG_E_NOT_AVAILABLE; + } + + if (!m_blob) + { + return SLANG_E_NOT_AVAILABLE; + } + + *outCastable = CastableUtil::getCastable(m_blob).detach(); + return SLANG_OK; +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FileArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */ void* OSFileArtifactRepresentation::getInterface(const Guid& guid) diff --git a/source/compiler-core/slang-artifact-representation-impl.h b/source/compiler-core/slang-artifact-representation-impl.h index 880a90c18..4b6d49e06 100644 --- a/source/compiler-core/slang-artifact-representation-impl.h +++ b/source/compiler-core/slang-artifact-representation-impl.h @@ -10,6 +10,8 @@ #include "../core/slang-com-object.h" #include "../core/slang-memory-arena.h" +#include "slang-source-loc.h" + namespace Slang { @@ -106,6 +108,43 @@ protected: ComPtr<ISlangFileSystemExt> m_fileSystem; }; +class SourceBlobWithPathInfoArtifactRepresentation : public ComBaseObject, public IPathArtifactRepresentation +{ +public: + typedef SourceBlobWithPathInfoArtifactRepresentation ThisType; + + SLANG_COM_BASE_IUNKNOWN_ALL + + // ICastable + SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE; + + // IArtifactRepresentation + SLANG_NO_THROW SlangResult SLANG_MCALL createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE; + SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE { return false; } + + // IPathArtifactRepresentation + virtual SLANG_NO_THROW const char* SLANG_MCALL getPath() SLANG_OVERRIDE { return m_pathInfo.getName().getBuffer(); } + virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType() SLANG_OVERRIDE { return SLANG_PATH_TYPE_FILE; } + + SourceBlobWithPathInfoArtifactRepresentation(const PathInfo& pathInfo, ISlangBlob* sourceBlob) : + m_pathInfo(pathInfo), + m_blob(sourceBlob) + { + } + + static ComPtr<IPathArtifactRepresentation> create(const PathInfo& pathInfo, ISlangBlob* sourceBlob) + { + return ComPtr<IPathArtifactRepresentation>(new ThisType(pathInfo, sourceBlob)); + } + +protected: + void* getInterface(const Guid& uuid); + void* getObject(const Guid& uuid); + + PathInfo m_pathInfo; + ComPtr<ISlangBlob> m_blob; +}; + /* This allows wrapping any object to be an artifact representation. NOTE! Only allows casting from a single guid. Passing a RefObject across an ABI boundary remains risky! |
