summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 3072ef0a7..aa114e44d 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1348,6 +1348,43 @@ SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL Linkage::specializeType(
return asExternal(specializedType);
}
+
+DeclRef<Decl> Linkage::specializeGeneric(
+ DeclRef<Decl> declRef,
+ List<Expr*> argExprs,
+ DiagnosticSink* sink)
+{
+ SLANG_AST_BUILDER_RAII(getASTBuilder());
+ SLANG_ASSERT(declRef);
+
+ SharedSemanticsContext sharedSemanticsContext(this, nullptr, sink);
+ SemanticsVisitor visitor(&sharedSemanticsContext);
+
+ // Create substituted parent decl ref.
+ auto decl = declRef.getDecl();
+
+ while (!as<GenericDecl>(decl))
+ {
+ decl = decl->parentDecl;
+ }
+
+ auto genericDecl = as<GenericDecl>(decl);
+ auto genericDeclRef = createDefaultSubstitutionsIfNeeded(getASTBuilder(), &visitor, DeclRef(genericDecl)).as<GenericDecl>();
+ genericDeclRef = substituteDeclRef(SubstitutionSet(declRef), getASTBuilder(), genericDeclRef).as<GenericDecl>();
+
+
+ DeclRefExpr* declRefExpr = getASTBuilder()->create<DeclRefExpr>();
+ declRefExpr->declRef = genericDeclRef;
+
+ GenericAppExpr* genericAppExpr = getASTBuilder()->create<GenericAppExpr>();
+ genericAppExpr->functionExpr = declRefExpr;
+ genericAppExpr->arguments = argExprs;
+
+ auto specializedDeclRef = as<DeclRefExpr>(visitor.checkGenericAppWithCheckedArgs(genericAppExpr))->declRef;
+
+ return specializedDeclRef;
+}
+
SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL Linkage::getTypeLayout(
slang::TypeReflection* inType,
SlangInt targetIndex,
@@ -2373,9 +2410,28 @@ DeclRef<Decl> ComponentType::findDeclFromStringInType(
result = declRefExpr->declRef;
}
+ if (auto genericDeclRef = result.as<GenericDecl>())
+ {
+ result = createDefaultSubstitutionsIfNeeded(
+ astBuilder, &visitor, DeclRef(genericDeclRef.getDecl()->inner));
+ result = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, result);
+ }
+
return result;
}
+bool ComponentType::isSubType(Type* subType, Type* superType)
+{
+ SharedSemanticsContext sharedSemanticsContext(
+ getLinkage(),
+ nullptr,
+ nullptr);
+ SemanticsContext context(&sharedSemanticsContext);
+ SemanticsVisitor visitor(context);
+
+ return (visitor.isSubtype(subType, superType, IsSubTypeOptions::None) != nullptr);
+}
+
static void collectExportedConstantInContainer(
Dictionary<String, IntVal*>& dict,
ASTBuilder* builder,
@@ -6805,4 +6861,4 @@ SlangResult EndToEndCompileRequest::isParameterLocationUsed(Int entryPointIndex,
return SLANG_OK;
}
-} // namespace Slang
+} // namespace Slang \ No newline at end of file