introduce &weaken attribute, which basically only prevents

the describe function for types to descend into record fields that
are marked with it.

With this, we can actually load the pacf scripts without crashing Bro
when running tests :)
This commit is contained in:
Johanna Amann 2015-04-13 16:05:55 -07:00
parent 21b78b7d92
commit 00204ab8a6
7 changed files with 25 additions and 9 deletions

View file

@ -85,7 +85,7 @@ export {
redef record PluginState += { redef record PluginState += {
## The plugin that the state belongs to. (Defined separately ## The plugin that the state belongs to. (Defined separately
## because of cyclic type dependency.) ## because of cyclic type dependency.)
plugin: Plugin &optional; plugin: Plugin &optional &weaken;
}; };
} }

View file

@ -37,7 +37,8 @@
@load base/frameworks/reporter @load base/frameworks/reporter
@load base/frameworks/sumstats @load base/frameworks/sumstats
@load base/frameworks/tunnels @load base/frameworks/tunnels
#@load base/frameworks/pacf @load base/frameworks/openflow
@load base/frameworks/pacf
@load base/protocols/conn @load base/protocols/conn
@load base/protocols/dhcp @load base/protocols/dhcp

View file

@ -18,7 +18,7 @@ const char* attr_name(attr_tag t)
"&encrypt", "&encrypt",
"&raw_output", "&mergeable", "&priority", "&raw_output", "&mergeable", "&priority",
"&group", "&log", "&error_handler", "&type_column", "&group", "&log", "&error_handler", "&type_column",
"(&tracked)", "&deprecated", "(&tracked)", "&deprecated", "&weaken",
}; };
return attr_names[int(t)]; return attr_names[int(t)];
@ -436,6 +436,11 @@ void Attributes::CheckAttr(Attr* a)
Error("&log applied to a type that cannot be logged"); Error("&log applied to a type that cannot be logged");
break; break;
case ATTR_WEAKEN:
if ( ! in_record )
Error("&weaken applied outside of record");
break;
case ATTR_TYPE_COLUMN: case ATTR_TYPE_COLUMN:
{ {
if ( type->Tag() != TYPE_PORT ) if ( type->Tag() != TYPE_PORT )

View file

@ -35,7 +35,8 @@ typedef enum {
ATTR_TYPE_COLUMN, // for input framework ATTR_TYPE_COLUMN, // for input framework
ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry
ATTR_DEPRECATED, ATTR_DEPRECATED,
#define NUM_ATTRS (int(ATTR_DEPRECATED) + 1) ATTR_WEAKEN,
#define NUM_ATTRS (int(ATTR_WEAKEN) + 1)
} attr_tag; } attr_tag;
class Attr : public BroObj { class Attr : public BroObj {

View file

@ -1129,6 +1129,9 @@ void RecordType::DescribeFields(ODesc* d) const
const TypeDecl* td = FieldDecl(i); const TypeDecl* td = FieldDecl(i);
d->Add(td->id); d->Add(td->id);
d->Add(":"); d->Add(":");
if ( td->FindAttr(ATTR_WEAKEN) )
d->Add("<weakened>");
else
td->type->Describe(d); td->type->Describe(d);
d->Add(";"); d->Add(";");
} }
@ -1170,6 +1173,9 @@ void RecordType::DescribeFieldsReST(ODesc* d, bool func_args) const
} }
const TypeDecl* td = FieldDecl(i); const TypeDecl* td = FieldDecl(i);
if ( td->FindAttr(ATTR_WEAKEN) )
d->Add("<weakened>");
else
td->DescribeReST(d); td->DescribeReST(d);
if ( func_args ) if ( func_args )

View file

@ -2,7 +2,7 @@
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
%} %}
%expect 78 %expect 81
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY %token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY
%token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF %token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF
@ -25,7 +25,7 @@
%token TOK_ATTR_PERSISTENT TOK_ATTR_SYNCHRONIZED %token TOK_ATTR_PERSISTENT TOK_ATTR_SYNCHRONIZED
%token TOK_ATTR_RAW_OUTPUT TOK_ATTR_MERGEABLE %token TOK_ATTR_RAW_OUTPUT TOK_ATTR_MERGEABLE
%token TOK_ATTR_PRIORITY TOK_ATTR_LOG TOK_ATTR_ERROR_HANDLER %token TOK_ATTR_PRIORITY TOK_ATTR_LOG TOK_ATTR_ERROR_HANDLER
%token TOK_ATTR_TYPE_COLUMN TOK_ATTR_DEPRECATED %token TOK_ATTR_TYPE_COLUMN TOK_ATTR_DEPRECATED TOK_ATTR_WEAKEN
%token TOK_DEBUG %token TOK_DEBUG
@ -1291,6 +1291,8 @@ attr:
{ $$ = new Attr(ATTR_ERROR_HANDLER); } { $$ = new Attr(ATTR_ERROR_HANDLER); }
| TOK_ATTR_DEPRECATED | TOK_ATTR_DEPRECATED
{ $$ = new Attr(ATTR_DEPRECATED); } { $$ = new Attr(ATTR_DEPRECATED); }
| TOK_ATTR_WEAKEN
{ $$ = new Attr(ATTR_WEAKEN); }
; ;
stmt: stmt:

View file

@ -276,6 +276,7 @@ when return TOK_WHEN;
&type_column return TOK_ATTR_TYPE_COLUMN; &type_column return TOK_ATTR_TYPE_COLUMN;
&read_expire return TOK_ATTR_EXPIRE_READ; &read_expire return TOK_ATTR_EXPIRE_READ;
&redef return TOK_ATTR_REDEF; &redef return TOK_ATTR_REDEF;
&weaken return TOK_ATTR_WEAKEN;
&write_expire return TOK_ATTR_EXPIRE_WRITE; &write_expire return TOK_ATTR_EXPIRE_WRITE;
&encrypt { &encrypt {