diff options
| author | Yong He <yonghe@outlook.com> | 2022-10-26 08:32:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-26 08:32:24 -0700 |
| commit | 939be44ca23476e622dfb24a592383fe2a1da61f (patch) | |
| tree | 7f45645897fe5735d58a7687290552d479e4d6fc /source/slang/slang-ast-decl.cpp | |
| parent | 4fc34b18da2f83ee6b4f094067503a66cab3d0b5 (diff) | |
Auto synthesis of Differential type (#2466)
Diffstat (limited to 'source/slang/slang-ast-decl.cpp')
| -rw-r--r-- | source/slang/slang-ast-decl.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/slang/slang-ast-decl.cpp b/source/slang/slang-ast-decl.cpp index 2df9164fb..b2802e304 100644 --- a/source/slang/slang-ast-decl.cpp +++ b/source/slang/slang-ast-decl.cpp @@ -1,5 +1,6 @@ // slang-ast-decl.cpp #include "slang-ast-builder.h" +#include "slang-syntax.h" #include <assert.h> #include "slang-generated-ast-macro.h" @@ -32,4 +33,60 @@ bool isInterfaceRequirement(Decl* decl) return false; } +void ContainerDecl::buildMemberDictionary() +{ + // Don't rebuild if already built + if (isMemberDictionaryValid()) + return; + + // If it's < 0 it means that the dictionaries are entirely invalid + if (dictionaryLastCount < 0) + { + dictionaryLastCount = 0; + memberDictionary.Clear(); + transparentMembers.clear(); + } + + // are we a generic? + GenericDecl* genericDecl = as<GenericDecl>(this); + + const Index membersCount = members.getCount(); + + SLANG_ASSERT(dictionaryLastCount >= 0 && dictionaryLastCount <= membersCount); + + for (Index i = dictionaryLastCount; i < membersCount; ++i) + { + Decl* m = members[i]; + + auto name = m->getName(); + + // Add any transparent members to a separate list for lookup + if (m->hasModifier<TransparentModifier>()) + { + TransparentMemberInfo info; + info.decl = m; + transparentMembers.add(info); + } + + // Ignore members with no name + if (!name) + continue; + + // Ignore the "inner" member of a generic declaration + if (genericDecl && m == genericDecl->inner) + continue; + + m->nextInContainerWithSameName = nullptr; + + Decl* next = nullptr; + if (memberDictionary.TryGetValue(name, next)) + m->nextInContainerWithSameName = next; + + memberDictionary[name] = m; + } + + dictionaryLastCount = membersCount; + SLANG_ASSERT(isMemberDictionaryValid()); +} + } // namespace Slang |
