Remove enum Opcode.

This commit is contained in:
Robin Sommer 2019-06-06 03:24:13 +00:00
parent 31ddca863c
commit 0ba382280c
8 changed files with 44 additions and 102 deletions

View file

@ -97,7 +97,7 @@ void Expr::EvalIntoAggregate(const BroType* /* t */, Val* /* aggr */,
Internal("Expr::EvalIntoAggregate called");
}
void Expr::Assign(Frame* /* f */, Val* /* v */, Opcode /* op */)
void Expr::Assign(Frame* /* f */, Val* /* v */)
{
Internal("Expr::Assign called");
}
@ -261,10 +261,10 @@ Expr* NameExpr::MakeLvalue()
return new RefExpr(this);
}
void NameExpr::Assign(Frame* f, Val* v, Opcode op)
void NameExpr::Assign(Frame* f, Val* v)
{
if ( id->IsGlobal() )
id->SetVal(v, op);
id->SetVal(v);
else
f->SetElement(id->Offset(), v);
}
@ -1007,18 +1007,18 @@ Val* IncrExpr::Eval(Frame* f) const
if ( elt )
{
Val* new_elt = DoSingleEval(f, elt);
v_vec->Assign(i, new_elt, OP_INCR);
v_vec->Assign(i, new_elt);
}
else
v_vec->Assign(i, 0, OP_INCR);
v_vec->Assign(i, 0);
}
op->Assign(f, v_vec, OP_INCR);
op->Assign(f, v_vec);
}
else
{
Val* old_v = v;
op->Assign(f, v = DoSingleEval(f, old_v), OP_INCR);
op->Assign(f, v = DoSingleEval(f, old_v));
Unref(old_v);
}
@ -2041,9 +2041,9 @@ Expr* RefExpr::MakeLvalue()
return this;
}
void RefExpr::Assign(Frame* f, Val* v, Opcode opcode)
void RefExpr::Assign(Frame* f, Val* v)
{
op->Assign(f, v, opcode);
op->Assign(f, v);
}
AssignExpr::AssignExpr(Expr* arg_op1, Expr* arg_op2, int arg_is_init,
@ -2684,7 +2684,7 @@ Val* IndexExpr::Fold(Val* v1, Val* v2) const
return 0;
}
void IndexExpr::Assign(Frame* f, Val* v, Opcode op)
void IndexExpr::Assign(Frame* f, Val* v)
{
if ( IsError() )
return;
@ -2704,7 +2704,7 @@ void IndexExpr::Assign(Frame* f, Val* v, Opcode op)
switch ( v1->Type()->Tag() ) {
case TYPE_VECTOR:
if ( ! v1->AsVectorVal()->Assign(v2, v, op) )
if ( ! v1->AsVectorVal()->Assign(v2, v) )
{
if ( v )
{
@ -2723,7 +2723,7 @@ void IndexExpr::Assign(Frame* f, Val* v, Opcode op)
break;
case TYPE_TABLE:
if ( ! v1->AsTableVal()->Assign(v2, v, op) )
if ( ! v1->AsTableVal()->Assign(v2, v) )
{
if ( v )
{
@ -2826,7 +2826,7 @@ int FieldExpr::CanDel() const
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
}
void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
void FieldExpr::Assign(Frame* f, Val* v)
{
if ( IsError() )
return;
@ -2835,14 +2835,14 @@ void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
if ( op_v )
{
RecordVal* r = op_v->AsRecordVal();
r->Assign(field, v, opcode);
r->Assign(field, v);
Unref(r);
}
}
void FieldExpr::Delete(Frame* f)
{
Assign(f, 0, OP_ASSIGN_IDX);
Assign(f, 0);
}
Val* FieldExpr::Fold(Val* v) const
@ -4635,7 +4635,7 @@ Expr* ListExpr::MakeLvalue()
return new RefExpr(this);
}
void ListExpr::Assign(Frame* f, Val* v, Opcode op)
void ListExpr::Assign(Frame* f, Val* v)
{
ListVal* lv = v->AsListVal();
@ -4643,7 +4643,7 @@ void ListExpr::Assign(Frame* f, Val* v, Opcode op)
RuntimeError("mismatch in list lengths");
loop_over_list(exprs, i)
exprs[i]->Assign(f, (*lv->Vals())[i]->Ref(), op);
exprs[i]->Assign(f, (*lv->Vals())[i]->Ref());
Unref(lv);
}

View file

@ -84,7 +84,7 @@ public:
const;
// Assign to the given value, if appropriate.
virtual void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN);
virtual void Assign(Frame* f, Val* v);
// Returns the type corresponding to this expression interpreted
// as an initialization. The type should be Unref()'d when done
@ -225,7 +225,7 @@ public:
ID* Id() const { return id; }
Val* Eval(Frame* f) const override;
void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN) override;
void Assign(Frame* f, Val* v) override;
Expr* MakeLvalue() override;
int IsPure() const override;
@ -572,7 +572,7 @@ class RefExpr : public UnaryExpr {
public:
explicit RefExpr(Expr* op);
void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN) override;
void Assign(Frame* f, Val* v) override;
Expr* MakeLvalue() override;
protected:
@ -615,7 +615,7 @@ public:
void Add(Frame* f) override;
void Delete(Frame* f) override;
void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN) override;
void Assign(Frame* f, Val* v) override;
Expr* MakeLvalue() override;
// Need to override Eval since it can take a vector arg but does
@ -643,7 +643,7 @@ public:
int CanDel() const override;
void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN) override;
void Assign(Frame* f, Val* v) override;
void Delete(Frame* f) override;
Expr* MakeLvalue() override;
@ -963,7 +963,7 @@ public:
BroType* InitType() const override;
Val* InitVal(const BroType* t, Val* aggr) const override;
Expr* MakeLvalue() override;
void Assign(Frame* f, Val* v, Opcode op = OP_ASSIGN) override;
void Assign(Frame* f, Val* v) override;
TraversalCode Traverse(TraversalCallback* cb) const override;

View file

@ -59,34 +59,14 @@ void ID::ClearVal()
val = 0;
}
void ID::SetVal(Val* v, Opcode op, bool arg_weak_ref)
void ID::SetVal(Val* v, bool arg_weak_ref)
{
if ( op != OP_NONE )
{
MutableVal::Properties props = 0;
if ( attrs && attrs->FindAttr(ATTR_TRACKED) )
props |= MutableVal::TRACKED;
if ( props )
{
if ( v->IsMutableVal() )
v->AsMutableVal()->AddProperties(props);
}
#ifndef DEBUG
if ( props )
#else
if ( debug_logger.IsVerbose() || props )
#endif
notifiers.Modified(this);
}
if ( ! weak_ref )
Unref(val);
val = v;
weak_ref = arg_weak_ref;
notifiers.Modified(this);
#ifdef DEBUG
UpdateValID();

View file

@ -46,7 +46,7 @@ public:
// reference to the Val, the Val will be destroyed (naturally,
// you have to take care that it will not be accessed via
// the ID afterwards).
void SetVal(Val* v, Opcode op = OP_ASSIGN, bool weak_ref = false);
void SetVal(Val* v, bool weak_ref = false);
void SetVal(Val* v, init_class c);
void SetVal(Expr* ev, init_class c);

View file

@ -1,23 +0,0 @@
// See the file "COPYING" in the main distribution directory for copyright.
#ifndef op_h
#define op_h
// BRO operations.
typedef enum {
OP_INCR, OP_DECR, OP_NOT, OP_NEGATE,
OP_PLUS, OP_MINUS, OP_TIMES, OP_DIVIDE, OP_MOD,
OP_AND, OP_OR,
OP_LT, OP_LE, OP_EQ, OP_NE, OP_GE, OP_GT,
OP_MATCH,
OP_ASSIGN,
OP_INDEX, OP_FIELD,
OP_IN,
OP_LIST,
OP_CALL,
OP_SCHED,
OP_NAME, OP_CONST, OP_THIS
} BroOP;
#endif

View file

@ -14,19 +14,6 @@ class HashKey;
class ODesc;
class TableVal;
enum Opcode { // Op1 Op2 Op3 (Vals)
OP_NONE,
OP_ASSIGN, // new old
OP_ASSIGN_IDX, // idx new old
OP_ADD, // idx old
OP_INCR, // idx new old
OP_INCR_IDX, // idx new old
OP_DEL, // idx old
OP_PRINT, // args
OP_EXPIRE, // idx
OP_READ_IDX, // idx
};
// We provide a notifier framework to inform interested parties of
// modifications to selected global IDs/Vals. To get notified about a change,
// derive a class from Notifier and register the interesting IDs/Vals with

View file

@ -443,7 +443,7 @@ ID* MutableVal::Bind() const
global_scope()->Insert(name, id);
id->SetVal(const_cast<MutableVal*>(this), OP_NONE, true);
id->SetVal(const_cast<MutableVal*>(this), true);
return id;
}
@ -461,7 +461,7 @@ void MutableVal::TransferUniqueID(MutableVal* mv)
id = new ID(new_name, SCOPE_GLOBAL, true);
id->SetType(const_cast<MutableVal*>(this)->Type()->Ref());
global_scope()->Insert(new_name, id);
id->SetVal(const_cast<MutableVal*>(this), OP_NONE, true);
id->SetVal(const_cast<MutableVal*>(this), true);
Unref(mv->id);
mv->id = 0;
@ -1132,7 +1132,7 @@ void TableVal::CheckExpireAttr(attr_tag at)
}
}
int TableVal::Assign(Val* index, Val* new_val, Opcode op)
int TableVal::Assign(Val* index, Val* new_val)
{
HashKey* k = ComputeHash(index);
if ( ! k )
@ -1142,10 +1142,10 @@ int TableVal::Assign(Val* index, Val* new_val, Opcode op)
return 0;
}
return Assign(index, k, new_val, op);
return Assign(index, k, new_val);
}
int TableVal::Assign(Val* index, HashKey* k, Val* new_val, Opcode op)
int TableVal::Assign(Val* index, HashKey* k, Val* new_val)
{
int is_set = table_type->IsSet();
@ -1227,15 +1227,13 @@ int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const
if ( type->IsSet() )
{
if ( ! t->Assign(v->Value(), k, 0,
propagate_ops ? OP_ASSIGN : OP_NONE) )
if ( ! t->Assign(v->Value(), k, 0) )
return 0;
}
else
{
v->Ref();
if ( ! t->Assign(0, k, v->Value(),
propagate_ops ? OP_ASSIGN : OP_NONE) )
if ( ! t->Assign(0, k, v->Value()) )
return 0;
}
}
@ -1822,7 +1820,7 @@ int TableVal::ExpandCompoundAndInit(val_list* vl, int k, Val* new_val)
return 1;
}
int TableVal::CheckAndAssign(Val* index, Val* new_val, Opcode op)
int TableVal::CheckAndAssign(Val* index, Val* new_val)
{
Val* v = 0;
if ( subnets )
@ -1834,7 +1832,7 @@ int TableVal::CheckAndAssign(Val* index, Val* new_val, Opcode op)
if ( v )
index->Warn("multiple initializations for index");
return Assign(index, new_val, op);
return Assign(index, new_val);
}
void TableVal::InitTimer(double delay)
@ -2219,7 +2217,7 @@ RecordVal::~RecordVal()
delete_vals(AsNonConstRecord());
}
void RecordVal::Assign(int field, Val* new_val, Opcode op)
void RecordVal::Assign(int field, Val* new_val)
{
Val* old_val = AsNonConstRecord()->replace(field, new_val);
Unref(old_val);
@ -2513,7 +2511,7 @@ VectorVal::~VectorVal()
delete val.vector_val;
}
bool VectorVal::Assign(unsigned int index, Val* element, Opcode op)
bool VectorVal::Assign(unsigned int index, Val* element)
{
if ( element &&
! same_type(element->Type(), vector_type->YieldType(), 0) )

View file

@ -840,8 +840,8 @@ public:
// version takes a HashKey and Unref()'s it when done. If we're a
// set, new_val has to be nil. If we aren't a set, index may be nil
// in the second version.
int Assign(Val* index, Val* new_val, Opcode op = OP_ASSIGN);
int Assign(Val* index, HashKey* k, Val* new_val, Opcode op = OP_ASSIGN);
int Assign(Val* index, Val* new_val);
int Assign(Val* index, HashKey* k, Val* new_val);
Val* SizeVal() const override { return val_mgr->GetCount(Size()); }
@ -951,7 +951,7 @@ protected:
void CheckExpireAttr(attr_tag at);
int ExpandCompoundAndInit(val_list* vl, int k, Val* new_val);
int CheckAndAssign(Val* index, Val* new_val, Opcode op = OP_ASSIGN);
int CheckAndAssign(Val* index, Val* new_val);
bool AddProperties(Properties arg_state) override;
bool RemoveProperties(Properties arg_state) override;
@ -995,7 +995,7 @@ public:
Val* SizeVal() const override
{ return val_mgr->GetCount(record_type->NumFields()); }
void Assign(int field, Val* new_val, Opcode op = OP_ASSIGN);
void Assign(int field, Val* new_val);
Val* Lookup(int field) const; // Does not Ref() value.
Val* LookupWithDefault(int field) const; // Does Ref() value.
@ -1095,11 +1095,11 @@ public:
// Note: does NOT Ref() the element! Remember to do so unless
// the element was just created and thus has refcount 1.
//
bool Assign(unsigned int index, Val* element, Opcode op = OP_ASSIGN);
bool Assign(Val* index, Val* element, Opcode op = OP_ASSIGN)
bool Assign(unsigned int index, Val* element);
bool Assign(Val* index, Val* element)
{
return Assign(index->AsListVal()->Index(0)->CoerceToUnsigned(),
element, op);
element);
}
// Assigns the value to how_many locations starting at index.