diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-04-11 10:18:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-11 10:18:18 -0400 |
| commit | 20ea33f3321738e7c1b4cad7bdcaedcdb54dd0f0 (patch) | |
| tree | 899484670ffacf3e884b5d670e2cc8ed6d5259e3 /source/compiler-core/slang-artifact-impl.h | |
| parent | d934bbcc5702ebd8964f65b1708c239c29320103 (diff) | |
Artifact simplification (#2781)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP simplifying artifact interface.
* Use ContainedKind.
* Remove LazyCastableList.
Use ContainedKind for find.
* Remove ICastableList.
* Remove need for ICastableList.
* Remove IArtifactContainer.
* Small fixes.
* Small improvements around Artifact.
* Make explicit find is for *representations* that can cast.
Fix bug in handling casting in lookup.
* Made associated items artifacts too.
* Small fixes.
* Small improvements around writing a container.
Diffstat (limited to 'source/compiler-core/slang-artifact-impl.h')
| -rw-r--r-- | source/compiler-core/slang-artifact-impl.h | 107 |
1 files changed, 21 insertions, 86 deletions
diff --git a/source/compiler-core/slang-artifact-impl.h b/source/compiler-core/slang-artifact-impl.h index b59c700d8..4862142a8 100644 --- a/source/compiler-core/slang-artifact-impl.h +++ b/source/compiler-core/slang-artifact-impl.h @@ -4,8 +4,6 @@ #include "slang-artifact.h" -#include "../core/slang-lazy-castable-list.h" - #include "../../slang-com-helper.h" #include "../../slang-com-ptr.h" @@ -26,13 +24,10 @@ as the main structure. Within this it can contain kernels, and then a json manif This all 'works', in that we can add an element of ISlangFileSystem with a desc of Container. Code that uses this can then go through the process of finding, and getting the blob, and find from the manifest what it means. That does sound a little tedious though. Perhaps we just have an interface that handles this detail, such that we search for that first. That interface is just attached to the artifact as an element. - -Note: Implementation of the IArtifact interface. We derive from IArtifactContainer, such that we don't have the -irritating multiple inheritance issue. */ -class Artifact : public ComBaseObject, public IArtifactContainer +*/ +class Artifact : public ComBaseObject, public IArtifact { public: - SLANG_COM_BASE_IUNKNOWN_ALL /// ICastable @@ -49,36 +44,26 @@ public: virtual SLANG_NO_THROW const char* SLANG_MCALL getName() SLANG_OVERRIDE { return m_name.getBuffer(); } virtual SLANG_NO_THROW void SLANG_MCALL setName(const char* name) SLANG_OVERRIDE { m_name = name; } - virtual SLANG_NO_THROW void SLANG_MCALL addAssociated(ICastable* castable) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void* SLANG_MCALL findAssociated(const Guid& unk) SLANG_OVERRIDE; - virtual SLANG_NO_THROW ICastableList* SLANG_MCALL getAssociated() SLANG_OVERRIDE; - virtual SLANG_NO_THROW ICastable* SLANG_MCALL findAssociatedWithPredicate(ICastableList::FindFunc findFunc, void* data) SLANG_OVERRIDE; - + virtual SLANG_NO_THROW void SLANG_MCALL addAssociated(IArtifact* artifact) SLANG_OVERRIDE; + virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getAssociated() SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addRepresentation(ICastable* castable) SLANG_OVERRIDE; virtual SLANG_NO_THROW void SLANG_MCALL addRepresentationUnknown(ISlangUnknown* rep) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void* SLANG_MCALL findRepresentation(const Guid& guid) SLANG_OVERRIDE; virtual SLANG_NO_THROW Slice<ICastable*> SLANG_MCALL getRepresentations() SLANG_OVERRIDE; - virtual SLANG_NO_THROW ICastableList* SLANG_MCALL getRepresentationList() SLANG_OVERRIDE; - virtual SLANG_NO_THROW ICastable* SLANG_MCALL findRepresentationWithPredicate(ICastableList::FindFunc findFunc, void* data) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL getOrCreateRepresentation(const Guid& typeGuid, ArtifactKeep keep, ICastable** outCastable) SLANG_OVERRIDE; virtual SLANG_NO_THROW IArtifactHandler* SLANG_MCALL getHandler() SLANG_OVERRIDE; virtual SLANG_NO_THROW void SLANG_MCALL setHandler(IArtifactHandler* handler) SLANG_OVERRIDE; - virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getChildren() SLANG_OVERRIDE { return Slice<IArtifact*>(nullptr, 0); } - - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByDerivedDesc(FindStyle findStyle, const ArtifactDesc& desc) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByPredicate(FindStyle findStyle, FindFunc func, void* data) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByName(FindStyle findStyle, const char* name) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByDesc(FindStyle findStyle, const ArtifactDesc& desc) SLANG_OVERRIDE; + virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getChildren() SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getExpandChildrenResult() SLANG_OVERRIDE { return m_expandResult; } + virtual SLANG_NO_THROW void SLANG_MCALL setChildren(IArtifact*const* children, Count count) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL expandChildren() SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addChild(IArtifact* artifact) SLANG_OVERRIDE; - // IArtifactCollection (Not implemented) - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getExpandChildrenResult() SLANG_OVERRIDE { SLANG_UNREACHABLE("Not implemented"); } - virtual SLANG_NO_THROW void SLANG_MCALL setChildren(IArtifact** children, Count count) SLANG_OVERRIDE { SLANG_UNUSED(children); SLANG_UNUSED(count); SLANG_UNREACHABLE("Not implemented"); } - virtual SLANG_NO_THROW SlangResult SLANG_MCALL expandChildren() SLANG_OVERRIDE { SLANG_UNREACHABLE("Not implemented"); } - virtual SLANG_NO_THROW void SLANG_MCALL addChild(IArtifact* artifact) SLANG_OVERRIDE { SLANG_UNUSED(artifact); SLANG_UNREACHABLE("Not implemented"); } - virtual SLANG_NO_THROW void SLANG_MCALL removeChildAt(Index index) SLANG_OVERRIDE { SLANG_UNUSED(index); SLANG_UNREACHABLE("Not implemented"); } - virtual SLANG_NO_THROW void SLANG_MCALL clearChildren() SLANG_OVERRIDE { SLANG_UNREACHABLE("Not implemented"); } + virtual SLANG_NO_THROW void* SLANG_MCALL findRepresentation(ContainedKind kind, const Guid& unk) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL clear(ContainedKind kind) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL removeAt(ContainedKind kind, Index i) SLANG_OVERRIDE; static ComPtr<IArtifact> create(const Desc& desc) { return ComPtr<IArtifact>(new Artifact(desc)); } static ComPtr<IArtifact> create(const Desc& desc, const UnownedStringSlice& name) { return ComPtr<IArtifact>(new Artifact(desc, name)); } @@ -88,77 +73,27 @@ protected: /// Ctor Artifact(const Desc& desc, const UnownedStringSlice& name) : m_desc(desc), - m_name(name), - m_parent(nullptr) + m_name(name) {} Artifact(const Desc& desc) : - m_desc(desc), - m_parent(nullptr) + m_desc(desc) {} IArtifactHandler* _getHandler(); + void _requireChildren(); void* getInterface(const Guid& uuid); void* getObject(const Guid& uuid); Desc m_desc; ///< Description of the artifact - IArtifact* m_parent; ///< Artifact this artifact belongs to - String m_name; ///< Name of this artifact - - ComPtr<IArtifactHandler> m_handler; ///< The handler. Can be nullptr and then default handler is used. - - LazyCastableList m_associated; ///< Associated items - LazyCastableList m_representations; ///< Representations -}; - -class ArtifactContainer : public Artifact -{ -public: - typedef Artifact Super; - SLANG_COM_BASE_IUNKNOWN_QUERY_INTERFACE - - /// ICastable - virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE; - - /// IArtifact - virtual SLANG_NO_THROW Slice<IArtifact*> SLANG_MCALL getChildren() SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByDerivedDesc(FindStyle findStyle, const ArtifactDesc& desc) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByPredicate(FindStyle findStyle, FindFunc func, void* data) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByName(FindStyle findStyle, const char* name) SLANG_OVERRIDE; - virtual SLANG_NO_THROW IArtifact* SLANG_MCALL findArtifactByDesc(FindStyle findStyle, const ArtifactDesc& desc) SLANG_OVERRIDE; - - // IArtifactCollection - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getExpandChildrenResult() SLANG_OVERRIDE { return m_expandResult; } - virtual SLANG_NO_THROW void SLANG_MCALL setChildren(IArtifact** children, Count count) SLANG_OVERRIDE; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL expandChildren() SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL addChild(IArtifact* artifact) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL removeChildAt(Index index) SLANG_OVERRIDE; - virtual SLANG_NO_THROW void SLANG_MCALL clearChildren() SLANG_OVERRIDE; - - static ComPtr<IArtifactContainer> create(const Desc& desc) { return ComPtr<IArtifactContainer>(new ArtifactContainer(desc)); } - static ComPtr<IArtifactContainer> create(const Desc& desc, const UnownedStringSlice& name) { return ComPtr<IArtifactContainer>(new ArtifactContainer(desc, name)); } - -protected: - /// Ctor - ArtifactContainer(const Desc& desc, const UnownedStringSlice& name) :Super(desc, name) {} - ArtifactContainer(const Desc& desc) : Super(desc) {} - - void* getInterface(const Guid& uuid); - void* getObject(const Guid& uuid); - void _requireChildren() - { - if (m_expandResult == SLANG_E_UNINITIALIZED) - { - const auto res = expandChildren(); - SLANG_UNUSED(res); - SLANG_ASSERT(SLANG_SUCCEEDED(res)); - } - } - SlangResult m_expandResult = SLANG_E_UNINITIALIZED; - List<ComPtr<IArtifact>> m_children; + ComPtr<IArtifactHandler> m_handler; ///< The handler. Can be nullptr and then default handler is used. + + List<ComPtr<ICastable>> m_representations; ///< All the representation of this artifact + List<ComPtr<IArtifact>> m_associated; ///< All the items associated with this artifact + List<ComPtr<IArtifact>> m_children; ///< All the child artifacts owned }; } // namespace Slang |
