![]() |
libsesstype
2.0.0
Library for Session Types programming.
|
00001 00005 #ifndef SESSTYPE__PARAMETERISED__EXPR__H__ 00006 #define SESSTYPE__PARAMETERISED__EXPR__H__ 00007 00008 #ifdef __cplusplus 00009 #include <ostream> 00010 #include <string> 00011 #include <vector> 00012 #else 00013 #include <stdbool.h> 00014 #include <stdio.h> 00015 #endif 00016 00017 #include "sesstype/util/clonable.h" 00018 00019 #ifdef __cplusplus 00020 namespace sesstype { 00021 namespace parameterised { 00022 namespace util { 00023 00024 class ExprVisitor; 00025 00026 } // namespace util 00027 } // namespace parameterised 00028 } // namespace sesstype 00029 #endif 00030 00031 #ifdef __cplusplus 00032 namespace sesstype { 00033 namespace parameterised { 00034 #endif 00035 00036 #define ST_EXPR_CONST 1 00037 #define ST_EXPR_VAR 2 00038 #define ST_EXPR_ADD 3 00039 #define ST_EXPR_SUB 4 00040 #define ST_EXPR_MUL 5 00041 #define ST_EXPR_DIV 6 00042 #define ST_EXPR_MOD 7 00043 #define ST_EXPR_SHL 8 // << 00044 #define ST_EXPR_SHR 9 // >> 00045 #define ST_EXPR_SEQ 10 // , (Sequence) 00046 #define ST_EXPR_RNG 11 // .. (Range) 00047 #define ST_EXPR_LOG 12 // log(val, base) 00048 00049 #ifdef __cplusplus 00050 00053 class Expr : public sesstype::util::Clonable { 00054 int type_; 00055 00056 public: 00058 virtual ~Expr() { } 00059 00061 virtual Expr *clone() const = 0; 00062 00064 int type() const 00065 { 00066 return type_; 00067 } 00068 00069 friend std::ostream &operator<<(std::ostream &os, Expr &expr); 00070 00071 virtual void accept(util::ExprVisitor &v) = 0; 00072 00073 protected: 00074 Expr(int type) : type_(type) { } 00075 }; 00076 00080 class BinExpr : public Expr { 00081 public: 00083 virtual ~BinExpr() override 00084 { 00085 delete lhs_; 00086 delete rhs_; 00087 } 00088 00090 int op() const 00091 { 00092 return type(); 00093 } 00094 00096 Expr *lhs() const 00097 { 00098 return lhs_; 00099 } 00100 00102 Expr *rhs() const 00103 { 00104 return rhs_; 00105 } 00106 00108 virtual bool is_commutative() const = 0; 00109 00111 virtual bool is_associative() const = 0; 00112 00113 virtual void accept(util::ExprVisitor &v) = 0; 00114 00115 protected: 00117 BinExpr(int op, Expr *lhs, Expr *rhs) 00118 : Expr(op), lhs_(lhs), rhs_(rhs) { } 00119 00120 Expr *lhs_; 00121 Expr *rhs_; 00122 }; 00123 00124 #endif // __cplusplus 00125 00126 #ifdef __cplusplus 00127 extern "C" { 00128 #endif 00129 00130 #ifdef __cplusplus 00131 typedef Expr st_expr; 00132 typedef BinExpr st_bin_expr; 00133 #else 00134 typedef struct Expr st_expr; 00135 typedef struct BinExpr st_bin_expr; 00136 #endif // __cplusplus 00137 00141 st_expr *st_expr_mk_const(int num); 00142 00146 st_expr *st_expr_mk_var(const char *var); 00147 00153 st_expr *st_expr_mk_binary(st_expr *lhs, int type, st_expr *rhs); 00154 00155 00159 st_expr *st_expr_copy(const st_expr *e); 00160 00165 bool st_expr_is_identical(st_expr *e0, st_expr *e1); 00166 00172 st_expr *st_expr_eval(st_expr *const e); 00173 00178 st_expr *st_expr_apply(const st_expr *b, const st_expr *e); 00179 00185 st_expr *st_expr_inv(const st_expr *e); 00186 00189 void st_expr_free(st_expr *e); 00190 00191 #ifdef __cplusplus 00192 } // extern "C" 00193 #endif 00194 00195 #ifdef __cplusplus 00196 } // namespace parameterised 00197 } // namespace sesstype 00198 #endif 00199 00200 #endif//SESSTYPE__PARAMETERISED__EXPR__H__