From 0f55649cc1aa8ad3218b7f8ba7b1eabdd2ec6526 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 8 Dec 2017 14:23:12 -0800 Subject: Cleanups to `ParameterBlock` behavior. (#304) * Cleanups to `ParameterBlock` behavior. These add some more realistic tests using the `ParameterBlock` support, and show that it can work with the "rewriter" mode. Unfortunately, this code does *not* currently work with the rewriter + the IR at once. That will need to be fixed in a follow-on change, because I now see that the root problem is pretty ugly. * cleanup --- source/slang/check.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source/slang/check.cpp') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index c1893423a..4840ae30d 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1005,6 +1005,40 @@ namespace Slang } } + + // Are we converting from a parameter group type to its element type? + if(auto fromParameterGroupType = fromType->As()) + { + auto fromElementType = fromParameterGroupType->getElementType(); + + // If we have, e.g., `ConstantBuffer` and we want to convert + // to `B`, where conversion from `A` to `B` is possible, then + // we will do so here. + + ConversionCost subCost = 0; + if(CanCoerce(toType, fromElementType, &subCost)) + { + if(outCost) + *outCost = subCost + kConversionCost_ImplicitDereference; + + if(outToExpr) + { + auto derefExpr = new DerefExpr(); + derefExpr->base = fromExpr; + derefExpr->type = QualType(fromElementType); + + return TryCoerceImpl( + toType, + outToExpr, + fromElementType, + derefExpr, + nullptr); + } + return true; + } + } + + // Look for an initializer/constructor declaration in the target type, // which is marked as usable for implicit conversion, and which takes // the source type as an argument. @@ -1171,6 +1205,7 @@ namespace Slang RefPtr castExpr = createImplicitCastExpr(); auto typeType = new TypeType(); + typeType->setSession(getSession()); typeType->type = toType; auto typeExpr = new SharedTypeExpr(); -- cgit v1.2.3