22 ap_var_t* r = (ap_var_t*)malloc(
sizeof(ap_var_t)*n.size());
24 for (
size_t i=0; i<n.size(); i++) r[i] = n[i].get_ap_var_t();
31 *x = (ap_var_t*)malloc(
sizeof(ap_var_t)*n.size());
32 *y = (ap_var_t*)malloc(
sizeof(ap_var_t)*n.size());
34 for (
size_t i=0; i<n.size(); i++) {
35 (*x)[i] = n[i].first.get_ap_var_t();
36 (*y)[i] = n[i].second.get_ap_var_t();
44 inline environment::environment()
45 : e(ap_environment_alloc_empty())
49 inline environment::environment(
const std::vector<var>& intdim,
const std::vector<var>& realdim)
53 e = ap_environment_alloc(i, intdim.size(), r, realdim.size());
55 if (!e)
throw std::invalid_argument(
"apron::environment::environment(const vector<var>&, const vector<var>&) incompatible variable types");
58 inline environment::environment(
const var* intdim,
size_t intdim_size,
const var* realdim,
size_t realdim_size)
60 e = ap_environment_alloc(const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(intdim)), intdim_size,
61 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(realdim)), realdim_size);
62 if (!e)
throw std::invalid_argument(
"apron::environment::environment(const var*, size_t, const var*, size_t) incompatible variable types");
65 inline environment::environment(
const environment& x)
66 : e(ap_environment_copy(x.e))
70 inline environment::~environment()
72 ap_environment_free(e);
79 inline const environment& environment::operator=(
const environment& x)
81 ap_environment_t* ee = ap_environment_copy(x.e);
82 ap_environment_free(e);
92 inline environment
environment::add(
const std::vector<var>& intdim,
const std::vector<var>& realdim)
const 96 ap_environment_t* ee = ap_environment_add(e, i, intdim.size(), r, realdim.size());
98 if (!ee)
throw std::invalid_argument(
"apron::environment::add(const vector<var>&, const vector<var>&) incompatible variable types");
102 inline environment
environment::add(
const var* intdim,
size_t intdim_size,
const var* realdim,
size_t realdim_size)
const 104 ap_environment_t* ee =
105 ap_environment_add(e,
106 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(intdim)), intdim_size,
107 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(realdim)), realdim_size);
108 if (!ee)
throw std::invalid_argument(
"apron::environment::add(const var*, size_t, const var*, size_t) incompatible variable types");
112 inline environment
environment::add(
const std::vector<var>& intdim,
const std::vector<var>& realdim, dimperm& perm)
const 117 ap_environment_t* ee = ap_environment_add_perm(e, i, intdim.size(), r, realdim.size(), &p);
119 if (!ee)
throw std::invalid_argument(
"apron::environment::add(const vector<var>&, const vector<var>&, dimperm& perm) incompatible variable types");
120 ap_dimperm_clear(perm.get_ap_dimperm_t());
121 *perm.get_ap_dimperm_t() = p;
125 inline environment
environment::add(
const var* intdim,
size_t intdim_size,
const var* realdim,
size_t realdim_size, dimperm& perm)
const 128 ap_environment_t* ee =
129 ap_environment_add_perm(e,
130 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(intdim)), intdim_size,
131 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(realdim)), realdim_size,
133 if (!ee)
throw std::invalid_argument(
"apron::environment::add(const var*, size_t, const var*, size_t, dimperm&) incompatible variable types");
134 ap_dimperm_clear(perm.get_ap_dimperm_t());
135 *perm.get_ap_dimperm_t() = p;
139 inline environment environment::remove(
const std::vector<var>& dims)
const 142 ap_environment_t* ee = ap_environment_remove(e, d, dims.size());
144 if (!ee)
throw std::invalid_argument(
"apron::environment::remove(const vector<var>&) variable not in environment");
148 inline environment environment::remove(
const var* dims,
size_t dims_size)
const 150 ap_environment_t* ee =
151 ap_environment_remove(e,
152 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(dims)),
154 if (!ee)
throw std::invalid_argument(
"apron::environment::remove(const var*, size_t) variable not in environment");
163 ap_environment_t* ee = ap_environment_rename(e, a, b, dims.size(), &p);
165 if (!ee)
throw std::invalid_argument(
"apron::environment::rename(const vector<std::pair<var,var>>&) variable mismatch");
166 ap_dimperm_clear(&p);
170 inline environment
environment::rename(
const var* before,
const var* after,
size_t dims_size)
const 173 ap_environment_t* ee =
174 ap_environment_rename(e,
175 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(before)),
176 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(after)),
178 if (!ee)
throw std::invalid_argument(
"apron::environment::rename(const var*, const var*, size_t) variable mismatch");
179 ap_dimperm_clear(&p);
183 inline environment
environment::rename(
const std::vector<std::pair<var,var> >& dims, dimperm& perm)
const 188 ap_dimperm_clear(perm.get_ap_dimperm_t());
189 ap_environment_t* ee = ap_environment_rename(e, a, b, dims.size(), &p);
191 if (!ee)
throw std::invalid_argument(
"apron::environment::rename(const vector<std::pair<var,var>>&, dimperm&) variable mismatch");
192 ap_dimperm_clear(perm.get_ap_dimperm_t());
193 *perm.get_ap_dimperm_t() = p;
197 inline environment
environment::rename(
const var* before,
const var* after,
size_t dims_size, dimperm& perm)
const 200 ap_environment_t* ee =
201 ap_environment_rename(e,
202 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(before)),
203 const_cast<ap_var_t*>(reinterpret_cast<const ap_var_t*>(after)),
205 if (!ee)
throw std::invalid_argument(
"apron::environment::rename(const var*, const var*, size_t, dimperm&) variable mismatch");
206 ap_dimperm_clear(perm.get_ap_dimperm_t());
207 *perm.get_ap_dimperm_t() = p;
212 inline environment
lce(
const environment& x,
const environment& y)
214 ap_dimchange_t *a = NULL, *b = NULL;
215 ap_environment_t* ee = ap_environment_lce(x.e, y.e, &a, &b);
216 if (a) ap_dimchange_free(a);
217 if (b) ap_dimchange_free(b);
218 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const environment&, const environment&) incompatible variable types");
222 inline environment
lce(
const environment& x,
const environment& y, dimchange& chgx, dimchange& chgy)
224 ap_dimchange_t *a = NULL, *b = NULL;
225 ap_environment_t* ee = ap_environment_lce(x.e, y.e, &a, &b);
226 ap_dimchange_clear(chgx.get_ap_dimchange_t());
227 ap_dimchange_clear(chgy.get_ap_dimchange_t());
228 if (a) { *chgx.get_ap_dimchange_t() = *a; free(a); }
229 else { ap_dimchange_init(chgx.get_ap_dimchange_t(), 0, 0); }
230 if (b) { *chgy.get_ap_dimchange_t() = *b; free(b); }
231 else { ap_dimchange_init(chgy.get_ap_dimchange_t(), 0, 0); }
232 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const environment&, const environment&, dimchange&, dimchange&) incompatible variable types");
236 inline environment
lce(
const std::vector<environment>& x)
238 ap_environment_t** ar = (ap_environment_t**)malloc(
sizeof(ap_environment_t*)*x.size());
239 ap_dimchange_t** r = NULL;
241 for (
size_t i=0; i<x.size(); i++) ar[i] = x[i].e;
242 ap_environment_t* ee = ap_environment_lce_array(ar, x.size(), &r);
245 for (
size_t i=0; i<x.size(); i++)
246 if (r[i]) ap_dimchange_free(r[i]);
249 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const vector<environment>&) incompatible variable types");
253 inline environment
lce(
const environment* env,
size_t env_size)
255 ap_dimchange_t** r = NULL;
256 ap_environment_t* ee =
257 ap_environment_lce_array(reinterpret_cast<ap_environment_t**>(const_cast<environment*>(env)),
260 for (
size_t i=0; i<env_size; i++)
261 if (r[i]) ap_dimchange_free(r[i]);
264 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const environment*, size_t) incompatible variable types");
268 inline environment
lce(
const std::vector<environment>& x, std::vector<dimchange>& chg)
270 if (x.size()>chg.size())
throw std::invalid_argument(
"apron::environment::lce(const vector<environment>&, vector<dimchange>&) dimchange vector too short");
271 ap_environment_t** ar = (ap_environment_t**)malloc(
sizeof(ap_environment_t*)*x.size());
272 ap_dimchange_t** r = NULL;
274 for (
size_t i=0; i<x.size(); i++) ar[i] = x[i].e;
275 ap_environment_t* ee = ap_environment_lce_array(ar, x.size(), &r);
277 for (
size_t i=0; i<x.size(); i++) {
278 ap_dimchange_clear(chg[i].get_ap_dimchange_t());
280 *chg[i].get_ap_dimchange_t() = *(r[i]);
284 ap_dimchange_init(chg[i].get_ap_dimchange_t(), 0, 0);
288 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const vector<environment>&, vector<dimchange>&) incompatible variable types");
292 inline environment
lce(
const environment* env, dimchange* chg,
size_t env_size)
294 ap_dimchange_t** r = NULL;
295 ap_environment_t* ee =
296 ap_environment_lce_array(reinterpret_cast<ap_environment_t**>(const_cast<environment*>(env)),
298 for (
size_t i=0; i<env_size; i++) {
299 ap_dimchange_clear(chg[i].get_ap_dimchange_t());
301 *chg[i].get_ap_dimchange_t() = *(r[i]);
305 ap_dimchange_init(chg[i].get_ap_dimchange_t(), 0, 0);
309 if (!ee)
throw std::invalid_argument(
"apron::environment::lce(const environment*, dimchange*, size_t) incompatible variable types");
315 ap_dimchange_t* d = ap_environment_dimchange(x.e,y.e);
316 if (!d)
throw std::invalid_argument(
"apron::environment::get_dimchange(const environment&, const environment &) not a super-type");
318 *c.get_ap_dimchange_t() = *d;
327 inline size_t environment::intdim()
const 332 inline size_t environment::realdim()
const 337 inline bool environment::contains(
const var& x)
const 339 return ap_environment_mem_var(e, x.get_ap_var_t());
342 inline ap_dim_t environment::operator[] (
const var& x)
const 344 ap_dim_t d = ap_environment_dim_of_var(e, x.get_ap_var_t());
345 if (d==AP_DIM_MAX)
throw std::invalid_argument(
"apron::environment::operator[](const var&) variable not in environment");
349 inline const var& environment::operator[] (ap_dim_t d)
const 351 return *reinterpret_cast<var*>(&e->var_of_dim[d]);
354 inline ap_dim_t environment::get_dim(
const var& x)
const 356 ap_dim_t d = ap_environment_dim_of_var(e, x.get_ap_var_t());
357 if (d==AP_DIM_MAX)
throw std::invalid_argument(
"apron::environment::get_dim(const var&) variable not in environment");
361 inline const var& environment::get_var(ap_dim_t d)
const 363 if (d >= e->intdim+e->realdim)
throw std::out_of_range(
"environment::get_var");
364 return *reinterpret_cast<var*>(&e->var_of_dim[d]);
367 inline std::vector<var> environment::get_vars()
const 369 std::vector<var> v = std::vector<var>(e->intdim+e->realdim,
"");
370 for (
size_t i=0; i<e->intdim+e->realdim; i++) v[i] = e->var_of_dim[i];
378 inline bool operator==(
const environment& x,
const environment& y)
380 return ap_environment_is_eq(x.e, y.e);
383 inline bool operator!=(
const environment& x,
const environment& y)
385 return !ap_environment_is_eq(x.e, y.e);
388 inline bool operator<=(
const environment& x,
const environment& y)
390 return ap_environment_is_leq(x.e, y.e);
393 inline bool operator>=(
const environment& x,
const environment& y)
395 return ap_environment_is_leq(y.e, x.e);
398 inline int cmp(
const environment& x,
const environment& y)
400 return ap_environment_compare(x.e, y.e);
406 inline std::ostream&
operator<< (std::ostream& os,
const environment& s)
408 for (
size_t i=0; i<s.e->intdim+s.e->realdim; i++) {
409 char* c = ap_var_operations->to_string(s.e->var_of_dim[i]);
410 os << i <<
": " << c << (i<s.e->intdim ?
" (int)" :
" (real)") << std::endl;
416 inline void environment::print(FILE* stream)
const 418 ap_environment_fdump(stream, e);
425 inline const ap_environment_t* environment::get_ap_environment_t()
const 430 inline ap_environment_t*environment:: get_ap_environment_t()
bool operator>=(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:393
bool operator!=(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:383
environment lce(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:212
texpr0::builder add(const texpr0::builder &a, const texpr0::builder &b, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition: apxx_texpr0.hh:772
int cmp(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:398
bool operator<=(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:388
abstract1 & rename(manager &m, abstract1 &dst, const abstract1 &src, size_t size, const var oldv[], const var newv[])
Definition: apxx_abstract1.hh:1396
std::ostream & operator<<(std::ostream &os, const environment &s)
Definition: apxx_environment_inline.hh:406
static ap_var_t * apxx_environment_get_names(const std::vector< var > &n)
Definition: apxx_environment_inline.hh:20
static void apxx_environment_get_names_pair(const std::vector< std::pair< var, var > > &n, ap_var_t **x, ap_var_t **y)
Definition: apxx_environment_inline.hh:29
bool operator==(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:378
dimchange get_dimchange(const environment &x, const environment &y)
Definition: apxx_environment_inline.hh:313