From 5c2c2cfc9918bb43225159e67a851e196e17759a Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 26 Aug 2022 20:32:53 -0400 Subject: DownstreamCompileOptions using POD types (#2381) * #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++. --- source/core/slang-blob.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'source/core/slang-blob.cpp') diff --git a/source/core/slang-blob.cpp b/source/core/slang-blob.cpp index 0da8f6292..6cf5214cc 100644 --- a/source/core/slang-blob.cpp +++ b/source/core/slang-blob.cpp @@ -33,6 +33,104 @@ void* BlobBase::castAs(const SlangUUID& guid) return getObject(guid); } +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* StringBlob::castAs(const SlangUUID& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + return getObject(guid); +} + +void* StringBlob::getObject(const Guid& guid) +{ + // Can allow accessing the contained String + if (guid == getTypeGuid()) + { + return this; + } + // Can always be accessed as terminated char* + if (guid == SlangTerminatedChars::getTypeGuid()) + { + return const_cast(m_string.getBuffer()); + } + return nullptr; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RawBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* RawBlob::castAs(const SlangUUID& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + return getObject(guid); +} + +void* RawBlob::getObject(const Guid& guid) +{ + // If the data has 0 termination, we can return the pointer + if (guid == SlangTerminatedChars::getTypeGuid() && m_data.isTerminated()) + { + return (char*)m_data.getData(); + } + return nullptr; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ScopeBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* ScopeBlob::castAs(const SlangUUID& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + if (auto obj = getObject(guid)) + { + return obj; + } + + // If the contained thing is castable, ask it + if (m_castable) + { + return m_castable->castAs(guid); + } + + return nullptr; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ListBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +void* ListBlob::castAs(const SlangUUID& guid) +{ + if (auto intf = getInterface(guid)) + { + return intf; + } + return getObject(guid); +} + +void* ListBlob::getObject(const Guid& guid) +{ + // If the data is terminated return the pointer + if (guid == SlangTerminatedChars::getTypeGuid()) + { + const auto count = m_data.getCount(); + if (m_data.getCapacity() > count) + { + auto buf = m_data.getBuffer(); + if (buf[count] == 0) + { + return (char*)buf; + } + } + } + return nullptr; +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StaticBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ SlangResult StaticBlob::queryInterface(SlangUUID const& guid, void** outObject) -- cgit v1.2.3