start support for annotation for log field types.

commit before rolling part of it back...
This commit is contained in:
Bernhard Amann 2011-12-05 15:02:03 -08:00
parent 949ec6897a
commit 78b24da7e4
7 changed files with 28 additions and 6 deletions

View file

@ -35,6 +35,7 @@ typedef enum {
ATTR_GROUP,
ATTR_LOG,
ATTR_ERROR_HANDLER,
ATTR_TYPE_COLUMN, // for input framework
ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry
#define NUM_ATTRS (int(ATTR_TRACKED) + 1)
} attr_tag;

View file

@ -561,6 +561,16 @@ bool InputMgr::UnrollRecordType(vector<LogField*> *fields, const RecordType *rec
field->subtype = rec->FieldType(i)->AsSetType()->Indices()->PureType()->Tag();
} else if ( field->type == TYPE_VECTOR ) {
field->subtype = rec->FieldType(i)->AsVectorType()->YieldType()->Tag();
} else if ( field->type == TYPE_PORT &&
rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN) ) {
// we have an annotation for the second column
Val* c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(0);
assert(c);
assert(c->Type()->Tag() == TYPE_STRING);
field->secondary_name = c->AsStringVal()->AsString()->CheckString();
}
fields->push_back(field);

View file

@ -12,8 +12,11 @@
struct FieldMapping {
string name;
TypeTag type;
// internal type for sets and vectors
TypeTag subtype;
int position;
// for ports: pos of the second field
int secondary_position;
FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position);
FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position);

View file

@ -83,7 +83,8 @@ bool LogField::Read(SerializationFormat* fmt)
int t;
int it;
bool success = (fmt->Read(&name, "name") && fmt->Read(&t, "type") && fmt->Read(&it, "subtype") );
bool success = (fmt->Read(&name, "name") && fmt->Read(&secondary_name, "secondary_name") &&
fmt->Read(&t, "type") && fmt->Read(&it, "subtype") );
type = (TypeTag) t;
subtype = (TypeTag) it;
@ -92,7 +93,8 @@ bool LogField::Read(SerializationFormat* fmt)
bool LogField::Write(SerializationFormat* fmt) const
{
return (fmt->Write(name, "name") && fmt->Write((int)type, "type") && fmt->Write((int)subtype, "subtype"));
return (fmt->Write(name, "name") && fmt->Write(secondary_name, "secondary_name") && fmt->Write((int)type, "type") &&
fmt->Write((int)subtype, "subtype"));
}
LogVal::~LogVal()
@ -151,7 +153,7 @@ bool LogVal::IsCompatibleType(BroType* t, bool atomic_only)
if ( ! t->IsSet() )
return false;
return IsCompatibleType(t->AsSetType()->Indices()->PureType(), true);
return IsCompatibleType(t->AsSetType()->Indices()->PureType());
}
case TYPE_VECTOR:

View file

@ -14,13 +14,15 @@ class SerializationFormat;
// Description of a log field.
struct LogField {
string name;
// needed by input framework. port fields have two names (one for the port, one for the type) - this specifies the secondary name.
string secondary_name;
TypeTag type;
// needed by input framework. otherwise it cannot determine the inner type of a set or vector.
// needed by input framework. otherwise it cannot determine the inner type of a set.
TypeTag subtype;
LogField() { }
LogField(const LogField& other)
: name(other.name), type(other.type), subtype(other.subtype) { }
: name(other.name), secondary_name(other.secondary_name), type(other.type), subtype(other.subtype) { }
// (Un-)serialize.
bool Read(SerializationFormat* fmt);

View file

@ -2,7 +2,7 @@
// See the file "COPYING" in the main distribution directory for copyright.
%}
%expect 88
%expect 91
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY
%token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF
@ -24,6 +24,7 @@
%token TOK_ATTR_PERSISTENT TOK_ATTR_SYNCHRONIZED
%token TOK_ATTR_DISABLE_PRINT_HOOK TOK_ATTR_RAW_OUTPUT TOK_ATTR_MERGEABLE
%token TOK_ATTR_PRIORITY TOK_ATTR_GROUP TOK_ATTR_LOG TOK_ATTR_ERROR_HANDLER
%token TOK_ATTR_TYPE_COLUMN
%token TOK_DEBUG
@ -1313,6 +1314,8 @@ attr:
{ $$ = new Attr(ATTR_PRIORITY, $3); }
| TOK_ATTR_GROUP '=' expr
{ $$ = new Attr(ATTR_GROUP, $3); }
| TOK_ATTR_TYPE_COLUMN '=' expr
{ $$ = new Attr(ATTR_TYPE_COLUMN, $3); }
| TOK_ATTR_LOG
{ $$ = new Attr(ATTR_LOG); }
| TOK_ATTR_ERROR_HANDLER

View file

@ -308,6 +308,7 @@ when return TOK_WHEN;
&optional return TOK_ATTR_OPTIONAL;
&persistent return TOK_ATTR_PERSISTENT;
&priority return TOK_ATTR_PRIORITY;
&type_column return TOK_ATTR_TYPE_COLUMN;
&read_expire return TOK_ATTR_EXPIRE_READ;
&redef return TOK_ATTR_REDEF;
&rotate_interval return TOK_ATTR_ROTATE_INTERVAL;