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 #include <coconut_config.h>
00029 #if defined(COCONUT_WINDOWS)
00030 #include <windows_utils.h>
00031 #endif
00032 #include <string.h>
00033 #include <cstring>
00034 #include <semantics.h>
00035 #include <api_exception.h>
00036
00037 namespace coco {
00038
00039 void convex_e::read(char *c)
00040 {
00041 switch(c[0])
00042 {
00043 case 'V':
00044 e = c_concave;
00045 break;
00046 case 'X':
00047 e = c_convex;
00048 break;
00049 case 'L':
00050 e = c_linear;
00051 break;
00052 case 'M':
00053 e = c_maybe;
00054 break;
00055 default:
00056 throw api_exception(apiee_internal,
00057 "convex_e::read: malformed convexity info: wrong type");
00058 }
00059 unsigned int t;
00060 if(sscanf(c+1,"%u",&t) != 1)
00061 throw api_exception(apiee_internal,
00062 "convex_e::read: malformed convexity info: tested is not an integer");
00063 tested = (uint16_t)t;
00064 }
00065
00066 const char* semantics::print_tristate(const tristate& x) const
00067 {
00068 if(x == t_true) return "T";
00069 if(x == t_false) return "F";
00070 return "M";
00071 }
00072
00073 tristate semantics::read_tristate(char c) const
00074 {
00075 if(c == 'T') return t_true;
00076 if(c == 'F') return t_false;
00077 return t_maybe;
00078 }
00079
00080 const char* semantics::print_type_annotation(const type_annotation& x) const
00081 {
00082 switch(x)
00083 {
00084 case v_exists:
00085 return "E";
00086 case v_forall:
00087 return "A";
00088 case v_free:
00089 return "F";
00090 case v_stochastic:
00091 return "S";
00092 }
00093
00094 return "";
00095 }
00096
00097 type_annotation semantics::read_type_annotation(char c) const
00098 {
00099 switch(c)
00100 {
00101 case 'A':
00102 return v_forall;
00103 case 'F':
00104 return v_free;
00105 case 'S':
00106 return v_stochastic;
00107 }
00108 return v_exists;
00109 }
00110
00111 const char* semantics::print_activity_descr(const activity_descr& x) const
00112 {
00113 switch(x)
00114 {
00115 case a_redundant:
00116 return "R";
00117 case a_active_lo:
00118 return "l";
00119 case a_active_lo_red:
00120 return "L";
00121 case a_active_hi:
00122 return "h";
00123 case a_active_hi_red:
00124 return "H";
00125 case a_active:
00126 return "a";
00127 case a_active_red:
00128 return "A";
00129 }
00130
00131 return "";
00132 }
00133
00134 activity_descr semantics::read_activity_descr(char c) const
00135 {
00136 switch(c)
00137 {
00138 case 'A':
00139 return a_active_red;
00140 case 'H':
00141 return a_active_hi_red;
00142 case 'L':
00143 return a_active_lo_red;
00144 case 'R':
00145 return a_redundant;
00146 case 'a':
00147 return a_active;
00148 case 'h':
00149 return a_active_hi;
00150 case 'l':
00151 return a_active_lo;
00152 }
00153 return a_active;
00154 }
00155
00156 void semantics::read(char *c)
00157 {
00158 try
00159 {
00160 for(; c;)
00161 {
00162 char *ct;
00163
00164 ct = strsep(&c, ",");
00165 ct += strspn(ct, " \t");
00166 switch(ct[0])
00167 {
00168 case 'C':
00169 if(ct[1] != '=')
00170 throw api_exception(apiee_internal,
00171 "malformed semantics C expression: `=' missing");
00172 property_flags.c_info.read(ct+2);
00173 break;
00174 case 'P':
00175 if(ct[1] != '=')
00176 throw api_exception(apiee_internal,
00177 "malformed semantics P expression: `=' missing");
00178 property_flags.separable = read_tristate(ct[2]);
00179 property_flags.act = read_activity_descr(ct[3]);
00180 property_flags.is_at_either_bound = (ct[4] == 'T' ? true : false);
00181 break;
00182 case 'N':
00183 if(ct[1] != '=')
00184 throw api_exception(apiee_internal,
00185 "malformed semantics N expression: `=' missing");
00186 annotation_flags.kj = (ct[2] == 'T' ? true : false);
00187 annotation_flags.integer = (ct[3] == 'T' ? true : false);
00188 annotation_flags.hard = (ct[4] == 'T' ? true : false);
00189 annotation_flags.type = read_type_annotation(ct[5]);
00190 break;
00191 case 'I':
00192 if(ct[1] != '=')
00193 throw api_exception(apiee_internal,
00194 "malformed semantics I expression: `=' missing");
00195 info_flags.has_0chnbase = read_tristate(ct[3]);
00196 break;
00197 case 'A':
00198 if(ct[1] != '=')
00199 throw api_exception(apiee_internal,
00200 "malformed semantics A expression: `=' missing");
00201 if(sscanf(ct+2, "%d", &addinfo) != 1)
00202 throw api_exception(apiee_internal,
00203 "malformed semantics A expression: no integer");
00204 break;
00205 case 'B':
00206 if(ct[1] != '=')
00207 throw api_exception(apiee_internal,
00208 "malformed semantics B expression: `=' missing");
00209 if(sscanf(ct+2, "%u", &_0chnbase) != 1)
00210 throw api_exception(apiee_internal,
00211 "malformed semantics B expression: no integer");
00212 break;
00213 case 'G':
00214 if(ct[1] != '=')
00215 throw api_exception(apiee_internal,
00216 "malformed semantics G expression: `=' missing");
00217 if(sscanf(ct+2, "%d", °ree) != 1)
00218 throw api_exception(apiee_internal,
00219 "malformed semantics G expression: no integer");
00220 break;
00221 case 'D':
00222 if(ct[1] != '=')
00223 throw api_exception(apiee_internal,
00224 "malformed semantics D expression: `=' missing");
00225 if(sscanf(ct+2, "%d", &dim) != 1)
00226 throw api_exception(apiee_internal,
00227 "malformed semantics D expression: no integer");
00228 break;
00229 case 'S':
00230 if(ct[1] != '=')
00231 throw api_exception(apiee_internal,
00232 "malformed semantics S expression: `=' missing");
00233 if(sscanf(ct+2, "%d", &stage) != 1)
00234 throw api_exception(apiee_internal,
00235 "malformed semantics S expression: no integer");
00236 break;
00237 default:
00238 throw api_exception(apiee_internal,
00239 "malformed semantics expression: wrong type");
00240 break;
00241 }
00242 }
00243 }
00244 catch(api_exception a)
00245 {
00246 throw api_exception(apiee_internal,
00247 std::string("semantics::read: ")+a.what());
00248 }
00249 }
00250
00251 std::ostream& operator<< (std::ostream& o, const semantics& __s)
00252 {
00253 o << "C=";
00254 o << __s.property_flags.c_info;
00255 o << ",P=";
00256 o << __s.print_tristate(__s.property_flags.separable);
00257 o << __s.print_activity_descr(__s.property_flags.act);
00258 o << (__s.property_flags.is_at_either_bound ? "T" : "F");
00259 o << ",N=";
00260 o << (__s.annotation_flags.kj ? "T" : "F");
00261 o << (__s.annotation_flags.integer ? "T" : "F");
00262 o << (__s.annotation_flags.hard ? "T" : "F");
00263 o << __s.print_type_annotation(__s.annotation_flags.type);
00264 o << ",I=";
00265 o << __s.print_tristate(__s.info_flags.has_0chnbase);
00266 o << ",A=" << __s.addinfo;
00267 o << ",B=" << __s._0chnbase;
00268 o << ",G=" << __s.degree;
00269 o << ",D=" << __s.dim;
00270 o << ",S=" << __s.stage;
00271 return o;
00272 }
00273
00274 }