Skip to content

Commit

Permalink
compiler: add Stmt.isOnceFieldInit
Browse files Browse the repository at this point in the history
  • Loading branch information
briansfrank committed Jul 12, 2024
1 parent 339cc83 commit 9b62739
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/compiler/fan/ast/Stmt.fan
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ abstract class Stmt : Node
**
abstract Bool isDefiniteAssign(|Expr lhs->Bool| f)

**
** Is this statement a field initialization for a once storage field.
** This is used in compilerEs to skip initializing fields to "_once_"
**
virtual Bool isOnceFieldInit() { false }

//////////////////////////////////////////////////////////////////////////
// Tree
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -112,6 +118,14 @@ class ExprStmt : Stmt

override Bool isDefiniteAssign(|Expr lhs->Bool| f) { expr.isDefiniteAssign(f) }

override Bool isOnceFieldInit()
{
if (expr.id !== ExprId.assign) return false
x := ((BinaryExpr)expr).lhs as FieldExpr
if (x === null) return false
return x.field.isOnce
}

override Void walkChildren(Visitor v, VisitDepth depth)
{
expr = walkExpr(v, depth, expr)
Expand Down Expand Up @@ -657,4 +671,5 @@ enum class StmtId
continueStmt,
tryStmt,
switchStmt
}
}

0 comments on commit 9b62739

Please sign in to comment.