Skip to content

Commit

Permalink
expr/SelectExpr: add boolean attribute for negating the SelectExpr co…
Browse files Browse the repository at this point in the history
…ndition
  • Loading branch information
vmihalko committed Mar 14, 2024
1 parent b703560 commit ac88b7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions expr/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ bool GepExpr::classof(const Expr* expr) {
return expr->getKind() == EK_GepExpr;
}

SelectExpr::SelectExpr(Expr* comp, Expr* l, Expr* r) :
SelectExpr::SelectExpr(Expr* comp, Expr* l, Expr* r, bool negateCondition = false) :
ExprBase(EK_SelectExpr),
left(l),
right(r),
comp(comp) {
comp(comp)
negateCondition(negateCondition) {
setType(l->getType());
}

Expand Down
3 changes: 2 additions & 1 deletion expr/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ class SelectExpr : public ExprBase {
Expr* left;
Expr* right;
Expr* comp;
bool negateCondition;

SelectExpr(Expr*, Expr*, Expr*);
SelectExpr(Expr*, Expr*, Expr*, bool negateCondition);

void accept(ExprVisitor& visitor) override;

Expand Down
4 changes: 4 additions & 0 deletions writer/ExprWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ void ExprWriter::visit(GepExpr& expr) {
}

void ExprWriter::visit(SelectExpr& expr) {
if (expr.negateCondition)
ss << "!(";
parensIfNotSimple(expr.comp);
if (expr.negateCondition)
ss << ")";
ss << " ? ";
parensIfNotSimple(expr.left);
ss << " : ";
Expand Down

0 comments on commit ac88b7c

Please sign in to comment.