Delete operator for record fields.

"delete x$y" now resets record field "x" back to its original state if
it is either &optional or has a &default. "delete" may not be used
with non-optional/default fields.
This commit is contained in:
Robin Sommer 2011-04-22 18:40:14 -07:00
parent 964060c32f
commit 46b1fd9850
9 changed files with 70 additions and 18 deletions

View file

@ -3113,9 +3113,14 @@ Expr* FieldExpr::Simplify(SimplifyType simp_type)
return this;
}
int FieldExpr::CanDel() const
{
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
}
void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
{
if ( IsError() || ! v )
if ( IsError() )
return;
if ( field < 0 )
@ -3130,6 +3135,11 @@ void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
}
}
void FieldExpr::Delete(Frame* f)
{
Assign(f, 0, OP_ASSIGN_IDX);
}
Val* FieldExpr::Fold(Val* v) const
{
Val* result = v->AsRecordVal()->Lookup(field);