mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 21:18:20 +00:00
Expr method to invert the sense of a relational
This commit is contained in:
parent
b1e95d68e0
commit
4ee8bd0082
2 changed files with 31 additions and 0 deletions
24
src/Expr.cc
24
src/Expr.cc
|
@ -211,6 +211,11 @@ ExprPtr Expr::MakeLvalue()
|
||||||
return {NewRef{}, this};
|
return {NewRef{}, this};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Expr::InvertSense()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Expr::EvalIntoAggregate(const zeek::Type* /* t */, Val* /* aggr */,
|
void Expr::EvalIntoAggregate(const zeek::Type* /* t */, Val* /* aggr */,
|
||||||
Frame* /* f */) const
|
Frame* /* f */) const
|
||||||
{
|
{
|
||||||
|
@ -2043,6 +2048,12 @@ ValPtr EqExpr::Fold(Val* v1, Val* v2) const
|
||||||
return BinaryExpr::Fold(v1, v2);
|
return BinaryExpr::Fold(v1, v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EqExpr::InvertSense()
|
||||||
|
{
|
||||||
|
tag = (tag == EXPR_EQ ? EXPR_NE : EXPR_EQ);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
RelExpr::RelExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2)
|
RelExpr::RelExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2)
|
||||||
: BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2))
|
: BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2))
|
||||||
{
|
{
|
||||||
|
@ -2100,6 +2111,19 @@ void RelExpr::Canonicize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RelExpr::InvertSense()
|
||||||
|
{
|
||||||
|
switch ( tag ) {
|
||||||
|
case EXPR_LT: tag = EXPR_GE; return true;
|
||||||
|
case EXPR_LE: tag = EXPR_GT; return true;
|
||||||
|
case EXPR_GE: tag = EXPR_LT; return true;
|
||||||
|
case EXPR_GT: tag = EXPR_LE; return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CondExpr::CondExpr(ExprPtr arg_op1, ExprPtr arg_op2, ExprPtr arg_op3)
|
CondExpr::CondExpr(ExprPtr arg_op1, ExprPtr arg_op2, ExprPtr arg_op3)
|
||||||
: Expr(EXPR_COND),
|
: Expr(EXPR_COND),
|
||||||
op1(std::move(arg_op1)), op2(std::move(arg_op2)), op3(std::move(arg_op3))
|
op1(std::move(arg_op1)), op2(std::move(arg_op2)), op3(std::move(arg_op3))
|
||||||
|
|
|
@ -197,6 +197,11 @@ public:
|
||||||
// the current value of expr (this is the default method).
|
// the current value of expr (this is the default method).
|
||||||
virtual ExprPtr MakeLvalue();
|
virtual ExprPtr MakeLvalue();
|
||||||
|
|
||||||
|
// Invert the sense of the operation. Returns true if the expression
|
||||||
|
// was invertible (currently only true for relational/equality
|
||||||
|
// expressions), false otherwise.
|
||||||
|
virtual bool InvertSense();
|
||||||
|
|
||||||
// Marks the expression as one requiring (or at least appearing
|
// Marks the expression as one requiring (or at least appearing
|
||||||
// with) parentheses. Used for pretty-printing.
|
// with) parentheses. Used for pretty-printing.
|
||||||
void MarkParen() { paren = true; }
|
void MarkParen() { paren = true; }
|
||||||
|
@ -791,6 +796,7 @@ public:
|
||||||
ExprPtr Duplicate() override;
|
ExprPtr Duplicate() override;
|
||||||
bool WillTransform(Reducer* c) const override;
|
bool WillTransform(Reducer* c) const override;
|
||||||
ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override;
|
ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override;
|
||||||
|
bool InvertSense() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ValPtr Fold(Val* v1, Val* v2) const override;
|
ValPtr Fold(Val* v1, Val* v2) const override;
|
||||||
|
@ -805,6 +811,7 @@ public:
|
||||||
ExprPtr Duplicate() override;
|
ExprPtr Duplicate() override;
|
||||||
bool WillTransform(Reducer* c) const override;
|
bool WillTransform(Reducer* c) const override;
|
||||||
ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override;
|
ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override;
|
||||||
|
bool InvertSense() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CondExpr final : public Expr {
|
class CondExpr final : public Expr {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue