Allow local table variables to be initialized with {} list expressions.

This commit is contained in:
Jon Siwek 2012-01-04 16:44:25 -06:00
parent f8ec98625d
commit aae60a6d76
5 changed files with 50 additions and 6 deletions

View file

@ -2435,7 +2435,7 @@ bool RefExpr::DoUnserialize(UnserialInfo* info)
}
AssignExpr::AssignExpr(Expr* arg_op1, Expr* arg_op2, int arg_is_init,
Val* arg_val)
Val* arg_val, attr_list* arg_attrs)
: BinaryExpr(EXPR_ASSIGN,
arg_is_init ? arg_op1 : arg_op1->MakeLvalue(), arg_op2)
{
@ -2455,14 +2455,14 @@ AssignExpr::AssignExpr(Expr* arg_op1, Expr* arg_op2, int arg_is_init,
// We discard the status from TypeCheck since it has already
// generated error messages.
(void) TypeCheck();
(void) TypeCheck(arg_attrs);
val = arg_val ? arg_val->Ref() : 0;
SetLocationInfo(arg_op1->GetLocationInfo(), arg_op2->GetLocationInfo());
}
bool AssignExpr::TypeCheck()
bool AssignExpr::TypeCheck(attr_list* attrs)
{
TypeTag bt1 = op1->Type()->Tag();
TypeTag bt2 = op2->Type()->Tag();
@ -2494,6 +2494,19 @@ bool AssignExpr::TypeCheck()
return true;
}
if ( bt1 == TYPE_TABLE && op2->Tag() == EXPR_LIST )
{
attr_list* attr_copy = 0;
if ( attrs )
{
attr_copy = new attr_list;
loop_over_list(*attrs, i)
attr_copy->append((*attrs)[i]);
}
op2 = new TableConstructorExpr(op2->AsListExpr(), attr_copy);
return true;
}
if ( bt1 == TYPE_VECTOR && bt2 == bt1 &&
op2->Type()->AsVectorType()->IsUnspecifiedVector() )
{