diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-04-01 18:59:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-01 15:59:24 -0700 |
| commit | 9475b11045089c9bc9773b16f7eb84f843db70c4 (patch) | |
| tree | f2855e1283a3811fd771d646f6e2532ca9cb5e21 /source/slang | |
| parent | 2a32fae2ca766862ad76973ab37605edf9ec0faa (diff) | |
Associating GUID (or UUID) with types (#1776)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Add mechanism to embed guid inside of type.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-check.cpp | 5 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.cpp | 4 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 9 | ||||
| -rwxr-xr-x | source/slang/slang-dxc-support.cpp | 5 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 37 |
5 files changed, 17 insertions, 43 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index cfc8c504c..600578297 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -18,9 +18,6 @@ namespace Slang PassThroughMode compilerType; }; - const Guid IID_ISlangSharedLibraryLoader = SLANG_UUID_ISlangSharedLibraryLoader; - const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; - class SinkSharedLibraryLoader : public RefObject, public ISlangSharedLibraryLoader { public: @@ -57,7 +54,7 @@ namespace Slang protected: ISlangUnknown* getInterface(const Guid& guid) { - return (guid == IID_ISlangUnknown || guid == IID_ISlangSharedLibraryLoader) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr; + return (guid == ISlangUnknown::getTypeGuid() || guid == ISlangSharedLibraryLoader::getTypeGuid()) ? static_cast<ISlangSharedLibraryLoader*>(this) : nullptr; } ISlangSharedLibraryLoader* m_loader; DiagnosticSink* m_sink; diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index c034f5f7d..44cfebf13 100755 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -185,11 +185,9 @@ namespace Slang // EntryPoint // - static const Guid IID_IEntryPoint = SLANG_UUID_IEntryPoint; - ISlangUnknown* EntryPoint::getInterface(const Guid& guid) { - if(guid == IID_IEntryPoint) + if(guid == slang::IEntryPoint::getTypeGuid()) return static_cast<slang::IEntryPoint*>(this); return Super::getInterface(guid); diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index b1e3c3a70..a3eac6fa6 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -37,8 +37,6 @@ namespace Slang class TargetRequest; class TypeLayout; - extern const Guid IID_EndToEndCompileRequest; - enum class CompilerMode { ProduceLibrary, @@ -1872,9 +1870,6 @@ namespace Slang RefPtr<ComponentType> m_program; }; - // UUID to identify EndToEndCompileRequest from an interface - #define SLANG_UUID_EndToEndCompileRequest { 0xce6d2383, 0xee1b, 0x4fd7, { 0xa0, 0xf, 0xb8, 0xb6, 0x33, 0x12, 0x95, 0xc8 } }; - /// A compile request that spans the front and back ends of the compiler /// /// This is what the command-line `slangc` uses, as well as the legacy @@ -1886,6 +1881,8 @@ namespace Slang class EndToEndCompileRequest : public RefObject, public slang::ICompileRequest { public: + SLANG_CLASS_GUID(0xce6d2383, 0xee1b, 0x4fd7, { 0xa0, 0xf, 0xb8, 0xb6, 0x33, 0x12, 0x95, 0xc8 }) + // ISlangUnknown SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) SLANG_OVERRIDE; SLANG_REF_OBJECT_IUNKNOWN_ADD_REF @@ -2402,7 +2399,7 @@ SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* reque SLANG_ASSERT(request); EndToEndCompileRequest* endToEndRequest = nullptr; // NOTE! We aren't using to access an interface, so *doesn't* return with a refcount - request->queryInterface(IID_EndToEndCompileRequest, (void**)&endToEndRequest); + request->queryInterface(EndToEndCompileRequest::getTypeGuid(), (void**)&endToEndRequest); SLANG_ASSERT(endToEndRequest); return endToEndRequest; } diff --git a/source/slang/slang-dxc-support.cpp b/source/slang/slang-dxc-support.cpp index 9abc4331e..4e5e4080e 100755 --- a/source/slang/slang-dxc-support.cpp +++ b/source/slang/slang-dxc-support.cpp @@ -48,8 +48,7 @@ namespace Slang // IDxcIncludeHandler // 7f61fc7d-950d-467f-b3e3-3c02fb49187c static const Guid IID_IDxcIncludeHandler = { 0x7f61fc7d, 0x950d, 0x467f, { 0x3c, 0x02, 0xfb, 0x49, 0x18, 0x7c } }; - static const Guid IID_IUnknown = SLANG_UUID_ISlangUnknown; - + class DxcIncludeHandler : public IDxcIncludeHandler { public: @@ -109,7 +108,7 @@ namespace Slang // Used by QueryInterface for casting ISlangUnknown* getInterface(const Guid& guid) { - if (guid == IID_IUnknown || guid == IID_IDxcIncludeHandler) + if (guid == ISlangUnknown::getTypeGuid() || guid == IID_IDxcIncludeHandler) { return (ISlangUnknown*)(static_cast<IDxcIncludeHandler*>(this)); } diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 5c04777de..8c6bf403e 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -108,20 +108,6 @@ namespace Slang { } } -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_IComponentType = SLANG_UUID_IComponentType; -static const Guid IID_IEntryPoint = SLANG_UUID_IEntryPoint; -static const Guid IID_IGlobalSession = SLANG_UUID_IGlobalSession; -static const Guid IID_IModule = SLANG_UUID_IModule; -static const Guid IID_ISession = SLANG_UUID_ISession; -static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; - -static const Guid IID_ICompileRequest = SLANG_UUID_ICompileRequest; - -// Available to other modules so not static -const Guid IID_EndToEndCompileRequest = SLANG_UUID_EndToEndCompileRequest; - const char* getBuildTagString() { return SLANG_TAG_VERSION; @@ -447,7 +433,7 @@ SlangResult Session::_readBuiltinModule(ISlangFileSystem* fileSystem, Scope* sco ISlangUnknown* Session::getInterface(const Guid& guid) { - if(guid == IID_ISlangUnknown || guid == IID_IGlobalSession) + if(guid == ISlangUnknown::getTypeGuid() || guid == IGlobalSession::getTypeGuid()) return asExternal(this); return nullptr; } @@ -750,7 +736,7 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka ISlangUnknown* Linkage::getInterface(const Guid& guid) { - if(guid == IID_ISlangUnknown || guid == IID_ISession) + if(guid == ISlangUnknown::getTypeGuid() || guid == ISession::getTypeGuid()) return asExternal(this); return nullptr; @@ -1969,7 +1955,7 @@ EndToEndCompileRequest::EndToEndCompileRequest( SLANG_NO_THROW SlangResult SLANG_MCALL EndToEndCompileRequest::queryInterface(SlangUUID const& uuid, void** outObject) { - if (uuid == IID_EndToEndCompileRequest) + if (uuid == EndToEndCompileRequest::getTypeGuid()) { // Special case to cast directly into internal type // NOTE! No addref(!) @@ -1977,7 +1963,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL EndToEndCompileRequest::queryInterface(Sl return SLANG_OK; } - if (uuid == IID_ISlangUnknown && uuid == IID_ICompileRequest) + if (uuid == ISlangUnknown::getTypeGuid() && uuid == ICompileRequest::getTypeGuid()) { addReference(); *outObject = static_cast<slang::ICompileRequest*>(this); @@ -2566,7 +2552,7 @@ Module::Module(Linkage* linkage, ASTBuilder* astBuilder) ISlangUnknown* Module::getInterface(const Guid& guid) { - if(guid == IID_IModule) + if(guid == IModule::getTypeGuid()) return asExternal(this); return Super::getInterface(guid); } @@ -2711,14 +2697,14 @@ ComponentType* asInternal(slang::IComponentType* inComponentType) // (without even `addRef`-ing it). // ComPtr<slang::IComponentType> componentType; - inComponentType->queryInterface(IID_IComponentType, (void**) componentType.writeRef()); + inComponentType->queryInterface(slang::IComponentType::getTypeGuid(), (void**) componentType.writeRef()); return static_cast<ComponentType*>(componentType.get()); } ISlangUnknown* ComponentType::getInterface(Guid const& guid) { - if(guid == IID_ISlangUnknown - || guid == IID_IComponentType) + if(guid == ISlangUnknown::getTypeGuid() + || guid == slang::IComponentType::getTypeGuid()) { return static_cast<slang::IComponentType*>(this); } @@ -3632,9 +3618,6 @@ Session* CompileRequestBase::getSession() return getLinkage()->getSessionImpl(); } -static const Slang::Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; -static const Slang::Guid IID_SlangCacheFileSystem = SLANG_UUID_CacheFileSystem; - void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) { // Set the fileSystem @@ -3653,7 +3636,7 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) else { CacheFileSystem* cacheFileSystemPtr = nullptr; - inFileSystem->queryInterface(IID_SlangCacheFileSystem, (void**)&cacheFileSystemPtr); + inFileSystem->queryInterface(CacheFileSystem::getTypeGuid(), (void**)&cacheFileSystemPtr); if (cacheFileSystemPtr) { m_cacheFileSystem = cacheFileSystemPtr; @@ -3669,7 +3652,7 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) else { // See if we have the full ISlangFileSystemExt interface, if we do just use it - inFileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)m_fileSystemExt.writeRef()); + inFileSystem->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)m_fileSystemExt.writeRef()); // If not wrap with CacheFileSystem that emulates ISlangFileSystemExt from the ISlangFileSystem interface if (!m_fileSystemExt) |
