Allow record_fields() string arguments that name a record type

This commit is contained in:
Jon Siwek 2019-11-01 12:46:17 -07:00
parent 295c28b48e
commit 63fe835acf
7 changed files with 92 additions and 35 deletions

View file

@ -824,6 +824,43 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const
d->PopType(this);
}
TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
{
auto rval = new TableVal(internal_type("record_field_table")->AsTableType());
for ( int i = 0; i < NumFields(); ++i )
{
const BroType* ft = FieldType(i);
const TypeDecl* fd = FieldDecl(i);
Val* fv = nullptr;
if ( rv )
fv = rv->Lookup(i);
if ( fv )
::Ref(fv);
bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != 0);
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())));
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);
}
return rval;
}
const char* RecordType::AddFields(type_decl_list* others, attr_list* attr)
{
assert(types);