Allow named record constructors. Addresses #983.

This commit is contained in:
Jon Siwek 2013-05-29 12:48:15 -05:00
parent d67123d0c3
commit a0ad87b4c2
6 changed files with 105 additions and 7 deletions

View file

@ -522,10 +522,39 @@ expr:
$$ = new VectorConstructorExpr($3);
}
| expr '(' opt_expr_list ')'
| expr '('
{
set_location(@1, @4);
$$ = new CallExpr($1, $3, in_hook > 0);
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
++in_init;
}
opt_expr_list
{
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
--in_init;
}
')'
{
set_location(@1, @6);
BroType* ctor_type = 0;
if ( $1->Tag() == EXPR_NAME &&
(ctor_type = $1->AsNameExpr()->Id()->AsType()) )
{
switch ( ctor_type->Tag() ) {
case TYPE_RECORD:
$$ = new RecordConstructorExpr($4, ctor_type);
break;
case TYPE_TABLE:
case TYPE_VECTOR:
default:
$1->Error("constructor type not implemented");
YYERROR;
}
}
else
$$ = new CallExpr($1, $4, in_hook > 0);
}
| TOK_HOOK { ++in_hook; } expr