00001
00004 #ifndef DIVINE_DVE_SYSTEM_HH
00005 #define DIVINE_DVE_SYSTEM_HH
00006
00007 #ifndef DOXYGEN_PROCESSING
00008 #include <fstream>
00009 #include "system/system.hh"
00010 #include "system/dve/syntax_analysis/dve_parser.hh"
00011 #include "system/dve/syntax_analysis/dve_symbol_table.hh"
00012 #include "system/dve/dve_expression.hh"
00013 #include "common/array.hh"
00014 #include "common/error.hh"
00015
00016
00017 namespace divine {
00018 #endif //DOXYGEN_PROCESSING
00019
00023 enum system_synchronicity_t { SYSTEM_SYNC = 0, SYSTEM_ASYNC = 1 };
00024
00026
00033 union SYS_initial_values_t
00034 {
00035 all_values_t all_value;
00036 all_values_t * all_values;
00037 size_int_t size_t_value;
00038
00039 };
00040
00043
00044
00045
00046 struct SYS_parameters_t
00047 {
00048 SYS_initial_values_t * initial_values;
00049 size_int_t * initial_states;
00050 size_int_t * initial_values_counts;
00051
00052 size_int_t * state_lids;
00053
00054 SYS_parameters_t(SYS_initial_values_t * const initial_vals,
00055 size_int_t * const init_st,
00056 size_int_t * const initial_vals_counts,
00057 size_int_t * const st_lids):
00058 initial_values(initial_vals),initial_states(init_st),initial_values_counts(initial_vals_counts), state_lids(st_lids) {}
00059 };
00060
00061 typedef SYS_parameters_t * SYS_p_parameters_t;
00062
00064
00097 class dve_system_t: virtual public system_t
00098 {
00099 private:
00100 struct expr_stack_element_t
00101 {
00102 const dve_expression_t * expr;
00103 array_t<dve_expression_t>::const_iterator ar;
00104 expr_stack_element_t(const dve_expression_t * const expr_pointer,
00105 array_t<dve_expression_t>::const_iterator ar_arg):
00106 expr(expr_pointer),
00107 ar(ar_arg) {}
00108 void inc_ar() { ar++; }
00109 };
00110
00111 struct expr_compacted_stack_element_t
00112 {
00113 mutable void* expr;
00114 void *ar;
00115 expr_compacted_stack_element_t(void * _expr, void* _ar):
00116 expr(_expr),
00117 ar(_ar) {}
00118
00119 };
00120
00121
00122 array_t<dve_transition_t *> transitions;
00123 size_int_t * channel_freq_ask;
00124 size_int_t * channel_freq_answ;
00125 size_int_t * global_variable_gids;
00126
00127 mutable std::vector<expr_stack_element_t> estack;
00128 mutable std::vector<expr_compacted_stack_element_t> estack_compacted;
00129 mutable std::vector<all_values_t> vstack;
00130
00131
00132 void consolidate();
00133
00134 void delete_fields();
00135
00136 protected:
00137 dve_symbol_table_t * psymbol_table;
00138
00139
00140 array_t<dve_process_t *> processes;
00141 size_int_t process_field_size;
00142 size_int_t channel_count;
00143 size_int_t var_count;
00144 size_int_t state_count;
00145 size_int_t glob_var_count;
00146
00147 system_synchronicity_t system_synchro;
00148 size_int_t prop_gid;
00149 dve_process_t * pproperty;
00150 bool property_has_synchronization;
00151
00153 const size_int_t MAX_INIT_VALUES_SIZE;
00154
00156 SYS_initial_values_t * initial_values;
00158
00166 size_int_t * initial_values_counts;
00167 size_int_t * initial_states;
00168 size_int_t * state_lids;
00170 dve_var_type_t * var_types;
00171 bool * constants;
00172
00173
00176 void * parameters;
00177
00180 all_values_t (*eval_id)
00181 (const void * parameters, const dve_expression_t & expr, bool & eval_err);
00182 all_values_t (*eval_id_compact)
00183 (const void * parameters, const size_int_t & gid, bool & eval_err);
00186 all_values_t (*eval_square_bracket)
00187 (const void * parameters, const dve_expression_t & subexpr,
00188 const size_int_t & array_index, bool & eval_err);
00189 all_values_t (*eval_square_bracket_compact)
00190 (const void * parameters, const size_int_t & gid,
00191 const size_int_t & array_index, bool & eval_err);
00194 all_values_t (*eval_dot)
00195 (const void * parameters, const dve_expression_t & subexpr, bool & eval_err);
00196 all_values_t (*eval_dot_compact)
00197 (const void * parameters, const dve_symbol_table_t *symbol_table, const size_int_t & gid, bool & eval_err);
00199
00205 all_values_t eval_expr(const dve_expression_t * const expr, bool & eval_err) const;
00207
00213 all_values_t fast_eval(compacted_viewer_t *p_compacted, bool &eval_err) const;
00214
00215 public:
00217
00220 dve_system_t(error_vector_t & evect = gerr);
00222 virtual ~dve_system_t();
00225
00226 virtual slong_int_t read(std::istream & ins = std::cin);
00228 virtual slong_int_t read(const char * const filename);
00230 virtual slong_int_t from_string(const std::string str);
00232 virtual bool write(const char * const filename);
00234 virtual void write(std::ostream & outs = std::cout);
00236 virtual std::string to_string();
00239
00240
00246 virtual int get_property_scc_id(state_t& _state) const
00247 {
00248 if ((_state.ptr) || !(_state.ptr))
00249 {
00250 gerr<<"dve_system_t::get_property_scc_id not implemented"<<thr();
00251 }
00252 return 0;
00253 }
00254
00258 virtual int get_property_scc_type(int _scc) const
00259 {
00260 if ((_scc) || !(_scc))
00261 {
00262 gerr<<"dve_system_t::get_property_scc_type not implemented"<<thr();
00263 }
00264 return 0;
00265 }
00266
00267
00271 virtual int get_property_scc_type(state_t& _state) const
00272 {
00273 if ((_state.ptr) || !(_state.ptr))
00274 {
00275 gerr<<"dve_system_t::get_property_scc_type not implemented"<<thr();
00276 }
00277 return 0;
00278 }
00279
00281 virtual int get_property_scc_count() const
00282 {
00283 gerr<<"dve_system_t::get_property_scc_count not implemented"<<thr();
00284 return 0;
00285 }
00286
00288 virtual bool is_property_weak() const
00289 {
00290 gerr<<"dve_system_t::is_property_weak not implemented"<<thr();
00291 return 0;
00292 }
00296
00297
00300
00301 virtual process_t * get_property_process() { return pproperty; }
00303 virtual const process_t * get_property_process() const { return pproperty; }
00305 virtual size_int_t get_property_gid() const { return prop_gid; }
00307 virtual void set_property_gid(const size_int_t gid);
00309 virtual property_type_t get_property_type()
00310 {
00311 if (get_with_property())
00312 return (dynamic_cast<dve_process_t *>(get_property_process()))->get_accepting_type();
00313 else
00314 return NONE;
00315 }
00319
00320
00323
00324 virtual size_int_t get_process_count() const
00325 { return processes.size(); }
00327 virtual process_t * get_process(const size_int_t gid)
00328 { return processes[gid]; }
00330 virtual const process_t * get_process(const size_int_t id) const
00331 { return processes[id]; }
00335
00336
00339
00340
00341
00344 virtual size_int_t get_trans_count() const { return transitions.size(); }
00346 virtual transition_t * get_transition(size_int_t gid)
00347 { return transitions[gid]; }
00349 virtual const transition_t * get_transition(size_int_t gid) const
00350 { return transitions[gid]; }
00353
00354
00357
00358
00359
00364 virtual void add_process(process_t * const process);
00366 virtual void remove_process(const size_int_t process_id);
00369
00370
00375
00376 bool get_property_with_synchro() const { return property_has_synchronization;}
00377
00379
00381 void set_property_with_synchro(const bool contains_synchro)
00382 { property_has_synchronization = contains_synchro; }
00383
00385 size_int_t get_channel_freq(size_int_t ch_gid) const
00386 { return (channel_freq_ask[ch_gid] + channel_freq_answ[ch_gid]); }
00389 size_int_t get_channel_freq_ask(size_int_t ch_gid) const
00390 { return (channel_freq_answ[ch_gid]); }
00393 size_int_t get_channel_freq_exclaim(size_int_t ch_gid) const
00394 { return (channel_freq_ask[ch_gid]); }
00396
00402 dve_symbol_table_t * get_symbol_table() const { return psymbol_table; }
00404 size_int_t get_channel_count() const { return channel_count; }
00406
00409 system_synchronicity_t get_system_synchro() const { return system_synchro; }
00411 void set_system_synchro(const system_synchronicity_t sync)
00412 { system_synchro = sync; }
00414
00417 size_int_t get_global_variable_gid(const size_int_t i) const
00418 { return global_variable_gids[i]; }
00420 size_int_t get_global_variable_count() const
00421 { return glob_var_count; }
00423 bool not_in_limits(dve_var_type_t var_type, all_values_t value);
00425
00426 void DBG_print_all_initialized_variables();
00428 };
00429
00430 #ifndef DOXYGEN_PROCESSING
00431 }
00432 #endif //DOXYGEN_PROCESSING
00433
00434 #endif