summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-expr.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-10 10:57:04 -0800
committerGitHub <noreply@github.com>2025-01-10 10:57:04 -0800
commit5290c580632cfb56847b863a32dc020a21d1c93e (patch)
tree4c543f28d13f62a1dc3293b76151dda7585743ab /source/slang/slang-check-expr.cpp
parent4cfae806a6f9c0203ce44c4ce04df5ad66cdc8a2 (diff)
Initial implementation of SP#015 `DescriptorHandle<T>`. (#6028)
* Initial implementation of `ResourcePtr<T>`. * Update docs * Fix build error. * Add more discussion. * Update documentation. * Update TOC. * Fix. * Fix. * Add test case for custom `getResourceFromBindlessHandle`. * Add namehint to generated descriptor heap param. * Fix. * Fix. * format code * Rename to `DescriptorHandle`, and add `T.Handle` alias. * Fix compiler error. * Fix. * Fix build. * Renames. * Fix documentation. * Documentation fix. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
-rw-r--r--source/slang/slang-check-expr.cpp73
1 files changed, 33 insertions, 40 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 95d5a2a7c..ce6206973 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -511,24 +511,41 @@ DeclRefExpr* SemanticsVisitor::ConstructDeclRefExpr(
}
}
-Expr* SemanticsVisitor::ConstructDerefExpr(Expr* base, SourceLoc loc)
+Expr* SemanticsVisitor::constructDerefExpr(Expr* base, QualType elementType, SourceLoc loc)
{
- auto elementType = getPointedToTypeIfCanImplicitDeref(base->type);
- SLANG_ASSERT(elementType);
+ if (auto resPtrType = as<DescriptorHandleType>(base->type))
+ {
+ return coerce(CoercionSite::ExplicitCoercion, resPtrType->getElementType(), base);
+ }
auto derefExpr = m_astBuilder->create<DerefExpr>();
derefExpr->loc = loc;
derefExpr->base = base;
derefExpr->type = QualType(elementType);
- if (as<PtrType>(base->type))
+ if (as<PtrType>(base->type) || as<RefType>(base->type))
+ {
derefExpr->type.isLeftValue = true;
+ }
else
+ {
+ derefExpr->type.isLeftValue = base->type.isLeftValue;
derefExpr->type.isLeftValue = base->type.isLeftValue;
+ derefExpr->type.hasReadOnlyOnTarget = base->type.hasReadOnlyOnTarget;
+ derefExpr->type.isWriteOnly = base->type.isWriteOnly;
+ }
return derefExpr;
}
+Expr* SemanticsVisitor::ConstructDerefExpr(Expr* base, SourceLoc loc)
+{
+ auto elementType = getPointedToTypeIfCanImplicitDeref(base->type);
+ SLANG_ASSERT(elementType);
+
+ return constructDerefExpr(base, elementType, loc);
+}
+
InvokeExpr* SemanticsVisitor::constructUncheckedInvokeExpr(
Expr* callee,
const List<Expr*>& arguments)
@@ -2301,8 +2318,7 @@ Expr* SemanticsVisitor::CheckSimpleSubscriptExpr(IndexExpr* subscriptExpr, Type*
auto indexExpr = subscriptExpr->indexExprs[0];
- if (!indexExpr->type->equals(m_astBuilder->getIntType()) &&
- !indexExpr->type->equals(m_astBuilder->getUIntType()))
+ if (!isScalarIntegerType(indexExpr->type.type))
{
getSink()->diagnose(indexExpr, Diagnostics::subscriptIndexNonInteger);
return CreateErrorExpr(subscriptExpr);
@@ -4084,43 +4100,16 @@ Expr* SemanticsVisitor::maybeDereference(Expr* inExpr, CheckBaseContext checkBas
for (;;)
{
auto baseType = expr->type;
- QualType elementType;
- if (auto pointerLikeType = as<PointerLikeType>(baseType))
- {
- elementType = QualType(pointerLikeType->getElementType());
- elementType.isLeftValue = baseType.isLeftValue;
- elementType.hasReadOnlyOnTarget = baseType.hasReadOnlyOnTarget;
- elementType.isWriteOnly = baseType.isWriteOnly;
- }
- else if (auto ptrType = as<PtrType>(baseType))
+ if (as<PtrType>(baseType))
{
if (checkBaseContext == CheckBaseContext::Subscript)
return expr;
- elementType = QualType(ptrType->getValueType());
- elementType.isLeftValue = true;
}
- else
- {
- auto newExpr = maybeOpenRef(expr);
- if (newExpr != expr)
- {
- expr = newExpr;
- continue;
- }
- }
- if (elementType.type)
- {
- auto derefExpr = m_astBuilder->create<DerefExpr>();
- derefExpr->base = expr;
- derefExpr->type = elementType;
-
- expr = derefExpr;
- continue;
- }
- break;
+ auto elementType = getPointedToTypeIfCanImplicitDeref(baseType);
+ if (!elementType)
+ return expr;
+ expr = constructDerefExpr(expr, elementType, inExpr->loc);
}
- // Default case: just use the expression as-is
- return expr;
}
Expr* SemanticsVisitor::CheckMatrixSwizzleExpr(
@@ -4740,8 +4729,12 @@ Expr* SemanticsVisitor::_lookupStaticMember(DeclRefExpr* expr, Expr* baseExpress
handleLeafCase(nsType->getDeclRef(), nsType);
else if (auto aggType = as<DeclRefType>(e->type))
handleLeafCase(aggType->getDeclRef(), aggType);
- else if (auto typetype = as<TypeType>(e->type))
- handleLeafCase(DeclRef<Decl>(), typetype->getType());
+ else if (as<TypeType>(e->type))
+ {
+ auto properType = CoerceToProperType(TypeExp(e));
+ if (properType.type)
+ handleLeafCase(DeclRef<Decl>(), properType.type);
+ }
};
auto& baseType = baseExpression->type;