summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-artifact-representation-impl.cpp46
-rw-r--r--source/compiler-core/slang-artifact-representation-impl.h39
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!