Removing global_attrs from parser, per #11, and also record

attributes. Both aren't used anywhere. Along with these goes some
more now unused code.

Closes #11.
This commit is contained in:
Robin Sommer 2011-01-06 16:53:31 -08:00
parent e1ab9b1c69
commit 75335b933e
8 changed files with 35 additions and 155 deletions

View file

@ -2611,7 +2611,6 @@ Val* AssignExpr::Eval(Frame* f) const
if ( v ) if ( v )
{ {
op1->Assign(f, v); op1->Assign(f, v);
//### op1->SetAttribs();
return val ? val->Ref() : v->Ref(); return val ? val->Ref() : v->Ref();
} }
else else
@ -3062,13 +3061,6 @@ FieldExpr::FieldExpr(Expr* arg_op, const char* arg_field_name)
if ( IsError() ) if ( IsError() )
return; return;
if ( streq(arg_field_name, "attr") )
{
field = -1;
SetType(op->Type()->AttributesType()->Ref());
return;
}
if ( ! IsRecord(op->Type()->Tag()) ) if ( ! IsRecord(op->Type()->Tag()) )
ExprError("not a record"); ExprError("not a record");
else else
@ -3106,12 +3098,7 @@ void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
return; return;
if ( field < 0 ) if ( field < 0 )
{ ExprError("no such field in record");
Val* lhs = op->Eval(f);
lhs->SetAttribs(v->AsRecordVal());
Unref(lhs);
return;
}
Val* op_v = op->Eval(f); Val* op_v = op->Eval(f);
if ( op_v ) if ( op_v )
@ -3124,9 +3111,6 @@ void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
Val* FieldExpr::Fold(Val* v) const Val* FieldExpr::Fold(Val* v) const
{ {
if ( field < 0 )
return v->GetAttribs(true)->Ref();
Val* result = v->AsRecordVal()->Lookup(field); Val* result = v->AsRecordVal()->Lookup(field);
if ( result ) if ( result )
return result->Ref(); return result->Ref();
@ -3179,24 +3163,20 @@ bool FieldExpr::DoUnserialize(UnserialInfo* info)
return td != 0; return td != 0;
} }
HasFieldExpr::HasFieldExpr(Expr* arg_op, const char* arg_field_name, HasFieldExpr::HasFieldExpr(Expr* arg_op, const char* arg_field_name)
bool arg_is_attr)
: UnaryExpr(EXPR_HAS_FIELD, arg_op) : UnaryExpr(EXPR_HAS_FIELD, arg_op)
{ {
field_name = arg_field_name; field_name = arg_field_name;
is_attr = arg_is_attr;
field = 0; field = 0;
if ( IsError() ) if ( IsError() )
return; return;
if ( ! is_attr && ! IsRecord(op->Type()->Tag()) ) if ( ! IsRecord(op->Type()->Tag()) )
ExprError("not a record"); ExprError("not a record");
else else
{ {
RecordType* rt = is_attr ? RecordType* rt = op->Type()->AsRecordType();
op->Type()->AttributesType() :
op->Type()->AsRecordType();
field = rt->FieldOffset(field_name); field = rt->FieldOffset(field_name);
if ( field < 0 ) if ( field < 0 )
@ -3215,9 +3195,6 @@ Val* HasFieldExpr::Fold(Val* v) const
{ {
RecordVal* rec_to_look_at; RecordVal* rec_to_look_at;
if ( is_attr )
rec_to_look_at = v->GetAttribs(false);
else
rec_to_look_at = v->AsRecordVal(); rec_to_look_at = v->AsRecordVal();
if ( ! rec_to_look_at ) if ( ! rec_to_look_at )
@ -3235,12 +3212,7 @@ void HasFieldExpr::ExprDescribe(ODesc* d) const
op->Describe(d); op->Describe(d);
if ( d->IsReadable() ) if ( d->IsReadable() )
{
if ( is_attr )
d->Add("?$$");
else
d->Add("?$"); d->Add("?$");
}
if ( IsError() ) if ( IsError() )
d->Add("<error>"); d->Add("<error>");
@ -3255,13 +3227,17 @@ IMPLEMENT_SERIAL(HasFieldExpr, SER_HAS_FIELD_EXPR);
bool HasFieldExpr::DoSerialize(SerialInfo* info) const bool HasFieldExpr::DoSerialize(SerialInfo* info) const
{ {
DO_SERIALIZE(SER_HAS_FIELD_EXPR, UnaryExpr); DO_SERIALIZE(SER_HAS_FIELD_EXPR, UnaryExpr);
return SERIALIZE(is_attr) && SERIALIZE(field_name) && SERIALIZE(field);
// Serialize the former "bool is_attr" first for backwards compatibility.
return SERIALIZE(false) && SERIALIZE(field_name) && SERIALIZE(field);
} }
bool HasFieldExpr::DoUnserialize(UnserialInfo* info) bool HasFieldExpr::DoUnserialize(UnserialInfo* info)
{ {
DO_UNSERIALIZE(UnaryExpr); DO_UNSERIALIZE(UnaryExpr);
return UNSERIALIZE(&is_attr) && UNSERIALIZE_STR(&field_name, 0) && UNSERIALIZE(&field); // Unserialize the former "bool is_attr" first for backwards compatibility.
bool not_used;
return UNSERIALIZE(&not_used) && UNSERIALIZE_STR(&field_name, 0) && UNSERIALIZE(&field);
} }
RecordConstructorExpr::RecordConstructorExpr(ListExpr* constructor_list) RecordConstructorExpr::RecordConstructorExpr(ListExpr* constructor_list)
@ -3507,8 +3483,6 @@ Val* SetConstructorExpr::Eval(Frame* f) const
aggr->Assign(element, 0); aggr->Assign(element, 0);
} }
aggr->AsTableVal()->SetAttrs(attrs);
return aggr; return aggr;
} }

View file

@ -709,7 +709,7 @@ protected:
// "rec?$$attrname" is true if the attribute attrname is not nil. // "rec?$$attrname" is true if the attribute attrname is not nil.
class HasFieldExpr : public UnaryExpr { class HasFieldExpr : public UnaryExpr {
public: public:
HasFieldExpr(Expr* op, const char* field_name, bool is_attr); HasFieldExpr(Expr* op, const char* field_name);
~HasFieldExpr(); ~HasFieldExpr();
protected: protected:

View file

@ -10,20 +10,6 @@
#include "Scope.h" #include "Scope.h"
#include "Serializer.h" #include "Serializer.h"
RecordType* init_global_attrs();
bool in_global_attr_decl = false;
RecordType* global_attributes_type = init_global_attrs();
RecordType* init_global_attrs()
{
in_global_attr_decl = true;
RecordType* rt = new RecordType(new type_decl_list);
in_global_attr_decl = false;
rt->MakeGlobalAttributeType();
return rt;
}
const char* type_name(TypeTag t) const char* type_name(TypeTag t)
{ {
static char errbuf[512]; static char errbuf[512];
@ -58,7 +44,6 @@ BroType::BroType(TypeTag t, bool arg_base_type)
tag = t; tag = t;
is_network_order = 0; is_network_order = 0;
base_type = arg_base_type; base_type = arg_base_type;
is_global_attributes_type = false;
switch ( tag ) { switch ( tag ) {
case TYPE_VOID: case TYPE_VOID:
@ -118,28 +103,6 @@ BroType::BroType(TypeTag t, bool arg_base_type)
break; break;
} }
// Kind of hacky; we don't want an error while we're defining
// the global attrs!
if ( in_global_attr_decl )
{
attributes_type = 0;
return;
}
if ( ! global_attributes_type )
SetError();
else
attributes_type = global_attributes_type;
}
bool BroType::SetAttributesType(type_decl_list* attr_types)
{
TypeList* global = new TypeList();
global->Append(global_attributes_type);
attributes_type = refine_type(global, attr_types)->AsRecordType();
return (attributes_type != 0);
} }
int BroType::MatchesIndex(ListExpr*& /* index */) const int BroType::MatchesIndex(ListExpr*& /* index */) const
@ -241,16 +204,6 @@ BroType* BroType::Unserialize(UnserialInfo* info, TypeTag want)
return t2; return t2;
} }
// For the global_attribute_type, we also return our current instance.
if ( t->is_global_attributes_type )
{
BroType* t2 = global_attributes_type;
Unref(t);
t2->Ref();
assert(t2);
return t2;
}
assert(t); assert(t);
return t; return t;
} }
@ -267,10 +220,15 @@ bool BroType::DoSerialize(SerialInfo* info) const
return false; return false;
if ( ! (SERIALIZE(is_network_order) && SERIALIZE(base_type) && if ( ! (SERIALIZE(is_network_order) && SERIALIZE(base_type) &&
SERIALIZE(is_global_attributes_type)) ) // Serialize the former "bool is_global_attributes_type" for
// backwards compatibility.
SERIALIZE(false)) )
return false; return false;
SERIALIZE_OPTIONAL(attributes_type); // Likewise, serialize the former optional "RecordType* attributes_type"
// for backwards compatibility.
void* null = NULL;
SERIALIZE(null);
info->s->WriteCloseTag("Type"); info->s->WriteCloseTag("Type");
@ -288,13 +246,19 @@ bool BroType::DoUnserialize(UnserialInfo* info)
tag = (TypeTag) c1; tag = (TypeTag) c1;
internal_tag = (InternalTypeTag) c2; internal_tag = (InternalTypeTag) c2;
bool not_used;
if ( ! (UNSERIALIZE(&is_network_order) && UNSERIALIZE(&base_type) if ( ! (UNSERIALIZE(&is_network_order) && UNSERIALIZE(&base_type)
&& UNSERIALIZE(&is_global_attributes_type)) ) // Unerialize the former "bool is_global_attributes_type" for
// backwards compatibility.
&& UNSERIALIZE(&not_used)) )
return 0; return 0;
BroType* type; BroType* not_used_either;
UNSERIALIZE_OPTIONAL(type, BroType::Unserialize(info, TYPE_RECORD));
attributes_type = (RecordType*) type; // Likewise, unserialize the former optional "RecordType*
// attributes_type" for backwards compatibility.
UNSERIALIZE_OPTIONAL(not_used_either, BroType::Unserialize(info, TYPE_RECORD));
return true; return true;
} }
@ -721,9 +685,6 @@ TypeDecl::TypeDecl(BroType* t, const char* i, attr_list* arg_attrs)
type = t; type = t;
attrs = arg_attrs ? new Attributes(arg_attrs, t) : 0; attrs = arg_attrs ? new Attributes(arg_attrs, t) : 0;
id = i; id = i;
if ( in_global_attr_decl && ! attrs->FindAttr(ATTR_DEFAULT) )
error("global attribute types must have default values");
} }
TypeDecl::~TypeDecl() TypeDecl::~TypeDecl()

View file

@ -60,9 +60,6 @@ class EnumType;
class Serializer; class Serializer;
class VectorType; class VectorType;
extern bool in_global_attr_decl;
extern RecordType* global_attributes_type;
const int DOES_NOT_MATCH_INDEX = 0; const int DOES_NOT_MATCH_INDEX = 0;
const int MATCHES_INDEX_SCALAR = 1; const int MATCHES_INDEX_SCALAR = 1;
const int MATCHES_INDEX_VECTOR = 2; const int MATCHES_INDEX_VECTOR = 2;
@ -74,15 +71,6 @@ public:
TypeTag Tag() const { return tag; } TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; } InternalTypeTag InternalType() const { return internal_tag; }
// Type for the attributes (metadata) on this type.
RecordType* AttributesType()
{
if ( ! attributes_type )
attributes_type = global_attributes_type;
return attributes_type;
}
bool SetAttributesType(type_decl_list* attr_types);
// Whether it's stored in network order. // Whether it's stored in network order.
int IsNetworkOrder() const { return is_network_order; } int IsNetworkOrder() const { return is_network_order; }
@ -211,8 +199,6 @@ public:
BroType* Ref() { ::Ref(this); return this; } BroType* Ref() { ::Ref(this); return this; }
void MakeGlobalAttributeType() { is_global_attributes_type = true; }
virtual void Describe(ODesc* d) const; virtual void Describe(ODesc* d) const;
virtual unsigned MemoryAllocation() const; virtual unsigned MemoryAllocation() const;
@ -221,7 +207,7 @@ public:
static BroType* Unserialize(UnserialInfo* info, TypeTag want = TYPE_ANY); static BroType* Unserialize(UnserialInfo* info, TypeTag want = TYPE_ANY);
protected: protected:
BroType() { attributes_type = 0; } BroType() { }
void SetError(); void SetError();
@ -232,8 +218,6 @@ private:
InternalTypeTag internal_tag; InternalTypeTag internal_tag;
bool is_network_order; bool is_network_order;
bool base_type; bool base_type;
bool is_global_attributes_type;
RecordType* attributes_type;
}; };
class TypeList : public BroType { class TypeList : public BroType {

View file

@ -414,15 +414,6 @@ bool Val::DoUnserialize(UnserialInfo* info)
return false; return false;
} }
RecordVal* Val::GetAttribs(bool instantiate)
{
if ( ! instantiate || attribs )
return attribs;
attribs = new RecordVal(type->AttributesType());
return attribs;
}
int Val::IsZero() const int Val::IsZero() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {

View file

@ -178,13 +178,6 @@ public:
Val* Ref() { ::Ref(this); return this; } Val* Ref() { ::Ref(this); return this; }
virtual Val* Clone() const; virtual Val* Clone() const;
RecordVal* GetAttribs(bool instantiate);
void SetAttribs(RecordVal* arg_attribs)
{
Unref((Val*) attribs);
attribs = arg_attribs;
}
int IsZero() const; int IsZero() const;
int IsOne() const; int IsOne() const;

View file

@ -8,7 +8,7 @@
%token TOK_BOOL TOK_BREAK TOK_CASE TOK_CONST %token TOK_BOOL TOK_BREAK TOK_CASE TOK_CONST
%token TOK_CONSTANT TOK_COPY TOK_COUNT TOK_COUNTER TOK_DEFAULT TOK_DELETE %token TOK_CONSTANT TOK_COPY TOK_COUNT TOK_COUNTER TOK_DEFAULT TOK_DELETE
%token TOK_DOUBLE TOK_ELSE TOK_ENUM TOK_EVENT TOK_EXPORT TOK_FILE TOK_FOR %token TOK_DOUBLE TOK_ELSE TOK_ENUM TOK_EVENT TOK_EXPORT TOK_FILE TOK_FOR
%token TOK_FUNCTION TOK_GLOBAL TOK_GLOBAL_ATTR TOK_ID TOK_IF TOK_INT %token TOK_FUNCTION TOK_GLOBAL TOK_ID TOK_IF TOK_INT
%token TOK_INTERVAL TOK_LIST TOK_LOCAL TOK_MODULE TOK_MATCH TOK_NET %token TOK_INTERVAL TOK_LIST TOK_LOCAL TOK_MODULE TOK_MATCH TOK_NET
%token TOK_NEXT TOK_OF TOK_PATTERN TOK_PATTERN_TEXT %token TOK_NEXT TOK_OF TOK_PATTERN TOK_PATTERN_TEXT
%token TOK_PORT TOK_PRINT TOK_RECORD TOK_REDEF %token TOK_PORT TOK_PRINT TOK_RECORD TOK_REDEF
@ -53,7 +53,7 @@
%type <func_type> func_hdr func_params %type <func_type> func_hdr func_params
%type <type_l> type_list %type <type_l> type_list
%type <type_decl> type_decl formal_args_decl %type <type_decl> type_decl formal_args_decl
%type <type_decl_l> type_decl_list formal_args_decl_list opt_attr_attr %type <type_decl_l> type_decl_list formal_args_decl_list
%type <record> formal_args %type <record> formal_args
%type <list> expr_list opt_expr_list %type <list> expr_list opt_expr_list
%type <c_case> case %type <c_case> case
@ -417,13 +417,7 @@ expr:
| expr TOK_HAS_FIELD TOK_ID | expr TOK_HAS_FIELD TOK_ID
{ {
set_location(@1, @3); set_location(@1, @3);
$$ = new HasFieldExpr($1, $3, false); $$ = new HasFieldExpr($1, $3);
}
| expr TOK_HAS_ATTR TOK_ID
{
set_location(@1, @3);
$$ = new HasFieldExpr($1, $3, true);
} }
| anonymous_function | anonymous_function
@ -821,17 +815,9 @@ decl:
} }
} }
| TOK_TYPE global_id ':' refined_type opt_attr opt_attr_attr ';' | TOK_TYPE global_id ':' refined_type opt_attr ';'
{ {
add_type($2, $4, $5, 0); add_type($2, $4, $5, 0);
if ( $6 )
$2->AsType()->SetAttributesType($6);
}
| TOK_GLOBAL_ATTR ':' { in_global_attr_decl = true; }
'{' type_decl_list '}' ';' { in_global_attr_decl = false; }
{
global_attributes_type = new RecordType($5);
} }
| TOK_EVENT event_id ':' refined_type opt_attr ';' | TOK_EVENT event_id ':' refined_type opt_attr ';'
@ -856,13 +842,6 @@ conditional:
{ do_atelse(); } { do_atelse(); }
; ;
opt_attr_attr:
TOK_ATTR_ATTR '=' '{' type_decl_list '}'
{ $$ = $4; }
|
{ $$ = 0; }
;
func_hdr: func_hdr:
TOK_FUNCTION global_id func_params TOK_FUNCTION global_id func_params
{ {

View file

@ -151,9 +151,7 @@ file return TOK_FILE;
for return TOK_FOR; for return TOK_FOR;
function return TOK_FUNCTION; function return TOK_FUNCTION;
global return TOK_GLOBAL; global return TOK_GLOBAL;
global_attr return TOK_GLOBAL_ATTR;
"?$" return TOK_HAS_FIELD; "?$" return TOK_HAS_FIELD;
"?$$" return TOK_HAS_ATTR;
if return TOK_IF; if return TOK_IF;
in return TOK_IN; in return TOK_IN;
"!"{OWS}in/[^A-Za-z0-9] return TOK_NOT_IN; /* don't confuse w "! infoo"! */ "!"{OWS}in/[^A-Za-z0-9] return TOK_NOT_IN; /* don't confuse w "! infoo"! */