Merge branch 'improve-container-record-fields-bif' of https://github.com/henridf/zeek

- Minor whitespace adjustment in merge

* 'improve-container-record-fields-bif' of https://github.com/henridf/zeek:
  Recursively handle into container types in record_fields()
  tabify
  Apply suggestions from code review
  Print full container types in record_fields()
This commit is contained in:
Jon Siwek 2019-11-13 13:43:16 -08:00
commit ca48a1865d
5 changed files with 56 additions and 7 deletions

View file

@ -824,6 +824,38 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const
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
{
auto rval = new TableVal(internal_type("record_field_table")->AsTableType());
@ -844,15 +876,11 @@ TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
RecordVal* nr = new RecordVal(internal_type("record_field")->AsRecordType());
if ( ft->Tag() == TYPE_RECORD )
nr->Assign(0, new StringVal("record " + ft->GetName()));
else
nr->Assign(0, new StringVal(type_name(ft->Tag())));
string s = container_type_name(ft);
nr->Assign(0, new StringVal(s));
nr->Assign(1, val_mgr->GetBool(logged));
nr->Assign(2, fv);
nr->Assign(3, FieldDefault(i));
Val* field_name = new StringVal(FieldName(i));
rval->Assign(field_name, nr);
Unref(field_name);