summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
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;
+ }
+
}