New BiF record_field_vals() that returns the fields of a record in a

table with meta-information.

Example:

type r: record {
	a: count;
	b: string &default="Foo";
	c: double &optional;
	d: string &log;
};

event bro_init()
{
    local x: r = [$a=42, $d="Bar"];
    print record_fields(x);
}

This prints:

  {
  [a] = [type_name=record, log=F, value=42, default_val=<uninitialized>]
  [b] = [type_name=record, log=F, value=<uninitialized>, default_val=Foo],
  [c] = [type_name=record, log=F, value=<uninitialized>, default_val=<uninitialized>],
  [d] = [type_name=record, log=T, value=Bar, default_val=<uninitialized>],
  }

This is one more step in Seth's quest for full inspection support. :-)
This commit is contained in:
Robin Sommer 2011-07-07 18:41:50 -07:00
parent cdd8827cc4
commit 8bacb6eb3d
9 changed files with 99 additions and 9 deletions

View file

@ -987,6 +987,18 @@ BroType* RecordType::FieldType(int field) const
}
}
Val* RecordType::FieldDefault(int field) const
{
const TypeDecl* td = FieldDecl(field);
if ( ! td->attrs )
return false;
const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT);
return def_attr ? def_attr->AttrExpr()->Eval(0) : 0;
}
int RecordType::FieldOffset(const char* field) const
{
if ( types )