summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-05-05 10:48:14 -0700
committerGitHub <noreply@github.com>2022-05-05 10:48:14 -0700
commit3088d901fee6447b6d80fa67f258626ece4408dc (patch)
tree95b7d6bcc4b549e58d705fcf0056dde71a52ae8e /source/slang/slang-check-decl.cpp
parentaa03cea0da38b2950e6f8694dc8b1405352eda66 (diff)
Various vulkan/glsl fixes. (#2222)
* Various vulkan/glsl fixes. * Fix. * Fix. * Canonicalize type constraints for name mangling. Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 8db157a37..3c654a48b 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -12,6 +12,8 @@
#include "slang-lookup.h"
+#include "slang-syntax.h"
+
namespace Slang
{
/// Visitor to transition declarations to `DeclCheckState::CheckedModifiers`
@@ -5342,4 +5344,49 @@ namespace Slang
}
}
+ static void _getCanonicalConstraintTypes(List<Type*>& outTypeList, Type* type)
+ {
+ if (auto andType = as<AndType>(type))
+ {
+ _getCanonicalConstraintTypes(outTypeList, andType->left);
+ _getCanonicalConstraintTypes(outTypeList, andType->right);
+ }
+ else
+ {
+ outTypeList.add(type);
+ }
+ }
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> getCanonicalGenericConstraints(
+ DeclRef<ContainerDecl> genericDecl)
+ {
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> genericConstraints;
+ for (auto mm : getMembersOfType<GenericTypeParamDecl>(genericDecl))
+ {
+ genericConstraints[mm.getDecl()] = List<Type*>();
+ }
+ for (auto genericTypeConstraintDecl : getMembersOfType<GenericTypeConstraintDecl>(genericDecl))
+ {
+ assert(
+ genericTypeConstraintDecl.getDecl()->sub.type->astNodeType ==
+ ASTNodeType::DeclRefType);
+ auto typeParamDecl = as<DeclRefType>(genericTypeConstraintDecl.getDecl()->sub.type)->declRef.getDecl();
+ List<Type*>* constraintTypes = genericConstraints.TryGetValue(typeParamDecl);
+ assert(constraintTypes);
+ constraintTypes->add(genericTypeConstraintDecl.getDecl()->getSup().type);
+ }
+
+ OrderedDictionary<GenericTypeParamDecl*, List<Type*>> result;
+ for (auto& constraints : genericConstraints)
+ {
+ List<Type*> typeList;
+ for (auto type : constraints.Value)
+ {
+ _getCanonicalConstraintTypes(typeList, type);
+ }
+ // TODO: we also need to sort the types within the list for each generic type param.
+ result[constraints.Key] = typeList;
+ }
+ return result;
+ }
+
}