mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Implementing += operator for record types.
This is per #375. Record types can now get additional fields later via '+='. The added fields must however either be &optional or have a &default value. Example: type Foo: record { a: count; b: count &optional; }; redef record Foo += { c: count &default=42; d: count &optional; }; global f: Foo = [$a=21]; print f; Output: [a=21, b=<uninitialized>, c=42, d=<uninitialized>]
This commit is contained in:
parent
cdb20e61b7
commit
95069f0993
3 changed files with 44 additions and 2 deletions
20
src/Type.cc
20
src/Type.cc
|
@ -898,6 +898,26 @@ void RecordType::Describe(ODesc* d) const
|
|||
}
|
||||
}
|
||||
|
||||
const char* RecordType::AddFields(type_decl_list* others)
|
||||
{
|
||||
assert(types);
|
||||
|
||||
loop_over_list(*others, i)
|
||||
{
|
||||
TypeDecl* td = (*others)[i];
|
||||
|
||||
if ( ! td->FindAttr(ATTR_DEFAULT) && ! td->FindAttr(ATTR_OPTIONAL) )
|
||||
return "extension field must be &optional or have &default";
|
||||
|
||||
types->append(td);
|
||||
}
|
||||
|
||||
delete others;
|
||||
|
||||
num_fields = types->length();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RecordType::DescribeFields(ODesc* d) const
|
||||
{
|
||||
if ( d->IsReadable() )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue