Let fields have default values.

This commit is contained in:
Nigel Tao committed 2017-05-28 13:47:29 +10:00
1 parent e66f1cb236
commit 99ff8e2487
8 files changed
+76 -17

No files matched your search

+8 -5
View File
@@ -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(),
}
}