mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Bro doc mode now only does a "shallow" copy of declared record types
This is necessary so that the cloned type will be able to see additions to the original type's list of fields
This commit is contained in:
parent
d919ebed58
commit
6d867cf999
3 changed files with 55 additions and 13 deletions
|
@ -456,6 +456,8 @@ public:
|
||||||
// Given an offset, returns the field's name.
|
// Given an offset, returns the field's name.
|
||||||
const char* FieldName(int field) const;
|
const char* FieldName(int field) const;
|
||||||
|
|
||||||
|
type_decl_list* Types() { return types; }
|
||||||
|
|
||||||
// Given an offset, returns the field's TypeDecl.
|
// Given an offset, returns the field's TypeDecl.
|
||||||
const TypeDecl* FieldDecl(int field) const;
|
const TypeDecl* FieldDecl(int field) const;
|
||||||
TypeDecl* FieldDecl(int field);
|
TypeDecl* FieldDecl(int field);
|
||||||
|
|
35
src/Var.cc
35
src/Var.cc
|
@ -242,22 +242,31 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
|
||||||
// t->GetTypeID() is true.
|
// t->GetTypeID() is true.
|
||||||
if ( generate_documentation )
|
if ( generate_documentation )
|
||||||
{
|
{
|
||||||
SerializationFormat* form = new BinarySerializationFormat();
|
if ( t->Tag() == TYPE_RECORD )
|
||||||
form->StartWrite();
|
{
|
||||||
CloneSerializer ss(form);
|
// Only "shallow" copy record types because we want to be able
|
||||||
SerialInfo sinfo(&ss);
|
// to see additions to the original type's list of fields
|
||||||
sinfo.cache = false;
|
tnew = new RecordType(t->AsRecordType()->Types());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SerializationFormat* form = new BinarySerializationFormat();
|
||||||
|
form->StartWrite();
|
||||||
|
CloneSerializer ss(form);
|
||||||
|
SerialInfo sinfo(&ss);
|
||||||
|
sinfo.cache = false;
|
||||||
|
|
||||||
t->Serialize(&sinfo);
|
t->Serialize(&sinfo);
|
||||||
char* data;
|
char* data;
|
||||||
uint32 len = form->EndWrite(&data);
|
uint32 len = form->EndWrite(&data);
|
||||||
form->StartRead(data, len);
|
form->StartRead(data, len);
|
||||||
|
|
||||||
UnserialInfo uinfo(&ss);
|
UnserialInfo uinfo(&ss);
|
||||||
uinfo.cache = false;
|
uinfo.cache = false;
|
||||||
tnew = t->Unserialize(&uinfo);
|
tnew = t->Unserialize(&uinfo);
|
||||||
|
|
||||||
delete [] data;
|
delete [] data;
|
||||||
|
}
|
||||||
|
|
||||||
tnew->SetTypeID(copy_string(id->Name()));
|
tnew->SetTypeID(copy_string(id->Name()));
|
||||||
}
|
}
|
||||||
|
|
31
testing/btest/doc/autogen-reST-record-add.bro
Normal file
31
testing/btest/doc/autogen-reST-record-add.bro
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# @TEST-EXEC: bro --doc-scripts %INPUT
|
||||||
|
|
||||||
|
# When in doc mode, bro will clone declared types (see add_type() in Var.cc)
|
||||||
|
# in order to keep track of the identifier name associated with the new type.
|
||||||
|
# This test makes sure that the cloning is done in a way that's compatible
|
||||||
|
# with adding fields to a record type -- we want to be sure that cloning
|
||||||
|
# a record that contains other record fields will correctly see field
|
||||||
|
# additions to those contained-records.
|
||||||
|
|
||||||
|
type my_record: record {
|
||||||
|
field1: bool;
|
||||||
|
field2: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type super_record: record {
|
||||||
|
rec: my_record;
|
||||||
|
};
|
||||||
|
|
||||||
|
redef record my_record += {
|
||||||
|
field3: count &optional;
|
||||||
|
};
|
||||||
|
|
||||||
|
global a: my_record;
|
||||||
|
|
||||||
|
global b: super_record;
|
||||||
|
|
||||||
|
function test_func()
|
||||||
|
{
|
||||||
|
a?$field3;
|
||||||
|
b$rec?$field3;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue