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:
Jon Siwek 2011-05-17 15:03:40 -05:00
parent 1199085b27
commit d69c3edf21
3 changed files with 29 additions and 114 deletions

View file

@ -242,15 +242,25 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
// t->GetTypeID() is true.
if ( generate_documentation )
{
if ( t->Tag() == TYPE_RECORD )
{
// Only "shallow" copy record types because we want to be able
// to see additions to the original type's list of fields
switch ( t->Tag() ) {
// Only "shallow" copy types that may contain records because
// we want to be able to see additions to the original record type's
// list of fields
case TYPE_RECORD:
tnew = new RecordType(t->AsRecordType()->Types());
}
else
{
break;
case TYPE_TABLE:
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();
form->StartWrite();
CloneSerializer ss(form);

View file

@ -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`

View file

@ -1,12 +1,11 @@
# @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)
# 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.
# a type that contains record types will correctly see field additions to
# those contained-records.
type my_record: record {
field1: bool;
@ -16,17 +15,22 @@ type my_record: record {
type super_record: record {
rec: my_record;
};
type my_table: table[count] of my_record;
type my_vector: vector of my_record;
redef record my_record += {
field3: count &optional;
};
global a: my_record;
global b: super_record;
global c: my_table;
global d: my_vector;
function test_func()
{
a?$field3;
b$rec?$field3;
c[0]$field3;
d[0]$field3;
}