mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Enabling automatic coercion from record type A to be B as long as A
has all the types that B has.
This commit is contained in:
parent
e00acaddd8
commit
af3267acc3
1 changed files with 16 additions and 9 deletions
25
src/Expr.cc
25
src/Expr.cc
|
@ -3994,15 +3994,8 @@ RecordCoerceExpr::RecordCoerceExpr(Expr* op, RecordType* r)
|
||||||
{
|
{
|
||||||
int t_i = t_r->FieldOffset(sub_r->FieldName(i));
|
int t_i = t_r->FieldOffset(sub_r->FieldName(i));
|
||||||
if ( t_i < 0 )
|
if ( t_i < 0 )
|
||||||
{
|
// Orphane field in rhs, that's ok.
|
||||||
// Same as in RecordConstructorExpr::InitVal.
|
|
||||||
char buf[512];
|
|
||||||
safe_snprintf(buf, sizeof(buf),
|
|
||||||
"orphan record field \"%s\"",
|
|
||||||
sub_r->FieldName(i));
|
|
||||||
Error(buf);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
BroType* sub_t_i = sub_r->FieldType(i);
|
BroType* sub_t_i = sub_r->FieldType(i);
|
||||||
BroType* sup_t_i = t_r->FieldType(t_i);
|
BroType* sup_t_i = t_r->FieldType(t_i);
|
||||||
|
@ -4047,7 +4040,21 @@ Val* RecordCoerceExpr::Fold(Val* v) const
|
||||||
for ( int i = 0; i < map_size; ++i )
|
for ( int i = 0; i < map_size; ++i )
|
||||||
{
|
{
|
||||||
if ( map[i] >= 0 )
|
if ( map[i] >= 0 )
|
||||||
val->Assign(i, rv->Lookup(map[i])->Ref());
|
{
|
||||||
|
Val* rhs = rv->Lookup(map[i]);
|
||||||
|
if ( ! rhs )
|
||||||
|
{
|
||||||
|
const Attr* def = rv->Type()->AsRecordType()->FieldDecl(map[i])->FindAttr(ATTR_DEFAULT);
|
||||||
|
if ( def )
|
||||||
|
rhs = def->AttrExpr()->Eval(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( rhs )
|
||||||
|
rhs = rhs->Ref();
|
||||||
|
|
||||||
|
assert(rhs || Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL));
|
||||||
|
val->Assign(i, rhs);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
val->Assign(i, 0);
|
val->Assign(i, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue