mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Let fields have default values.
This commit is contained in:
1 parent
e66f1cb236
commit
99ff8e2487
8 files changed
+76
-17
No files matched your search
+8
-5
@@ -299,20 +299,23 @@ func NewVar(name t.ID, xType *TypeExpr, value *Expr) *Var {
|
||||
}
|
||||
}
|
||||
|
||||
// Field is a "name type" struct field:
|
||||
// Field is a "name type = default_value" struct field:
|
||||
// - ID1: name
|
||||
// - LHS: <TypeExpr>
|
||||
// - RHS: <nil|Expr>
|
||||
type Field Node
|
||||
|
||||
func (n *Field) Node() *Node { return (*Node)(n) }
|
||||
func (n *Field) Name() t.ID { return n.id1 }
|
||||
func (n *Field) XType() *TypeExpr { return n.lhs.TypeExpr() }
|
||||
func (n *Field) Node() *Node { return (*Node)(n) }
|
||||
func (n *Field) Name() t.ID { return n.id1 }
|
||||
func (n *Field) XType() *TypeExpr { return n.lhs.TypeExpr() }
|
||||
func (n *Field) DefaultValue() *Expr { return n.rhs.Expr() }
|
||||
|
||||
func NewField(name t.ID, xType *TypeExpr) *Field {
|
||||
func NewField(name t.ID, xType *TypeExpr, defaultValue *Expr) *Field {
|
||||
return &Field{
|
||||
kind: KField,
|
||||
id1: name,
|
||||
lhs: xType.Node(),
|
||||
rhs: defaultValue.Node(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user