mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fixes for more doc mode corner cases caused by type cloning.
"shallow" copying has to be done for any type that can contain record types in order to accommodate record redefs that add fields.
This commit is contained in:
parent
1199085b27
commit
d69c3edf21
3 changed files with 29 additions and 114 deletions
28
src/Var.cc
28
src/Var.cc
|
@ -242,15 +242,25 @@ 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 )
|
||||||
{
|
{
|
||||||
if ( t->Tag() == TYPE_RECORD )
|
switch ( t->Tag() ) {
|
||||||
{
|
// Only "shallow" copy types that may contain records because
|
||||||
// Only "shallow" copy record types because we want to be able
|
// we want to be able to see additions to the original record type's
|
||||||
// to see additions to the original type's list of fields
|
// list of fields
|
||||||
|
case TYPE_RECORD:
|
||||||
tnew = new RecordType(t->AsRecordType()->Types());
|
tnew = new RecordType(t->AsRecordType()->Types());
|
||||||
}
|
break;
|
||||||
|
case TYPE_TABLE:
|
||||||
else
|
tnew = new TableType(t->AsTableType()->Indices(),
|
||||||
{
|
t->AsTableType()->YieldType());
|
||||||
|
break;
|
||||||
|
case TYPE_VECTOR:
|
||||||
|
tnew = new VectorType(t->AsVectorType()->YieldType());
|
||||||
|
break;
|
||||||
|
case TYPE_FUNC:
|
||||||
|
tnew = new FuncType(t->AsFuncType()->Args(),
|
||||||
|
t->AsFuncType()->YieldType(),
|
||||||
|
t->AsFuncType()->IsEvent());
|
||||||
|
default:
|
||||||
SerializationFormat* form = new BinarySerializationFormat();
|
SerializationFormat* form = new BinarySerializationFormat();
|
||||||
form->StartWrite();
|
form->StartWrite();
|
||||||
CloneSerializer ss(form);
|
CloneSerializer ss(form);
|
||||||
|
@ -267,7 +277,7 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
|
||||||
tnew = t->Unserialize(&uinfo);
|
tnew = t->Unserialize(&uinfo);
|
||||||
|
|
||||||
delete [] data;
|
delete [] data;
|
||||||
}
|
}
|
||||||
|
|
||||||
tnew->SetTypeID(copy_string(id->Name()));
|
tnew->SetTypeID(copy_string(id->Name()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
.. Automatically generated. Do not edit.
|
|
||||||
|
|
||||||
autogen-reST-record-add.bro
|
|
||||||
===========================
|
|
||||||
|
|
||||||
:download:`Original Source File <autogen-reST-record-add.bro>`
|
|
||||||
|
|
||||||
Overview
|
|
||||||
--------
|
|
||||||
|
|
||||||
|
|
||||||
Summary
|
|
||||||
~~~~~~~
|
|
||||||
State Variables
|
|
||||||
###############
|
|
||||||
===================================== =
|
|
||||||
:bro:id:`a`: :bro:type:`my_record`
|
|
||||||
|
|
||||||
:bro:id:`b`: :bro:type:`super_record`
|
|
||||||
===================================== =
|
|
||||||
|
|
||||||
Types
|
|
||||||
#####
|
|
||||||
============================================ =
|
|
||||||
:bro:type:`my_record`: :bro:type:`record`
|
|
||||||
|
|
||||||
:bro:type:`super_record`: :bro:type:`record`
|
|
||||||
============================================ =
|
|
||||||
|
|
||||||
Functions
|
|
||||||
#########
|
|
||||||
===================================== =
|
|
||||||
:bro:id:`test_func`: :bro:type:`func`
|
|
||||||
===================================== =
|
|
||||||
|
|
||||||
Redefinitions
|
|
||||||
#############
|
|
||||||
========================================= =
|
|
||||||
:bro:type:`my_record`: :bro:type:`record`
|
|
||||||
========================================= =
|
|
||||||
|
|
||||||
Public Interface
|
|
||||||
----------------
|
|
||||||
State Variables
|
|
||||||
~~~~~~~~~~~~~~~
|
|
||||||
.. bro:id:: a
|
|
||||||
|
|
||||||
:Type: :bro:type:`my_record`
|
|
||||||
:Default:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
{
|
|
||||||
field1=<uninitialized>
|
|
||||||
field2=<uninitialized>
|
|
||||||
field3=<uninitialized>
|
|
||||||
}
|
|
||||||
|
|
||||||
.. bro:id:: b
|
|
||||||
|
|
||||||
:Type: :bro:type:`super_record`
|
|
||||||
:Default:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
{
|
|
||||||
rec=[field1=<uninitialized>, field2=<uninitialized>, field3=<uninitialized>]
|
|
||||||
}
|
|
||||||
|
|
||||||
Types
|
|
||||||
~~~~~
|
|
||||||
.. bro:type:: my_record
|
|
||||||
|
|
||||||
:Type: :bro:type:`record`
|
|
||||||
|
|
||||||
field1: :bro:type:`bool`
|
|
||||||
|
|
||||||
field2: :bro:type:`string`
|
|
||||||
|
|
||||||
.. bro:type:: super_record
|
|
||||||
|
|
||||||
:Type: :bro:type:`record`
|
|
||||||
|
|
||||||
rec: :bro:type:`my_record`
|
|
||||||
|
|
||||||
Functions
|
|
||||||
~~~~~~~~~
|
|
||||||
.. bro:id:: test_func
|
|
||||||
|
|
||||||
:Type: :bro:type:`function` () : :bro:type:`void`
|
|
||||||
|
|
||||||
Redefinitions
|
|
||||||
~~~~~~~~~~~~~
|
|
||||||
.. bro:type:: my_record
|
|
||||||
|
|
||||||
:Type: :bro:type:`record`
|
|
||||||
|
|
||||||
field3: :bro:type:`count` :bro:attr:`&optional`
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
# @TEST-EXEC: bro --doc-scripts %INPUT
|
# @TEST-EXEC: bro --doc-scripts %INPUT
|
||||||
# @TEST-EXEC: btest-diff autogen-reST-record-add.rst
|
|
||||||
|
|
||||||
# When in doc mode, bro will clone declared types (see add_type() in Var.cc)
|
# 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.
|
# 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
|
# 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
|
# 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
|
# a type that contains record types will correctly see field additions to
|
||||||
# additions to those contained-records.
|
# those contained-records.
|
||||||
|
|
||||||
type my_record: record {
|
type my_record: record {
|
||||||
field1: bool;
|
field1: bool;
|
||||||
|
@ -16,17 +15,22 @@ type my_record: record {
|
||||||
type super_record: record {
|
type super_record: record {
|
||||||
rec: my_record;
|
rec: my_record;
|
||||||
};
|
};
|
||||||
|
type my_table: table[count] of my_record;
|
||||||
|
type my_vector: vector of my_record;
|
||||||
|
|
||||||
redef record my_record += {
|
redef record my_record += {
|
||||||
field3: count &optional;
|
field3: count &optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
global a: my_record;
|
global a: my_record;
|
||||||
|
|
||||||
global b: super_record;
|
global b: super_record;
|
||||||
|
global c: my_table;
|
||||||
|
global d: my_vector;
|
||||||
|
|
||||||
function test_func()
|
function test_func()
|
||||||
{
|
{
|
||||||
a?$field3;
|
a?$field3;
|
||||||
b$rec?$field3;
|
b$rec?$field3;
|
||||||
}
|
c[0]$field3;
|
||||||
|
d[0]$field3;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue