Fix parsing of "local" named table constructors.

This commit is contained in:
Jon Siwek 2014-03-20 16:47:20 -05:00
parent b1fd161274
commit bf3c3887fd
3 changed files with 33 additions and 7 deletions

View file

@ -207,6 +207,22 @@ static void extend_record(ID* id, type_decl_list* fields, attr_list* attrs)
}
}
}
static bool expr_is_table_type_name(const Expr* expr)
{
if ( expr->Tag() != EXPR_NAME )
return false;
BroType* type = expr->Type();
if ( type->IsTable() )
return true;
if ( type->Tag() == TYPE_TYPE )
return type->AsTypeType()->Type()->IsTable();
return false;
}
%}
%union {
@ -538,13 +554,13 @@ expr:
| expr '('
{
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
if ( expr_is_table_type_name($1) )
++in_init;
}
opt_expr_list
{
if ( $1->Tag() == EXPR_NAME && $1->Type()->IsTable() )
if ( expr_is_table_type_name($1) )
--in_init;
}

View file

@ -17,3 +17,7 @@
[three] = 3.0
}
0
{
[42] = forty-two,
[37] = thirty-seven
}

View file

@ -17,8 +17,14 @@ global mytablecomp: FooTableComp = FooTableComp(["test", 1] = "test1", ["cool",
2] = "cool2");
global mytabley: FooTableY = FooTableY(["one"] = 1, ["two"] = 2, ["three"] = 3) &default=0;
print mytable;
print mytablerec;
print mytablecomp;
print mytabley;
print mytabley["test"];
event bro_init()
{
print mytable;
print mytablerec;
print mytablecomp;
print mytabley;
print mytabley["test"];
local loctable = FooTable([42] = "forty-two", [37] = "thirty-seven");
print loctable;
}