00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #ifndef _SEMANTICS_H_
00029 #define _SEMANTICS_H_
00030
00031 #include <stdint.h>
00032 #if defined(COCONUT_WINDOWS)
00033 #include <msc_stdint.h>
00034 #endif
00035 #include <string>
00036 #include <fstream>
00037 #include <iostream>
00038 #include <coconut_types.h>
00039
00040 namespace coco {
00041
00043
00045 typedef enum {
00046 c_convex=1,
00047 c_linear=0,
00048 c_concave=-1,
00049 c_maybe=2
00054 } convex_info;
00055
00057
00059 typedef enum {
00060 v_exists=0,
00062 v_forall=1,
00064 v_free=2,
00066 v_stochastic=3
00067 } type_annotation;
00068
00070
00094 typedef enum { a_redundant=1,
00095 a_active_lo=2, a_active_lo_red=a_active_lo|a_redundant,
00096 a_active_hi=4, a_active_hi_red=a_active_hi|a_redundant,
00097 a_active=a_active_lo|a_active_hi,
00098 a_active_red=a_active|a_redundant } activity_descr;
00099
00101
00106 class convex_e
00107 {
00108 private:
00110 convex_info e;
00113 uint16_t tested;
00114 public:
00116 convex_e() : e(c_maybe), tested(0) {}
00119 convex_e(const convex_info& __e, uint16_t __t) : e(__e), tested(__t) {}
00121 convex_e(const convex_e& __e) : e(__e.e), tested(__e.tested) {}
00124 explicit convex_e(int16_t __e) : tested(0) { e = (convex_info)__e; }
00125
00127 ~convex_e() {}
00128
00130 const convex_info& i() const { return e; }
00132 uint16_t t() const { return tested; }
00133
00137 convex_e operator-() const
00138 {
00139 convex_e __tmp;
00140 if(e == c_convex)
00141 __tmp.e = c_concave;
00142 else if(e == c_concave)
00143 __tmp.e = c_convex;
00144 else
00145 __tmp.e = e;
00146 return __tmp;
00147 }
00148
00150 convex_e& operator=(const convex_e& __c)
00151 {
00152 e = __c.e;
00153 tested = __c.tested;
00154 return *this;
00155 }
00156
00158 convex_e& operator=(const convex_info& __i)
00159 {
00160 e = __i;
00161 return *this;
00162 }
00163
00165 convex_e& operator=(unsigned int __t)
00166 {
00167 tested = (uint16_t) __t;
00168 return *this;
00169 }
00170
00172 convex_e& operator=(uint16_t __t)
00173 {
00174 tested = __t;
00175 return *this;
00176 }
00177
00179 void read(char *c);
00180
00182 void merge(const convex_e& __c)
00183 {
00184 if(e == __c.e)
00185 {
00186 if(tested < __c.tested)
00187 tested = __c.tested;
00188 }
00189 else
00190 {
00191 if(tested < __c.tested)
00192 *this = __c;
00193 else if(tested == __c.tested)
00194 e = c_maybe;
00195 }
00196 }
00197
00198 friend bool operator==(const convex_e& __c, const convex_e& __d);
00199 friend bool operator==(const convex_e& __c, const convex_info& __d);
00200 friend bool operator==(const convex_info& __c, const convex_e& __d);
00201 friend bool operator!=(const convex_e& __c, const convex_e& __d);
00202 friend bool operator!=(const convex_e& __c, const convex_info& __d);
00203 friend bool operator!=(const convex_info& __c, const convex_e& __d);
00204 friend std::ostream& operator<< (std::ostream& o, const convex_e& __s);
00205 };
00206
00208
00210 inline bool operator==(const convex_e& __c, const convex_e& __d)
00211 {
00212 return __c.e == __d.e;
00213 }
00214
00216
00218 inline bool operator==(const convex_e& __c, const convex_info& __d)
00219 {
00220 return __c.e == __d;
00221 }
00222
00224
00226 inline bool operator==(const convex_info& __c, const convex_e& __d)
00227 {
00228 return __c == __d.e;
00229 }
00230
00232
00234 inline bool operator!=(const convex_e& __c, const convex_e& __d)
00235 {
00236 return __c.e != __d.e;
00237 }
00238
00240
00242 inline bool operator!=(const convex_e& __c, const convex_info& __d)
00243 {
00244 return __c.e != __d;
00245 }
00246
00248
00250 inline bool operator!=(const convex_info& __c, const convex_e& __d)
00251 {
00252 return __c != __d.e;
00253 }
00254
00256
00258 inline std::ostream& operator<< (std::ostream& o, const convex_e& __s)
00259 {
00260 char c[5] = "VLXM";
00261 o << c[__s.e+1] << __s.tested;
00262 return o;
00263 }
00264
00266
00271 class semantics
00272 {
00273 public:
00275 struct {
00276 convex_e c_info;
00277 activity_descr act;
00278 tristate separable;
00279 bool is_at_either_bound;
00281 } property_flags;
00282
00284 struct {
00285 bool kj;
00286 bool integer;
00287 type_annotation type;
00288 bool hard;
00289 } annotation_flags;
00290
00292 struct {
00293 tristate has_0chnbase;
00294 } info_flags;
00295
00298 unsigned int _0chnbase;
00299
00302 int addinfo;
00303
00306 int degree;
00309 int dim;
00312 int stage;
00313 public:
00315 semantics();
00316
00318 semantics(const semantics& __s) : property_flags(__s.property_flags),
00319 annotation_flags(__s.annotation_flags),
00320 info_flags(__s.info_flags),
00321 _0chnbase(__s._0chnbase),
00322 addinfo(__s.addinfo), degree(__s.degree),
00323 dim(__s.dim), stage(__s.stage) {}
00324
00326 ~semantics() {}
00327
00328 friend std::ostream& operator<< (std::ostream& o, const semantics& __s);
00329
00330 private:
00332 const char* print_tristate(const tristate& x) const;
00334 tristate read_tristate(char c) const;
00336 const char* print_type_annotation(const type_annotation& x) const;
00339 type_annotation read_type_annotation(char c) const;
00341 const char* print_activity_descr(const activity_descr& x) const;
00344 activity_descr read_activity_descr(char c) const;
00345
00347 void merge_tristate(tristate& __o, const tristate& __n);
00348
00350 void merge_type_annotation(type_annotation& __o, const type_annotation& __n);
00351
00353 void merge_activity_descr(activity_descr& __o, const activity_descr& __n);
00354
00355 public:
00358 void read(char *c);
00359
00361 void merge(const semantics& __s);
00362
00363 public:
00370 const convex_e& convexity() const { return property_flags.c_info; }
00373 void convexity(const convex_e& __c) { property_flags.c_info = __c; }
00374
00377 const tristate& separability() const { return property_flags.separable; }
00380 void separability(const tristate& __c) { property_flags.separable = __c; }
00381
00384 const activity_descr& activity() const { return property_flags.act; }
00387 void activity(const activity_descr& __c) { property_flags.act = __c; }
00388
00391 bool kj_flag() const { return annotation_flags.kj; }
00394 void kj_flag(bool __c) { annotation_flags.kj = __c; }
00395
00398 bool integer_flag() const { return annotation_flags.integer; }
00401 void integer_flag(bool __c) { annotation_flags.integer = __c; }
00402
00405 bool hard_flag() const { return annotation_flags.hard; }
00408 void hard_flag(bool __c) { annotation_flags.hard = __c; }
00409
00412 bool is_at_either_bound() const { return property_flags.is_at_either_bound; }
00415 void is_at_either_bound(bool __c) { property_flags.is_at_either_bound = __c; }
00416
00419 const type_annotation& type() const { return annotation_flags.type; }
00422 void type(const type_annotation& __c) { annotation_flags.type = __c; }
00423
00425 bool redundancy() const
00426 { return (bool)(((unsigned int)activity()) & (unsigned int)a_redundant); }
00429 bool inactive_hi() const
00430 { return (bool)(!((unsigned int)activity() & (unsigned int)a_active_hi)); }
00433 bool inactive_lo() const
00434 { return (bool)(!((unsigned int)activity() & (unsigned int)a_active_lo)); }
00436 bool inactive() const
00437 { return (bool)(!((unsigned int)activity() & (unsigned int)a_active)); }
00439 };
00440
00441 inline semantics::semantics()
00442 {
00443 property_flags.c_info = convex_e(c_maybe,0);
00444 property_flags.separable = t_maybe;
00445 property_flags.act = a_active;
00446 property_flags.is_at_either_bound = false;
00447
00448 annotation_flags.kj = false;
00449 annotation_flags.integer = false;
00450 annotation_flags.hard = true;
00451 annotation_flags.type = v_exists;
00452
00453 info_flags.has_0chnbase = t_false;
00454
00455 _0chnbase = 0;
00456 addinfo = 0;
00457
00458 degree = -1;
00459 dim = 0;
00460 stage = 0;
00461 }
00462
00463 inline void semantics::merge_tristate(tristate& __o, const tristate& __n)
00464 {
00465 if(__o != __n)
00466 {
00467 if((__o == t_true && __n == t_false) || (__o == t_false && __n == t_true))
00468 __o = t_maybe;
00469 else if(__n == t_true)
00470 __o = t_true;
00471 else if(__n == t_false)
00472 __o = t_false;
00473 }
00474 }
00475
00476 inline void semantics::merge_type_annotation(type_annotation& __o,
00477 const type_annotation& __n)
00478 {
00479 if((__o != __n) &&
00480 (__o == v_exists || __n != v_exists))
00481 __o = __n;
00482 }
00483
00484 inline void semantics::merge_activity_descr(activity_descr& __o,
00485 const activity_descr& __n)
00486 {
00487 if(__o != __n)
00488 {
00489 unsigned int _n = (unsigned int) __n;
00490 unsigned int _o = (unsigned int) __o;
00491 unsigned int _r = _n & ((unsigned int)a_redundant);
00492 _n |= (unsigned int)a_redundant;
00493 _o &= _n;
00494 _o |= _r;
00495 if(_o == 0) _o = (unsigned int)a_redundant;
00496 __o = (activity_descr)_o;
00497 }
00498 }
00499
00500 inline void semantics::merge(const semantics& __s)
00501 {
00502 property_flags.c_info.merge(__s.property_flags.c_info);
00503 merge_tristate(property_flags.separable, __s.property_flags.separable);
00504 merge_activity_descr(property_flags.act, __s.property_flags.act);
00505 if(__s.property_flags.is_at_either_bound)
00506 property_flags.is_at_either_bound = true;
00507 if(!__s.annotation_flags.kj)
00508 annotation_flags.kj = false;
00509 if(__s.annotation_flags.integer)
00510 annotation_flags.integer = true;
00511 if(__s.annotation_flags.hard)
00512 annotation_flags.hard = true;
00513 if(addinfo == 0)
00514 addinfo = __s.addinfo;
00515 else if(addinfo != 0 && __s.addinfo != 0)
00516 addinfo = std::max(addinfo,__s.addinfo);
00517 merge_type_annotation(annotation_flags.type, __s.annotation_flags.type);
00518 merge_tristate(info_flags.has_0chnbase, __s.info_flags.has_0chnbase);
00519 if(stage == 0 && __s.stage != 0)
00520 stage = __s.stage;
00521 }
00522
00524
00527 std::ostream& operator<< (std::ostream& o, const semantics& __s);
00528
00529 }
00530
00531 #endif // _SEMANTICS_H_