4 #ifndef ILANG_ILA_AST_EXPR_H__
5 #define ILANG_ILA_AST_EXPR_H__
10 #include <unordered_map>
11 #include <unordered_set>
25 class Expr :
public Ast,
public std::enable_shared_from_this<Expr> {
49 inline size_t arg_num()
const {
return args_.size(); }
51 inline ExprPtr arg(
const size_t& i)
const {
return args_.at(i); }
53 inline size_t param_num()
const {
return params_.size(); }
55 inline int param(
const size_t& i)
const {
return params_.at(i); }
62 void set_params(
const std::vector<int> params);
72 virtual bool is_const()
const {
return false; }
74 virtual bool is_var()
const {
return false; }
76 virtual bool is_op()
const {
return false; }
79 inline bool is_bool()
const {
return sort_->is_bool(); }
81 inline bool is_bv(
const int& width = 0)
const {
return sort_->is_bv(width); }
83 inline bool is_mem()
const {
return sort_->is_mem(); }
88 const std::string& suffix =
"")
const = 0;
91 virtual std::ostream&
Print(std::ostream& out)
const = 0;
95 return expr->Print(out);
101 for (
size_t i = 0; i !=
arg_num(); i++) {
102 auto arg_i = this->
arg(i);
103 arg_i->DepthFirstVisit<F>(func);
105 func(shared_from_this());
112 if (func.pre(shared_from_this())) {
116 for (
size_t i = 0; i !=
arg_num(); i++) {
117 auto arg_i = this->
arg(i);
118 arg_i->DepthFirstVisitPrePost<F>(func);
121 func.post(shared_from_this());
131 std::vector<int> params_;
151 typedef std::unordered_map<const ExprPtr, const ExprPtr, ExprHash>
ExprMap;
153 typedef std::unordered_set<ExprPtr, ExprHash>
ExprSet;
157 #endif // ILANG_ILA_AST_EXPR_H__
Expr()
Default constructor.
std::shared_ptr< Expr > ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:28
bool is_expr() const
Is type expr (object).
Definition: expr.h:69
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
size_t param_num() const
Return the number of parameters.
Definition: expr.h:53
The class for expression, which is the basic type for variables, constraints, state update expression...
Definition: expr.h:25
ExprPtr arg(const size_t &i) const
Return the i-th argument.
Definition: expr.h:51
Sort::SortPtr SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:82
void set_params(const std::vector< int > params)
Set the parameters.
const SortPtr sort() const
Return the pointer of the sort.
Definition: expr.h:47
The function object for hashing Expr. The hash value is the id of the symbol, which is supposed to be...
Definition: expr.h:144
std::vector< z3::expr > Z3ExprVec
Vector type for z3 expression.
Definition: defines.h:19
std::unordered_set< ExprPtr, ExprHash > ExprSet
Type for storing a set of Expr.
Definition: expr.h:153
size_t operator()(const ExprPtr &expr) const
Function object for hashing.
Definition: expr.h:147
std::vector< ExprPtr > ExprPtrVec
Type for storing a set of Expr.
Definition: expr.h:30
bool is_bv(const int &width=0) const
Return true if this is a Bitvector expression.
Definition: expr.h:81
int param(const size_t &i) const
Return the i-th paramter.
Definition: expr.h:55
void DepthFirstVisitPrePost(F &func)
Templated visitor: visit each node in a depth-first order and apply the function object F pre/pose on...
Definition: expr.h:110
std::vector< z3::expr > Z3ExprVec
Vector type for z3 expression.
Definition: expr.h:34
virtual z3::expr GetZ3Expr(z3::context &z3_ctx, const Z3ExprVec &z3expr_vec, const std::string &suffix="") const =0
Return the z3 expression for the node.
void DepthFirstVisit(F &func)
Templated visitor: visit each node in a depth-first order and apply the function object F on it...
Definition: expr.h:100
The class for the Abstract Syntax Tree. An Ast object can be an expression or function definition (in...
Definition: ast.h:20
virtual bool is_op() const
Return true if this is an operation.
Definition: expr.h:76
std::unordered_map< const ExprPtr, const ExprPtr, ExprHash > ExprMap
Type for mapping between Expr.
Definition: expr.h:151
virtual bool is_var() const
Return true if this is a variable.
Definition: expr.h:74
Expr::ExprPtrVec ExprPtrVec
Type for storing a set of Expr.
Definition: expr.h:140
friend std::ostream & operator<<(std::ostream &out, const ExprPtr &expr)
Overload output stream operator for pointer.
Definition: expr.h:94
void replace_arg(const int &idx, const ExprPtr &arg)
Replace the i-th argument.
void set_args(const ExprPtrVec &args)
Set the arguments.
size_t arg_num() const
Retrun the number of argument (arity).
Definition: expr.h:49
void set_sort(const SortPtr sort)
Set the sort of the expression.
virtual bool is_const() const
Return true if this is a constant.
Definition: expr.h:72
bool is_mem() const
Return true if this is an Array expression.
Definition: expr.h:83
bool is_bool() const
Return true if this is a Boolean expression.
Definition: expr.h:79
virtual std::ostream & Print(std::ostream &out) const =0
Output to stream.
virtual ~Expr()
Default destructor.
const Symbol & name() const
Get the symbol (name).