mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Recursively handle into container types in record_fields()
This commit is contained in:
parent
bb8d6bca67
commit
a645e38b78
3 changed files with 42 additions and 38 deletions
68
src/Type.cc
68
src/Type.cc
|
@ -824,6 +824,39 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const
|
||||||
d->PopType(this);
|
d->PopType(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string container_type_name(const BroType* ft)
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
if ( ft->Tag() == TYPE_RECORD )
|
||||||
|
s = "record " + ft->GetName();
|
||||||
|
else if ( ft->Tag() == TYPE_VECTOR )
|
||||||
|
s = "vector of " + container_type_name(ft->YieldType());
|
||||||
|
else if ( ft->Tag() == TYPE_TABLE )
|
||||||
|
{
|
||||||
|
if ( ft->IsSet() )
|
||||||
|
s = "set[";
|
||||||
|
else
|
||||||
|
s = "table[";
|
||||||
|
const type_list* tl = ((const IndexType*) ft)->IndexTypes();
|
||||||
|
loop_over_list(*tl, i)
|
||||||
|
{
|
||||||
|
if ( i > 0 )
|
||||||
|
s += ",";
|
||||||
|
s += container_type_name((*tl)[i]);
|
||||||
|
}
|
||||||
|
s += "]";
|
||||||
|
if ( ft->YieldType() )
|
||||||
|
{
|
||||||
|
s += " of ";
|
||||||
|
s += container_type_name(ft->YieldType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s = type_name(ft->Tag());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
|
TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
|
||||||
{
|
{
|
||||||
auto rval = new TableVal(internal_type("record_field_table")->AsTableType());
|
auto rval = new TableVal(internal_type("record_field_table")->AsTableType());
|
||||||
|
@ -844,42 +877,11 @@ TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
|
||||||
|
|
||||||
RecordVal* nr = new RecordVal(internal_type("record_field")->AsRecordType());
|
RecordVal* nr = new RecordVal(internal_type("record_field")->AsRecordType());
|
||||||
|
|
||||||
if ( ft->Tag() == TYPE_RECORD )
|
string s = container_type_name(ft);
|
||||||
nr->Assign(0, new StringVal("record " + ft->GetName()));
|
nr->Assign(0, new StringVal(s));
|
||||||
else if ( ft->Tag() == TYPE_VECTOR )
|
|
||||||
{
|
|
||||||
string s = fmt("vector of %s", ft->YieldType()->Tag());
|
|
||||||
nr->Assign(0, new StringVal(s));
|
|
||||||
}
|
|
||||||
else if ( ft->Tag() == TYPE_TABLE )
|
|
||||||
{
|
|
||||||
string s;
|
|
||||||
if ( ft->IsSet() )
|
|
||||||
s = "set[";
|
|
||||||
else
|
|
||||||
s = "table[";
|
|
||||||
const type_list* tl = ((const IndexType*) ft)->IndexTypes();
|
|
||||||
loop_over_list(*tl, i)
|
|
||||||
{
|
|
||||||
if ( i > 0 )
|
|
||||||
s += ",";
|
|
||||||
s += type_name((*tl)[i]->Tag());
|
|
||||||
}
|
|
||||||
s += "]";
|
|
||||||
if ( ft->YieldType() )
|
|
||||||
{
|
|
||||||
s += " of ";
|
|
||||||
s += type_name(ft->YieldType()->Tag());
|
|
||||||
}
|
|
||||||
nr->Assign(0, new StringVal(s));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
nr->Assign(0, new StringVal(type_name(ft->Tag())));
|
|
||||||
|
|
||||||
nr->Assign(1, val_mgr->GetBool(logged));
|
nr->Assign(1, val_mgr->GetBool(logged));
|
||||||
nr->Assign(2, fv);
|
nr->Assign(2, fv);
|
||||||
nr->Assign(3, FieldDefault(i));
|
nr->Assign(3, FieldDefault(i));
|
||||||
|
|
||||||
Val* field_name = new StringVal(FieldName(i));
|
Val* field_name = new StringVal(FieldName(i));
|
||||||
rval->Assign(field_name, nr);
|
rval->Assign(field_name, nr);
|
||||||
Unref(field_name);
|
Unref(field_name);
|
||||||
|
|
|
@ -49,8 +49,9 @@ F
|
||||||
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>]
|
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>]
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
|
||||||
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[c] = [type_name=table[double,string] of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[c] = [type_name=set[double,record r], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[d] = [type_name=vector[string], log=F, value=<uninitialized>, default_val=<uninitialized>]
|
[e] = [type_name=vector of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
|
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
|
[d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>]
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ type mystring: string;
|
||||||
type cr: record {
|
type cr: record {
|
||||||
a: set[double];
|
a: set[double];
|
||||||
b: set[double, string];
|
b: set[double, string];
|
||||||
c: table[double, string] of string;
|
c: set[double, r];
|
||||||
d: vector of string;
|
d: table[double, string] of table[string] of vector of string;
|
||||||
|
e: vector of vector of string;
|
||||||
};
|
};
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue