00001
00004 #ifndef DIVINE_DVE_EXPRESSION_HH
00005 #define DIVINE_DVE_EXPRESSION_HH
00006
00007 #ifndef DOXYGEN_PROCESSING
00008 #include <iostream>
00009 #include <string>
00010 #include <stack>
00011 #include "system/expression.hh"
00012 #include "common/error.hh"
00013 #include "common/types.hh"
00014 #include "common/array.hh"
00015 #include "system/dve/syntax_analysis/dve_commonparse.hh"
00016 #include "system/dve/syntax_analysis/dve_symbol_table.hh"
00017 #include "system/dve/dve_source_position.hh"
00018 #include "common/deb.hh"
00019
00020
00021
00022 namespace divine {
00023 using std::cerr; using std::endl;
00024 #endif //DOXYGEN_PROCESSING
00025
00026 class dve_symbol_table_t;
00027 class dve_parser_t;
00028 class dve_system_t;
00029
00030 const size_int_t DVE_MAXIMAL_ARITY = 2;
00031
00032
00034 struct compacted_viewer_t
00035 {
00036 int size;
00037 int op;
00038 int arity;
00039 int r_offset;
00040 };
00041
00043
00045 struct compacted_t {
00046
00047 mutable compacted_viewer_t * ptr;
00048
00050
00051 std::string to_string();
00052
00054
00056 void create_val(int _op, all_values_t _value) const;
00057
00059
00061 void create_gid(int _op, size_int_t _gid) const;
00062
00064
00067 void join(int _op, compacted_viewer_t* _left, compacted_viewer_t* _right) const;
00068
00070
00071 compacted_viewer_t* last() const
00072 {
00073 if (ptr->arity > 1)
00074 {
00075
00076 return reinterpret_cast<compacted_viewer_t*>((char*)ptr + ptr->r_offset);
00077 }
00078 else
00079 {
00080
00081 return reinterpret_cast<compacted_viewer_t*>((char*)ptr+sizeof(compacted_viewer_t));
00082 }
00083 }
00084
00086
00087 compacted_viewer_t* first() const
00088 {
00089 return reinterpret_cast<compacted_viewer_t*>((char*)ptr+sizeof(compacted_viewer_t));
00090 }
00091
00093
00094 compacted_viewer_t* left() const
00095 {
00096
00097 return reinterpret_cast<compacted_viewer_t*>((char*)ptr+sizeof(compacted_viewer_t));
00098 }
00099
00101
00102 compacted_viewer_t* right() const
00103 {
00104 return reinterpret_cast<compacted_viewer_t*>((char*)ptr+ptr->r_offset);
00105 }
00106
00108
00109 int get_arity() const
00110 {
00111 return ptr->arity;
00112 }
00113
00115
00116 int get_operator() const
00117 {
00118 return ptr->op;
00119 }
00120
00122
00123 all_values_t get_value() const
00124 {
00125 return *((all_values_t*)((char*)ptr + sizeof(compacted_viewer_t)));
00126 }
00127
00129
00130 size_int_t get_gid() const
00131 {
00132 return *((size_int_t*)((char*)ptr + sizeof(compacted_viewer_t)));
00133 }
00134 };
00135
00136
00138
00186 class dve_expression_t: public expression_t, public dve_source_position_t
00187 {
00188 private:
00189 static dve_parser_t expr_parser;
00190 static error_vector_t * pexpr_terr;
00191
00192
00193 int op;
00194 union {
00195 all_values_t value;
00196 size_int_t symbol_gid;
00197 } contain;
00198 array_t<dve_expression_t> subexprs;
00199
00200 compacted_viewer_t *p_compact;
00201
00202 public:
00205 virtual ~dve_expression_t();
00207 virtual void swap(expression_t & expr);
00209 virtual void assign(const expression_t & expr);
00210
00212 virtual std::string to_string() const;
00214 virtual int from_string(std::string & expr_str,
00215 const size_int_t process_gid = NO_ID);
00217 virtual void write(std::ostream & ostr) const;
00219 virtual int read(std::istream & istr, size_int_t process_gid = NO_ID);
00220
00221
00222
00224 dve_expression_t(system_t * const system = 0):
00225 expression_t(system), op(0), subexprs(0,DVE_MAXIMAL_ARITY), p_compact(0)
00226 { DEBFUNC(cerr << "Constructor 1 of dve_expression_t" << endl;) }
00228 dve_expression_t(int expr_op, std::stack<dve_expression_t *> & subexprs_stack, const short int ar = 0, system_t * const system = 0);
00231 dve_expression_t(int expr_op,
00232 const dve_expression_t & expr_left, const dve_expression_t & expr_right,
00233 system_t * const system = 0):
00234 expression_t(system), subexprs(2,DVE_MAXIMAL_ARITY)
00235 { DEBFUNC(cerr << "Constructor 3 of dve_expression_t" << endl;)
00236 subexprs.extend(2);
00237 op = expr_op; left()->assign(expr_left); right()->assign(expr_right);
00238 p_compact=0;
00239 }
00242 dve_expression_t(int expr_op,
00243 const dve_expression_t & expr_left,
00244 system_t * const system = 0):
00245 expression_t(system), subexprs(2,DVE_MAXIMAL_ARITY), p_compact(0)
00246 { DEBFUNC(cerr << "Constructor 4 of dve_expression_t" << endl;)
00247 subexprs.extend(1);
00248 op = expr_op; left()->assign(expr_left);
00249 p_compact=0;
00250 }
00252
00259 dve_expression_t(const std::string & str_expr,
00260 system_t * const system,
00261 size_int_t process_gid = NO_ID);
00263 dve_expression_t(const dve_expression_t & expr):
00264 expression_t(expr),dve_source_position_t(),subexprs(expr.arity(),DVE_MAXIMAL_ARITY)
00265 {
00266 DEBFUNC(cerr << "Constructor 5 of dve_expression_t" << endl;)
00267 assign(expr);
00268 }
00269
00277
00278
00280 void compaction();
00282 bool is_compacted() const { return (p_compact != 0); }
00283
00285 compacted_viewer_t *get_p_compact() const { return (p_compact); };
00286
00289 int get_operator() const { return op; }
00292 void set_operator(const int oper) { op = oper; }
00296 all_values_t get_value() const { return contain.value; }
00300 void set_value(const all_values_t value) { contain.value=value; }
00303
00310 size_int_t get_ident_gid() const { return contain.symbol_gid; }
00313
00320 void set_ident_gid(const size_int_t gid) { contain.symbol_gid=gid; }
00323 size_int_t arity() const { return subexprs.size(); }
00326 void set_arity(const size_int_t new_arity) { subexprs.resize(new_arity); }
00327
00329 dve_symbol_table_t * get_symbol_table() const;
00330
00331
00333 dve_expression_t * left() { return subexprs.last(); }
00335 const dve_expression_t * left() const { return subexprs.last(); }
00337 dve_expression_t * right() { return subexprs.begin(); }
00339 const dve_expression_t * right() const { return subexprs.begin(); }
00341 dve_expression_t * subexpr(size_int_t index) { return &subexprs[index]; }
00343 const dve_expression_t * subexpr(size_int_t index) const
00344 { return &subexprs[index]; }
00347 };
00348
00349 #ifndef DOXYGEN_PROCESSING
00350 }
00351 #include "common/undeb.hh"
00352
00353 #endif //DOXYGEN_PROCESSING
00354
00355 #endif
00356
00357