summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-artifact-representation-impl.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-01 10:06:19 -0400
committerGitHub <noreply@github.com>2022-09-01 10:06:19 -0400
commit3c0177134d126956336865623ea3d6861be59cfa (patch)
tree920ba158afe75edde6f5254617dfa22ffeb98403 /source/compiler-core/slang-artifact-representation-impl.cpp
parentcd8715a7760189c54b36c0c250efbe1db5b8635c (diff)
Make FileSystem files and OS files distinct (#2383)
* #include an absolute path didn't work - because paths were taken to always be relative. * Make DownstreamCompileOptions use POD types. * CharSliceAllocator -> SliceAllocator Added SliceConverter CharSliceCaster -> SliceCaster * First attempt at zero terminating around blobs. * Fix clang warning. * Add SlangTerminatedChars Make Blob implementations support it. Make most blobs 'terminated'. * Fix bug setting up sourceFiles for CommandLineDownstreamCompiler. * Traffic in TerminatedCharSlice for sourceFiles. Use ArtifactDesc to generate temporary file names for source. * Fix typo in testing for shared library/C++. * Working with source being passed as artifacts to DownstreamCompiler. * Use artifacts in SourceManager/SourceFile. * Support infering extension from the original file extension. * * Infer extension if can't determine from the artifact type * Split IOSFile/IExtFile representations * Move responsibility for creating OS file to the handler. * Disable the check memory path.
Diffstat (limited to 'source/compiler-core/slang-artifact-representation-impl.cpp')
-rw-r--r--source/compiler-core/slang-artifact-representation-impl.cpp77
1 files changed, 66 insertions, 11 deletions
diff --git a/source/compiler-core/slang-artifact-representation-impl.cpp b/source/compiler-core/slang-artifact-representation-impl.cpp
index 4e33f2f0c..9a5c13311 100644
--- a/source/compiler-core/slang-artifact-representation-impl.cpp
+++ b/source/compiler-core/slang-artifact-representation-impl.cpp
@@ -13,32 +13,87 @@
namespace Slang {
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ExtFileArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void* ExtFileArtifactRepresentation::getInterface(const Guid& guid)
+{
+ if (guid == ISlangUnknown::getTypeGuid() ||
+ guid == ICastable::getTypeGuid() ||
+ guid == IArtifactRepresentation::getTypeGuid() ||
+ guid == IPathArtifactRepresentation::getTypeGuid() ||
+ guid == IExtFileArtifactRepresentation::getTypeGuid())
+ {
+ return static_cast<IPathArtifactRepresentation*>(this);
+ }
+ return nullptr;
+}
+
+void* ExtFileArtifactRepresentation::getObject(const Guid& guid)
+{
+ SLANG_UNUSED(guid);
+ return nullptr;
+}
+
+void* ExtFileArtifactRepresentation::castAs(const Guid& guid)
+{
+ if (auto intf = getInterface(guid))
+ {
+ return intf;
+ }
+ return getObject(guid);
+}
+
+SlangResult ExtFileArtifactRepresentation::createRepresentation(const Guid& typeGuid, ICastable** outCastable)
+{
+ // We can convert into a blob only, and only if we have a path
+ // If it's referenced by a name only, it's a file that *can't* be loaded as a blob in general.
+ if (typeGuid != ISlangBlob::getTypeGuid())
+ {
+ return SLANG_E_NOT_AVAILABLE;
+ }
+
+ ComPtr<ISlangBlob> blob;
+ SLANG_RETURN_ON_FAIL(m_fileSystem->loadFile(m_path.getBuffer(), blob.writeRef()));
+
+ *outCastable = CastableUtil::getCastable(blob).detach();
+ return SLANG_OK;
+}
+
+bool ExtFileArtifactRepresentation::exists()
+{
+ SlangPathType pathType;
+ const auto res = m_fileSystem->getPathType(m_path.getBuffer(), &pathType);
+ // It exists if it is a file
+ return SLANG_SUCCEEDED(res) && pathType == getPathType();
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FileArtifactRepresentation !!!!!!!!!!!!!!!!!!!!!!!!!!! */
-void* FileArtifactRepresentation::getInterface(const Guid& guid)
+void* OSFileArtifactRepresentation::getInterface(const Guid& guid)
{
if (guid == ISlangUnknown::getTypeGuid() ||
guid == ICastable::getTypeGuid() ||
guid == IArtifactRepresentation::getTypeGuid() ||
- guid == IFileArtifactRepresentation::getTypeGuid())
+ guid == IPathArtifactRepresentation::getTypeGuid() ||
+ guid == IOSFileArtifactRepresentation::getTypeGuid())
{
- return static_cast<IFileArtifactRepresentation*>(this);
+ return static_cast<IOSFileArtifactRepresentation*>(this);
}
return nullptr;
}
-void* FileArtifactRepresentation::getObject(const Guid& guid)
+void* OSFileArtifactRepresentation::getObject(const Guid& guid)
{
SLANG_UNUSED(guid);
return nullptr;
}
-ISlangMutableFileSystem* FileArtifactRepresentation::_getFileSystem()
+/* static */ISlangMutableFileSystem* OSFileArtifactRepresentation::_getFileSystem()
{
- return m_fileSystem ? m_fileSystem : OSFileSystem::getMutableSingleton();
+ return OSFileSystem::getMutableSingleton();
}
-void* FileArtifactRepresentation::castAs(const Guid& guid)
+void* OSFileArtifactRepresentation::castAs(const Guid& guid)
{
if (auto intf = getInterface(guid))
{
@@ -47,7 +102,7 @@ void* FileArtifactRepresentation::castAs(const Guid& guid)
return getObject(guid);
}
-SlangResult FileArtifactRepresentation::createRepresentation(const Guid& typeGuid, ICastable** outCastable)
+SlangResult OSFileArtifactRepresentation::createRepresentation(const Guid& typeGuid, ICastable** outCastable)
{
// We can convert into a blob only, and only if we have a path
// If it's referenced by a name only, it's a file that *can't* be loaded as a blob in general.
@@ -66,7 +121,7 @@ SlangResult FileArtifactRepresentation::createRepresentation(const Guid& typeGui
return SLANG_OK;
}
-bool FileArtifactRepresentation::exists()
+bool OSFileArtifactRepresentation::exists()
{
// TODO(JS):
// If it's a name only it's hard to know what exists should do. It can't *check* because it relies on the 'system' doing
@@ -86,7 +141,7 @@ bool FileArtifactRepresentation::exists()
return SLANG_SUCCEEDED(res) && pathType == SLANG_PATH_TYPE_FILE;
}
-void FileArtifactRepresentation::disown()
+void OSFileArtifactRepresentation::disown()
{
if (_isOwned())
{
@@ -94,7 +149,7 @@ void FileArtifactRepresentation::disown()
}
}
-FileArtifactRepresentation::~FileArtifactRepresentation()
+OSFileArtifactRepresentation::~OSFileArtifactRepresentation()
{
if (_isOwned())
{