diff --git a/doc/scripts/example.bro b/doc/scripts/example.bro index f148788ce4..5cb17c7050 100644 --- a/doc/scripts/example.bro +++ b/doc/scripts/example.bro @@ -107,6 +107,11 @@ export { field2: bool; ##< toggles something }; + ## document the record extension redef here + redef record SimpleRecord += { + ## document the extending field here + field_ext: string &optional; ##< (or here) + }; ## general documentation for a type "ComplexRecord" goes here type ComplexRecord: record { diff --git a/src/parse.y b/src/parse.y index debdf02177..cb30494df5 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1067,8 +1067,9 @@ decl: } | TOK_REDEF TOK_RECORD global_id TOK_ADD_TO - '{' type_decl_list '}' opt_attr ';' + '{' { do_doc_token_start(); } type_decl_list '}' opt_attr ';' { + do_doc_token_stop(); if ( ! $3->Type() ) $3->Error("unknown identifier"); else @@ -1078,9 +1079,27 @@ decl: $3->Error("not a record type"); else { - const char* error = add_to->AddFields($6, $8); + const char* error = add_to->AddFields($7, $9); if ( error ) - $3->Error(error); + $3->Error(error); + else if ( generate_documentation ) + { + if ( fake_type_decl_list ) + { + BroType* fake_record = + new RecordType(fake_type_decl_list); + ID* fake = create_dummy_id($3, fake_record); + fake_type_decl_list = 0; + current_reST_doc->AddRedef( + new BroDocObj(fake, reST_doc_comments, true)); + } + else + { + fprintf(stderr, "Warning: doc mode did not process " + "record extension for '%s', CommentedTypeDecl" + "list unavailable.\n", $3->Name()); + } + } } } } diff --git a/testing/btest/Baseline/doc.autogen-reST-example/example.rst b/testing/btest/Baseline/doc.autogen-reST-example/example.rst index 6de04b10aa..2f22f07ad9 100644 --- a/testing/btest/Baseline/doc.autogen-reST-example/example.rst +++ b/testing/btest/Baseline/doc.autogen-reST-example/example.rst @@ -65,9 +65,11 @@ Functions Redefinitions ############# -================================================= ==================================== -:bro:type:`Example::SimpleEnum`: :bro:type:`enum` document the "SimpleEnum" redef here -================================================= ==================================== +===================================================== ======================================== +:bro:type:`Example::SimpleEnum`: :bro:type:`enum` document the "SimpleEnum" redef here + +:bro:type:`Example::SimpleRecord`: :bro:type:`record` document the record extension redef here +===================================================== ======================================== Namespaces ~~~~~~~~~~ @@ -227,6 +229,16 @@ Redefinitions document the "SimpleEnum" redef here +.. bro:type:: Example::SimpleRecord + + :Type: :bro:type:`record` + + field_ext: :bro:type:`string` :bro:attr:`&optional` + document the extending field here + (or here) + + document the record extension redef here + Port Analysis ------------- :ref:`More Information ` diff --git a/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst b/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst new file mode 100644 index 0000000000..333600f179 --- /dev/null +++ b/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst @@ -0,0 +1,99 @@ +.. Automatically generated. Do not edit. + +autogen-reST-record-add.bro +=========================== + +:download:`Original Source File ` + +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= + field2= + field3= + } + +.. bro:id:: b + + :Type: :bro:type:`super_record` + :Default: + + :: + + { + rec=[field1=, field2=, field3=] + } + +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` + diff --git a/testing/btest/doc/autogen-reST-record-add.bro b/testing/btest/doc/autogen-reST-record-add.bro index 5f95a27e8c..4ad33e68ae 100644 --- a/testing/btest/doc/autogen-reST-record-add.bro +++ b/testing/btest/doc/autogen-reST-record-add.bro @@ -1,4 +1,5 @@ # @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.