Expr: Convert a bunch of methods returning ints to return bools

This commit is contained in:
Tim Wojtulewicz 2020-02-27 13:15:08 -07:00
parent e3ecaa1297
commit 1d9968d393
3 changed files with 78 additions and 78 deletions

View file

@ -69,14 +69,14 @@ Expr::~Expr()
Unref(type);
}
int Expr::CanAdd() const
bool Expr::CanAdd() const
{
return 0;
return false;
}
int Expr::CanDel() const
bool Expr::CanDel() const
{
return 0;
return false;
}
void Expr::Add(Frame* /* f */)
@ -113,14 +113,14 @@ BroType* Expr::InitType() const
return type->Ref();
}
int Expr::IsRecordElement(TypeDecl* /* td */) const
bool Expr::IsRecordElement(TypeDecl* /* td */) const
{
return 0;
return false;
}
int Expr::IsPure() const
bool Expr::IsPure() const
{
return 1;
return true;
}
Val* Expr::InitVal(const BroType* t, Val* aggr) const
@ -137,7 +137,7 @@ Val* Expr::InitVal(const BroType* t, Val* aggr) const
return check_and_promote(Eval(0), t, 1);
}
int Expr::IsError() const
bool Expr::IsError() const
{
return type && type->Tag() == TYPE_ERROR;
}
@ -153,12 +153,12 @@ void Expr::SetError(const char* msg)
SetError();
}
int Expr::IsZero() const
bool Expr::IsZero() const
{
return IsConst() && ExprVal()->IsZero();
}
int Expr::IsOne() const
bool Expr::IsOne() const
{
return IsConst() && ExprVal()->IsOne();
}
@ -295,7 +295,7 @@ void NameExpr::Assign(Frame* f, Val* v)
f->SetElement(id, v);
}
int NameExpr::IsPure() const
bool NameExpr::IsPure() const
{
return id->IsConst();
}
@ -414,7 +414,7 @@ Val* UnaryExpr::Eval(Frame* f) const
}
}
int UnaryExpr::IsPure() const
bool UnaryExpr::IsPure() const
{
return op->IsPure();
}
@ -551,7 +551,7 @@ Val* BinaryExpr::Eval(Frame* f) const
return result;
}
int BinaryExpr::IsPure() const
bool BinaryExpr::IsPure() const
{
return op1->IsPure() && op2->IsPure();
}
@ -604,20 +604,20 @@ Val* BinaryExpr::Fold(Val* v1, Val* v2) const
bro_int_t i1 = 0, i2 = 0, i3 = 0;
bro_uint_t u1 = 0, u2 = 0, u3 = 0;
double d1 = 0.0, d2 = 0.0, d3 = 0.0;
int is_integral = 0;
int is_unsigned = 0;
bool is_integral = false;
bool is_unsigned = false;
if ( it == TYPE_INTERNAL_INT )
{
i1 = v1->InternalInt();
i2 = v2->InternalInt();
++is_integral;
is_integral = true;
}
else if ( it == TYPE_INTERNAL_UNSIGNED )
{
u1 = v1->InternalUnsigned();
u2 = v2->InternalUnsigned();
++is_unsigned;
is_unsigned = true;
}
else if ( it == TYPE_INTERNAL_DOUBLE )
{
@ -858,7 +858,7 @@ Val* BinaryExpr::AddrFold(Val* v1, Val* v2) const
{
IPAddr a1 = v1->AsAddr();
IPAddr a2 = v2->AsAddr();
int result = 0;
bool result = false;
switch ( tag ) {
@ -893,7 +893,7 @@ Val* BinaryExpr::SubNetFold(Val* v1, Val* v2) const
const IPPrefix& n1 = v1->AsSubNet();
const IPPrefix& n2 = v2->AsSubNet();
bool result = ( n1 == n2 ) ? true : false;
bool result = n1 == n2;
if ( tag == EXPR_NE )
result = ! result;
@ -1053,9 +1053,9 @@ Val* IncrExpr::Eval(Frame* f) const
}
}
int IncrExpr::IsPure() const
bool IncrExpr::IsPure() const
{
return 0;
return false;
}
ComplementExpr::ComplementExpr(Expr* arg_op) : UnaryExpr(EXPR_COMPLEMENT, arg_op)
@ -1605,8 +1605,8 @@ Val* BoolExpr::Eval(Frame* f) const
if ( ! v1 )
return 0;
int is_vec1 = is_vector(op1);
int is_vec2 = is_vector(op2);
bool is_vec1 = is_vector(op1);
bool is_vec2 = is_vector(op2);
// Handle scalar op scalar
if ( ! is_vec1 && ! is_vec2 )
@ -2044,7 +2044,7 @@ Val* CondExpr::Eval(Frame* f) const
return result;
}
int CondExpr::IsPure() const
bool CondExpr::IsPure() const
{
return op1->IsPure() && op2->IsPure() && op3->IsPure();
}
@ -2499,7 +2499,7 @@ Val* AssignExpr::InitVal(const BroType* t, Val* aggr) const
}
}
int AssignExpr::IsRecordElement(TypeDecl* td) const
bool AssignExpr::IsRecordElement(TypeDecl* td) const
{
if ( op1->Tag() == EXPR_NAME )
{
@ -2510,15 +2510,15 @@ int AssignExpr::IsRecordElement(TypeDecl* td) const
td->id = copy_string(n->Id()->Name());
}
return 1;
}
else
return 0;
return true;
}
int AssignExpr::IsPure() const
return false;
}
bool AssignExpr::IsPure() const
{
return 0;
return false;
}
IndexSliceAssignExpr::IndexSliceAssignExpr(Expr* op1, Expr* op2, int is_init)
@ -2595,19 +2595,19 @@ IndexExpr::IndexExpr(Expr* arg_op1, ListExpr* arg_op2, bool arg_is_slice)
}
int IndexExpr::CanAdd() const
bool IndexExpr::CanAdd() const
{
if ( IsError() )
return 1; // avoid cascading the error report
return true; // avoid cascading the error report
// "add" only allowed if our type is "set".
return op1->Type()->IsSet();
}
int IndexExpr::CanDel() const
bool IndexExpr::CanDel() const
{
if ( IsError() )
return 1; // avoid cascading the error report
return true; // avoid cascading the error report
return op1->Type()->Tag() == TYPE_TABLE;
}
@ -2993,7 +2993,7 @@ Expr* FieldExpr::MakeLvalue()
return new RefExpr(this);
}
int FieldExpr::CanDel() const
bool FieldExpr::CanDel() const
{
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
}
@ -3553,7 +3553,7 @@ void FieldAssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f)
}
}
int FieldAssignExpr::IsRecordElement(TypeDecl* td) const
bool FieldAssignExpr::IsRecordElement(TypeDecl* td) const
{
if ( td )
{
@ -3561,7 +3561,7 @@ int FieldAssignExpr::IsRecordElement(TypeDecl* td) const
td->id = copy_string(field_name.c_str());
}
return 1;
return true;
}
void FieldAssignExpr::ExprDescribe(ODesc* d) const
@ -4028,9 +4028,9 @@ ScheduleExpr::~ScheduleExpr()
Unref(event);
}
int ScheduleExpr::IsPure() const
bool ScheduleExpr::IsPure() const
{
return 0;
return false;
}
Val* ScheduleExpr::Eval(Frame* f) const
@ -4304,7 +4304,7 @@ CallExpr::~CallExpr()
Unref(args);
}
int CallExpr::IsPure() const
bool CallExpr::IsPure() const
{
if ( IsError() )
return 1;
@ -4614,22 +4614,22 @@ void ListExpr::Append(Expr* e)
((TypeList*) type)->Append(e->Type()->Ref());
}
int ListExpr::IsPure() const
bool ListExpr::IsPure() const
{
for ( const auto& expr : exprs )
if ( ! expr->IsPure() )
return 0;
return false;
return 1;
return true;
}
int ListExpr::AllConst() const
bool ListExpr::AllConst() const
{
for ( const auto& expr : exprs )
if ( ! expr->IsConst() )
return 0;
return false;
return 1;
return true;
}
Val* ListExpr::Eval(Frame* f) const
@ -5321,7 +5321,7 @@ val_list* eval_list(Frame* f, const ListExpr* l)
return v;
}
int expr_greater(const Expr* e1, const Expr* e2)
bool expr_greater(const Expr* e1, const Expr* e2)
{
return int(e1->Tag()) > int(e2->Tag());
return e1->Tag() > e2->Tag();
}

View file

@ -102,7 +102,7 @@ public:
// constitutes a record element, false otherwise. If the TypeDecl*
// is non-nil and the expression is a record element, fills in the
// TypeDecl with a description of the element.
virtual int IsRecordElement(TypeDecl* td) const;
virtual bool IsRecordElement(TypeDecl* td) const;
// Returns a value corresponding to this expression interpreted
// as an initialization, or nil if the expression is inconsistent
@ -112,13 +112,13 @@ public:
virtual Val* InitVal(const BroType* t, Val* aggr) const;
// True if the expression has no side effects, false otherwise.
virtual int IsPure() const;
virtual bool IsPure() const;
// True if the expression is a constant, false otherwise.
int IsConst() const { return tag == EXPR_CONST; }
bool IsConst() const { return tag == EXPR_CONST; }
// True if the expression is in error (to alleviate error propagation).
int IsError() const;
bool IsError() const;
// Mark expression as in error.
void SetError();
@ -129,15 +129,15 @@ public:
inline Val* ExprVal() const;
// True if the expression is a constant zero, false otherwise.
int IsZero() const;
bool IsZero() const;
// True if the expression is a constant one, false otherwise.
int IsOne() const;
bool IsOne() const;
// True if the expression supports the "add" or "delete" operations,
// false otherwise.
virtual int CanAdd() const;
virtual int CanDel() const;
virtual bool CanAdd() const;
virtual bool CanDel() const;
virtual void Add(Frame* f); // perform add operation
virtual void Delete(Frame* f); // perform delete operation
@ -149,8 +149,8 @@ public:
// Marks the expression as one requiring (or at least appearing
// with) parentheses. Used for pretty-printing.
void MarkParen() { paren = 1; }
int IsParen() const { return paren; }
void MarkParen() { paren = true; }
bool IsParen() const { return paren; }
const ListExpr* AsListExpr() const
{
@ -227,7 +227,7 @@ protected:
BroExprTag tag;
BroType* type;
int paren;
bool paren;
};
class NameExpr : public Expr {
@ -240,7 +240,7 @@ public:
Val* Eval(Frame* f) const override;
void Assign(Frame* f, Val* v) override;
Expr* MakeLvalue() override;
int IsPure() const override;
bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
@ -276,7 +276,7 @@ public:
// vectors correctly as necessary.
Val* Eval(Frame* f) const override;
int IsPure() const override;
bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
@ -297,7 +297,7 @@ public:
Expr* Op1() const { return op1; }
Expr* Op2() const { return op2; }
int IsPure() const override;
bool IsPure() const override;
// BinaryExpr::Eval correctly handles vector types. Any child
// class that overrides Eval() should be modified to handle
@ -366,7 +366,7 @@ public:
Val* Eval(Frame* f) const override;
Val* DoSingleEval(Frame* f, Val* v) const;
int IsPure() const override;
bool IsPure() const override;
};
class ComplementExpr : public UnaryExpr {
@ -490,7 +490,7 @@ public:
const Expr* Op3() const { return op3; }
Val* Eval(Frame* f) const override;
int IsPure() const override;
bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
@ -520,9 +520,9 @@ public:
Val* Eval(Frame* f) const override;
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
BroType* InitType() const override;
int IsRecordElement(TypeDecl* td) const override;
bool IsRecordElement(TypeDecl* td) const override;
Val* InitVal(const BroType* t, Val* aggr) const override;
int IsPure() const override;
bool IsPure() const override;
protected:
bool TypeCheck(attr_list* attrs = 0);
@ -542,8 +542,8 @@ class IndexExpr : public BinaryExpr {
public:
IndexExpr(Expr* op1, ListExpr* op2, bool is_slice = false);
int CanAdd() const override;
int CanDel() const override;
bool CanAdd() const override;
bool CanDel() const override;
void Add(Frame* f) override;
void Delete(Frame* f) override;
@ -575,7 +575,7 @@ public:
int Field() const { return field; }
const char* FieldName() const { return field_name; }
int CanDel() const override;
bool CanDel() const override;
void Assign(Frame* f, Val* v) override;
void Delete(Frame* f) override;
@ -677,7 +677,7 @@ public:
const char* FieldName() const { return field_name.c_str(); }
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
int IsRecordElement(TypeDecl* td) const override;
bool IsRecordElement(TypeDecl* td) const override;
protected:
void ExprDescribe(ODesc* d) const override;
@ -758,7 +758,7 @@ public:
ScheduleExpr(Expr* when, EventExpr* event);
~ScheduleExpr() override;
int IsPure() const override;
bool IsPure() const override;
Val* Eval(Frame* f) const override;
@ -791,7 +791,7 @@ public:
Expr* Func() const { return func; }
ListExpr* Args() const { return args; }
int IsPure() const override;
bool IsPure() const override;
Val* Eval(Frame* f) const override;
@ -861,10 +861,10 @@ public:
expr_list& Exprs() { return exprs; }
// True if the entire list represents pure values.
int IsPure() const override;
bool IsPure() const override;
// True if the entire list represents constant values.
int AllConst() const;
bool AllConst() const;
Val* Eval(Frame* f) const override;
@ -943,7 +943,7 @@ val_list* eval_list(Frame* f, const ListExpr* l);
// Returns true if e1 is "greater" than e2 - here "greater" is just
// a heuristic, used with commutative operators to put them into
// a canonical form.
extern int expr_greater(const Expr* e1, const Expr* e2);
extern bool expr_greater(const Expr* e1, const Expr* e2);
// True if the given Val* has a vector type
inline bool is_vector(Expr* e) { return e->Type()->Tag() == TYPE_VECTOR; }

View file

@ -301,12 +301,12 @@ public:
return (TypeType*) this;
}
int IsSet() const
bool IsSet() const
{
return tag == TYPE_TABLE && (YieldType() == 0);
}
int IsTable() const
bool IsTable() const
{
return tag == TYPE_TABLE && (YieldType() != 0);
}