diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-03 12:08:37 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-03 12:08:37 -0700 |
| commit | e81a5fe56f3177fc3c7040e2320ae083e3746eb7 (patch) | |
| tree | 884c15287bc10050e7883897dd266b27e62bff66 /source/slang/slang-check-expr.cpp | |
| parent | 260fc5fbe58f2cf976d64993054c638769bc280f (diff) | |
Basic pointer usages. (#2342)
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 1895da70b..addd3a5c4 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -231,6 +231,21 @@ namespace Slang return expr; } + Expr* SemanticsVisitor::maybeOpenRef(Expr* expr) + { + auto exprType = expr->type.type; + + if (auto refType = as<RefType>(exprType)) + { + auto openRef = m_astBuilder->create<OpenRefExpr>(); + openRef->innerExpr = expr; + openRef->type.isLeftValue = true; + openRef->type.type = refType->getValueType(); + return openRef; + } + return expr; + } + static SourceLoc _getMemberOpLoc(Expr* expr) { if (auto m = as<MemberExpr>(expr)) @@ -1329,8 +1344,8 @@ namespace Slang Expr* SemanticsVisitor::checkAssignWithCheckedOperands(AssignExpr* expr) { auto type = expr->left->type; - - expr->right = coerce(type, expr->right); + auto right = maybeOpenRef(expr->right); + expr->right = coerce(type, right); if (!type.isLeftValue) { @@ -2514,6 +2529,16 @@ namespace Slang return expr; } + Expr* SemanticsExprVisitor::visitPointerTypeExpr(PointerTypeExpr* expr) + { + expr->base = CheckProperType(expr->base); + if (as<ErrorType>(expr->base.type)) + expr->type = expr->base.type; + auto ptrType = m_astBuilder->getPtrType(expr->base.type); + expr->type = m_astBuilder->getTypeType(ptrType); + return expr; + } + Expr* SemanticsExprVisitor::visitModifiedTypeExpr(ModifiedTypeExpr* expr) { // The base type should be a proper type (not an expression, generic, etc.) |
