APRONXX 0.9.15
/home/mine/apron/apronxx/apxx_texpr0_inline.hh
Go to the documentation of this file.
1/* -*- C++ -*-
2 * apxx_texpr0_inline.hh
3 *
4 * APRON Library / C++ inline functions
5 *
6 * DO NOT INCLUDE THIS FILE DIRECTLY
7 *
8 * Copyright (C) Antoine Mine' 2007
9 *
10 */
11/* This file is part of the APRON Library, released under LGPL license
12 with an exception allowing the redistribution of statically linked
13 executables.
14
15 Please read the COPYING file packaged in the distribution.
16*/
17
18
19inline dim::dim(ap_dim_t d) : d(d)
20{}
21
22inline dim::dim(const environment& e, const var& v)
23{
24 ap_dim_t d = ap_environment_dim_of_var(const_cast<ap_environment_t*>(e.get_ap_environment_t()),
25 v.get_ap_var_t());
26 if (d==AP_DIM_MAX)
27 throw std::invalid_argument("apron::dim::dim(const environment&, const var&) invalid variable name");
28}
29
30
31
32inline bool is_unop(ap_texpr_op_t op)
33{
34 return ap_texpr_is_unop(op);
35}
36
37inline bool is_binop(ap_texpr_op_t op)
38{
39 return ap_texpr_is_binop(op);
40}
41
42
43/* ================================= */
44/* texpr0 */
45/* ================================= */
46
47inline void texpr0::init_from(ap_texpr0_t* x)
48{
49 l = *x;
50 free(x);
51}
52
53inline texpr0::texpr0(ap_texpr0_t* x)
54{ init_from(x); }
55
56inline texpr0::texpr0(const builder& x)
57{ init_from(ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()))); }
58
59inline texpr0::texpr0(const const_iterator& x)
60{ init_from(ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()))); }
61
62inline texpr0::texpr0(const texpr0& x)
63{ init_from(ap_texpr0_copy(const_cast<ap_texpr0_t*>(&x.l))); }
64
65
66/* linear expression */
67
68inline texpr0::texpr0(const linexpr0& l)
69{ init_from(ap_texpr0_from_linexpr0(const_cast<ap_linexpr0_t*>(l.get_ap_linexpr0_t()))); }
70
71
72/* change of dimension */
73
74inline texpr0::texpr0(const texpr0& x, const dimchange& d, bool add)
75{
76 if (add)
77 init_from(ap_texpr0_add_dimensions(const_cast<ap_texpr0_t*>(&x.l),
78 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t())));
79 else
80 init_from(ap_texpr0_remove_dimensions(const_cast<ap_texpr0_t*>(&x.l),
81 const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t())));
82}
83
84inline texpr0::texpr0(const texpr0& x, const dimperm& d)
85{
86 init_from(ap_texpr0_permute_dimensions(const_cast<ap_texpr0_t*>(&x.l),
87 const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t())));
88}
89
90inline texpr0::texpr0(const texpr0& x, ap_dim_t dim, const texpr0& dst)
91{
92 init_from(ap_texpr0_substitute(const_cast<ap_texpr0_t*>(&x.l),
93 dim, const_cast<ap_texpr0_t*>(&dst.l)));
94}
95
96
97/* destructor */
98/* ========== */
99
100/* (deep) destruction */
101
102inline texpr0::~texpr0()
103{
104 ap_texpr0_clear(&l);
105}
106
107
108/* assignment */
109/* ========== */
110
111/* (deep) copy */
112
113
114inline texpr0& texpr0::operator= (const builder& x)
115{
116 // copy first, as x.l may alias this!
117 ap_texpr0_t* c = ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()));
118 ap_texpr0_clear(&l);
119 init_from(c);
120 return *this;
121}
122
123inline texpr0& texpr0::operator= (const texpr0& x)
124{
125 // copy first, as x.l may alias this!
126 ap_texpr0_t* c = ap_texpr0_copy(const_cast<ap_texpr0_t*>(&x.l));
127 ap_texpr0_clear(&l);
128 init_from(c);
129 return *this;
130}
131
132inline texpr0& texpr0::operator= (const const_iterator& x)
133{
134 // copy first, as x.l may alias this!
135 ap_texpr0_t* c = ap_texpr0_copy(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()));
136 ap_texpr0_clear(&l);
137 init_from(c);
138 return *this;
139}
140
141inline texpr0& texpr0::operator= (const linexpr0& x)
142{
143 ap_texpr0_clear(&l);
144 init_from(ap_texpr0_from_linexpr0(const_cast<ap_linexpr0_t*>(x.get_ap_linexpr0_t())));
145 return *this;
146}
147
148
149/* print */
150/* ===== */
151
152inline std::ostream& operator<< (std::ostream& os, const texpr0& s)
153{
154 return os << s.root();
155}
156
157inline void texpr0::print(char** name_of_dim, FILE* stream) const
158{
159 root().print(name_of_dim,stream);
160}
161
162
163/* tests, size */
164/* =========== */
165
166inline bool texpr0::is_zero() const
167{
168 return root().is_zero();
169}
170
171inline bool texpr0::equal(const texpr0& x) const
172{
173 return root().equal(x);
174}
175
176inline size_t texpr0::depth() const
177{
178 return root().depth();
179}
180
181inline size_t texpr0::size() const
182{
183 return root().size();
184}
185
186inline ap_dim_t texpr0::max_dim() const
187{
188 return root().max_dim();
189}
190
191inline bool texpr0::has_dim(ap_dim_t d) const
192{
193 return root().has_dim(d);
194}
195
196inline std::vector<ap_dim_t> texpr0::dimlist() const
197{
198 return root().dimlist();
199}
200
201inline bool texpr0::is_interval_cst() const
202{
203 return root().is_interval_cst();
204}
205
206inline bool texpr0::is_interval_linear() const
207{
208 return root().is_interval_linear();
209}
210
211inline bool texpr0::is_interval_polynomial() const
212{
213 return root().is_interval_polynomial();
214}
215
216inline bool texpr0::is_interval_polyfrac() const
217{
218 return root().is_interval_polyfrac();
219}
220
221inline bool texpr0::is_scalar() const
222{
223 return root().is_scalar();
224}
225
226
227/* operations */
228/* ========== */
229
230inline void texpr0::substitute(ap_dim_t dim, const texpr0& dst)
231{
232 ap_texpr0_substitute_with(&l,dim,const_cast<ap_texpr0_t*>(&dst.l));
233}
234
235#if 0
236inline interval texpr0::eval(manager& m, const abstract0& a, ap_scalar_discr_t discr,
237 bool* pexact) const
238{
239 bool b;
240 if (!pexact) pexact = &b;
241 return
242 ap_eval_texpr0(m.get_ap_manager_t(),
243 const_cast<ap_abstract0_t*>(a.get_ap_abstract0_t()),
244 const_cast<ap_texpr0_t*>(l),
245 discr, pexact);
246}
247
248inline linexpr0 texpr0::intlinearize(manager& m, const abstract0& a, ap_scalar_discr_t discr,
249 bool quasilinearize, bool* pexact) const
250{
251 bool b;
252 if (!pexact) pexact = &b;
253 return
254 ap_intlinearize_texpr0(m.get_ap_manager_t(),
255 const_cast<ap_abstract0_t*>(a.get_ap_abstract0_t()),
256 const_cast<ap_texpr0_t*>(l),
257 pexact, discr, quasilinearize);
258}
259#endif
260
261inline long texpr0::hash() const
262{
263 return ap_texpr0_hash(const_cast<ap_texpr0_t*>(&l));
264}
265
266
267
268/* change of dimension */
269/* =================== */
270
271
272inline void texpr0::add_dimensions(const dimchange& d)
273{
274 ap_texpr0_add_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
275}
276
277
278inline void texpr0::remove_dimensions(const dimchange& d)
279{
280 ap_texpr0_remove_dimensions_with(&l, const_cast<ap_dimchange_t*>(d.get_ap_dimchange_t()));
281}
282
283inline void texpr0::permute_dimensions(const dimperm& d)
284{
285 ap_texpr0_permute_dimensions_with(&l, const_cast<ap_dimperm_t*>(d.get_ap_dimperm_t()));
286}
287
288
289
290/* C-level compatibility */
291/* ===================== */
292
293inline ap_texpr0_t* texpr0::get_ap_texpr0_t()
294{
295 return &l;
296}
297
298inline const ap_texpr0_t* texpr0::get_ap_texpr0_t() const
299{
300 return &l;
301}
302
303
304
305
306
307/* ================================= */
308/* iterator */
309/* ================================= */
310
311
312/* constructors */
313/* ============ */
314
315inline texpr0::const_iterator texpr0::root() const
316{
317 return const_iterator(const_cast<ap_texpr0_t*>(&l));
318}
319
320inline texpr0::const_iterator::const_iterator(ap_texpr0_t* l) : l(l)
321{}
322
323
324inline texpr0::const_iterator::const_iterator(const texpr0& e)
325 : l(const_cast<ap_texpr0_t*>(e.get_ap_texpr0_t()))
326{}
327
328inline texpr0::const_iterator::const_iterator(const const_iterator& i) : l(i.l)
329{}
330
331
332/* access */
333/* ====== */
334
335inline ap_texpr_discr_t texpr0::const_iterator::get_discr() const
336{
337 return l->discr;
338}
339
340inline const coeff& texpr0::const_iterator::get_coeff() const
341{
342 if (l->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr0::const_iterator::get_coeff()"));
343 return reinterpret_cast<coeff&>(l->val.cst);
344}
345
346inline ap_dim_t texpr0::const_iterator::get_dim() const
347{
348 if (l->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr0::const_iterator::get_dim()"));
349 return l->val.dim;
350}
351
352inline ap_texpr_op_t texpr0::const_iterator::get_op() const
353{
354 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_op()"));
355 return l->val.node->op;
356}
357
358inline ap_texpr_rtype_t texpr0::const_iterator::get_rtype() const
359{
360 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_type()"));
361 return l->val.node->type;
362}
363
364inline ap_texpr_rdir_t texpr0::const_iterator::get_rdir() const
365{
366 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::get_dir()"));
367 return l->val.node->dir;
368}
369
370
371/* traversal */
372/* ========= */
373
374inline texpr0::const_iterator& texpr0::const_iterator::operator=(const const_iterator& i)
375{
376 l = i.l;
377 return *this;
378}
379
380inline texpr0::const_iterator texpr0::const_iterator::child() const
381{
382 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::child()"));
383 if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::const_iterator::child()"));
384 return l->val.node->exprA;
385}
386
387inline texpr0::const_iterator texpr0::const_iterator::left() const
388{
389 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::left()"));
390 if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::const_iterator::left()"));
391 return l->val.node->exprA;
392}
393
394inline texpr0::const_iterator texpr0::const_iterator::right() const
395{
396 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::const_iterator::right()"));
397 if (!l->val.node->exprB) throw(std::out_of_range("apron::texpr0::const_iterator::right()"));
398 return l->val.node->exprB;
399}
400
401
402/* print */
403/* ===== */
404
405extern void apxx_texpr0_ostream(std::ostream& os, ap_texpr0_t* a,
406 std::vector<std::string>* names);
407
408inline std::ostream& operator<< (std::ostream& os, const texpr0::const_iterator& s)
409{
410 apxx_texpr0_ostream(os, const_cast<ap_texpr0_t*>(s.l), get_varname(os));
411 return os;
412}
413
414inline void texpr0::const_iterator::print(char** name_of_dim, FILE* stream) const
415{
416 ap_texpr0_fprint(stream, const_cast<ap_texpr0_t*>(l), name_of_dim);
417}
418
419
420/* tests, size */
421/* =========== */
422
423inline bool texpr0::const_iterator::is_zero() const
424{
425 return l->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast<ap_texpr0_t*>(l)->val.cst);
426}
427
428inline bool texpr0::const_iterator::equal(const texpr0& x) const
429{
430 return ap_texpr0_equal(const_cast<ap_texpr0_t*>(l),
431 const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()));
432}
433
434inline size_t texpr0::const_iterator::depth() const
435{
436 return ap_texpr0_depth(const_cast<ap_texpr0_t*>(l));
437}
438
439inline size_t texpr0::const_iterator::size() const
440{
441 return ap_texpr0_size(const_cast<ap_texpr0_t*>(l));
442}
443
444inline ap_dim_t texpr0::const_iterator::max_dim() const
445{
446 return ap_texpr0_max_dim(const_cast<ap_texpr0_t*>(l));
447}
448
449inline bool texpr0::const_iterator::has_dim(ap_dim_t d) const
450{
451 return ap_texpr0_has_dim(const_cast<ap_texpr0_t*>(l), d);
452}
453
454inline std::vector<ap_dim_t> texpr0::const_iterator::dimlist() const
455{
456 ap_dim_t* d = ap_texpr0_dimlist(const_cast<ap_texpr0_t*>(l));
457 ap_dim_t i;
458 for (i=0; d[i]!=AP_DIM_MAX; i++) ;
459 std::vector<ap_dim_t> r = std::vector<ap_dim_t>(i,0);
460 for (i=0; d[i]!=AP_DIM_MAX; i++) r[i] = d[i];
461 free(d);
462 return r;
463}
464
465inline bool texpr0::const_iterator::is_interval_cst() const
466{
467 return ap_texpr0_is_interval_cst(const_cast<ap_texpr0_t*>(l));
468}
469
470inline bool texpr0::const_iterator::is_interval_linear() const
471{
472 return ap_texpr0_is_interval_linear(const_cast<ap_texpr0_t*>(l));
473}
474
475inline bool texpr0::const_iterator::is_interval_polynomial() const
476{
477 return ap_texpr0_is_interval_polynomial(const_cast<ap_texpr0_t*>(l));
478}
479
480inline bool texpr0::const_iterator::is_interval_polyfrac() const
481{
482 return ap_texpr0_is_interval_polyfrac(const_cast<ap_texpr0_t*>(l));
483}
484
485inline bool texpr0::const_iterator::is_scalar() const
486{
487 return ap_texpr0_is_scalar(const_cast<ap_texpr0_t*>(l));
488}
489
490
491/* C-level compatibility */
492/* ===================== */
493
494inline ap_texpr0_t* texpr0::const_iterator::get_ap_texpr0_t()
495{
496 return l;
497}
498
499inline const ap_texpr0_t* texpr0::const_iterator::get_ap_texpr0_t() const
500{
501 return l;
502}
503
504
505/* constructors */
506/* ============ */
507
508inline texpr0::iterator texpr0::root()
509{
510 return iterator(*this);
511}
512
513inline texpr0::iterator::iterator(ap_texpr0_t* l)
514 : texpr0::const_iterator(l)
515{}
516
517
518inline texpr0::iterator::iterator(texpr0& e)
519 : texpr0::const_iterator(e.get_ap_texpr0_t())
520{}
521
522inline texpr0::iterator::iterator(const iterator& i)
523 : texpr0::const_iterator(i)
524{}
525
526
527
528/* substitution */
529/* ============ */
530
531inline texpr0::iterator& texpr0::iterator::operator= (const builder& c)
532{
533 ap_texpr0_t* cc = ap_texpr0_copy(const_cast<ap_texpr0_t*>(c.get_ap_texpr0_t()));
534 ap_texpr0_clear(l);
535 *l = *cc;
536 free(cc);
537 return *this;
538}
539
540
541/* access */
542/* ====== */
543
544inline coeff& texpr0::iterator::get_coeff() const
545{
546 if (l->discr!=AP_TEXPR_CST) throw(bad_discriminant("apron::texpr0::iterator::get_coeff()"));
547 return reinterpret_cast<coeff&>(l->val.cst);
548}
549
550inline ap_dim_t& texpr0::iterator::get_dim() const
551{
552 if (l->discr!=AP_TEXPR_DIM) throw(bad_discriminant("apron::texpr0::iterator::get_dim()"));
553 return l->val.dim;
554}
555
556inline ap_texpr_op_t& texpr0::iterator::get_op() const
557{
558 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_op()"));
559 return l->val.node->op;
560}
561
562inline ap_texpr_rtype_t& texpr0::iterator::get_rtype() const
563{
564 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_type()"));
565 return l->val.node->type;
566}
567
568inline ap_texpr_rdir_t& texpr0::iterator::get_rdir() const
569{
570 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::get_dir()"));
571 return l->val.node->dir;
572}
573
574
575/* traversal */
576/* ========= */
577
578inline texpr0::iterator& texpr0::iterator::operator=(const iterator& i)
579{
580 l = i.l;
581 return *this;
582}
583
584inline texpr0::iterator texpr0::iterator::child() const
585{
586 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::child()"));
587 if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::iterator::child()"));
588 return l->val.node->exprA;
589}
590
591inline texpr0::iterator texpr0::iterator::left() const
592{
593 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::left()"));
594 if (!l->val.node->exprA) throw(std::out_of_range("apron::texpr0::iterator::left()"));
595 return l->val.node->exprA;
596}
597
598inline texpr0::iterator texpr0::iterator::right() const
599{
600 if (l->discr!=AP_TEXPR_NODE) throw(bad_discriminant("apron::texpr0::iterator::right()"));
601 if (!l->val.node->exprB) throw(std::out_of_range("apron::texpr0::iterator::right()"));
602 return l->val.node->exprB;
603}
604
605
606/* C-level compatibility */
607/* ===================== */
608
609inline ap_texpr0_t* texpr0::iterator::get_ap_texpr0_t()
610{
611 return l;
612}
613
614inline const ap_texpr0_t* texpr0::iterator::get_ap_texpr0_t() const
615{
616 return l;
617}
618
619
620
621/* ================================= */
622/* builder */
623/* ================================= */
624
625
626inline void texpr0::builder::init_from(ap_texpr0_t* x)
627{
628 switch (x->discr) {
629 case AP_TEXPR_DIM: l = ap_texpr0_dim(x->val.dim); break;
630 case AP_TEXPR_CST: l = ap_texpr0_cst(const_cast<ap_coeff_t*>(&x->val.cst)); break;
631 case AP_TEXPR_NODE:
632 l = ap_texpr0_node(x->val.node->op,
633 x->val.node->type, x->val.node->dir,
634 x->val.node->exprA, x->val.node->exprB);
635 break;
636 default: throw std::invalid_argument("apron::texpr0::builder::init_from(ap_texpr0_t*) invalid discriminant");
637 }
638}
639
640inline texpr0::builder::builder(ap_texpr0_t* x)
641{
642 init_from(x);
643}
644
645inline texpr0::builder::builder(const builder& x)
646{
647 init_from(x.l);
648}
649
650inline texpr0::builder::builder(const const_iterator& x)
651{
652 init_from(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()));
653}
654
655inline texpr0::builder::builder(const texpr0& x)
656{
657 init_from(const_cast<ap_texpr0_t*>(x.get_ap_texpr0_t()));
658}
659
660inline texpr0::builder::builder(const coeff& x)
661 : l(ap_texpr0_cst(const_cast<ap_coeff_t*>(x.get_ap_coeff_t())))
662{}
663
664inline texpr0::builder::builder(const scalar& x)
665 : l(ap_texpr0_cst_scalar(const_cast<ap_scalar_t*>(x.get_ap_scalar_t())))
666{}
667
668inline texpr0::builder::builder(const mpq_class& x)
669 : l(ap_texpr0_cst_scalar_mpq(const_cast<mpq_class&>(x).get_mpq_t()))
670{}
671
672inline texpr0::builder::builder(mpfr_t x)
673 : l(ap_texpr0_cst_scalar_mpfr(x))
674{}
675
676inline texpr0::builder::builder(int x)
677 : l(ap_texpr0_cst_scalar_int(x))
678{}
679
680inline texpr0::builder::builder(long x)
681 : l(ap_texpr0_cst_scalar_int(x))
682{}
683
684inline texpr0::builder::builder(double x)
685 : l(ap_texpr0_cst_scalar_double(x))
686{}
687
688inline texpr0::builder::builder(const frac& x)
689 : l(ap_texpr0_cst_scalar_frac(x.num, x.den))
690{}
691
692inline texpr0::builder::builder(const interval& x)
693 : l(ap_texpr0_cst_interval(const_cast<ap_interval_t*>(x.get_ap_interval_t())))
694{}
695
696inline texpr0::builder::builder(const scalar& inf, const scalar& sup)
697 : l(ap_texpr0_cst_interval_scalar(const_cast<ap_scalar_t*>(inf.get_ap_scalar_t()),
698 const_cast<ap_scalar_t*>(sup.get_ap_scalar_t())))
699{}
700
701inline texpr0::builder::builder(const mpq_class& inf, const mpq_class& sup)
702 : l(ap_texpr0_cst_interval_mpq(const_cast<mpq_class&>(inf).get_mpq_t(),
703 const_cast<mpq_class&>(sup).get_mpq_t()))
704{}
705
706inline texpr0::builder::builder(mpfr_t inf, mpfr_t sup)
707 : l(ap_texpr0_cst_interval_mpfr(inf,sup))
708{}
709
710inline texpr0::builder::builder(int inf, int sup)
711 : l(ap_texpr0_cst_interval_int(inf, sup))
712{}
713
714inline texpr0::builder::builder(long inf, long sup)
715 : l(ap_texpr0_cst_interval_int(inf, sup))
716{}
717
718inline texpr0::builder::builder(double inf, double sup)
719 : l(ap_texpr0_cst_interval_double(inf, sup))
720{}
721
722inline texpr0::builder::builder(const frac& inf, const frac& sup)
723 : l(ap_texpr0_cst_interval_frac(inf.num, inf.den, sup.num, sup.den))
724{}
725
726inline texpr0::builder::builder(top t)
727 : l(ap_texpr0_cst_interval_top())
728{}
729
730inline texpr0::builder::builder(dim d)
731 : l(ap_texpr0_dim(d.d))
732{}
733
734inline texpr0::builder::builder(ap_texpr_op_t op, const builder& argA, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
735{
736 if (!ap_texpr_is_unop(op))
737 throw std::invalid_argument("apron::texpr0::builder::builder(ap_texpr_op_t, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a unary operator");
738 l = ap_texpr0_unop(op,
739 const_cast<ap_texpr0_t*>(argA.l),
740 rtype, rdir);
741}
742
743inline texpr0::builder::builder(ap_texpr_op_t op, const builder& argA, const builder& argB, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir)
744{
745 if (!ap_texpr_is_binop(op))
746 throw std::invalid_argument("apron::texpr0::builder::builder(ap_texpr_op_t, const builder&, const builder&, ap_texpr_rtype_t, ap_texpr_rdir_t) not a binary operator");
747 l = ap_texpr0_binop(op,
748 const_cast<ap_texpr0_t*>(argA.l),
749 const_cast<ap_texpr0_t*>(argB.l),
750 rtype, rdir);
751}
752
753
754/* 'intelligent' constructors */
755
756inline texpr0::builder unary(ap_texpr_op_t op, const texpr0::builder& a,
757 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
758 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
759{
760 return texpr0::builder(op, a, rtype, rdir);
761}
762
763inline texpr0::builder binary(ap_texpr_op_t op, const texpr0::builder& a, const texpr0::builder& b,
764 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
765 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
766{
767 return texpr0::builder(op, a, b, rtype, rdir);
768}
769
770
771inline texpr0::builder add(const texpr0::builder& a, const texpr0::builder& b,
772 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
773 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
774{
775 return texpr0::builder(AP_TEXPR_ADD, a, b, rtype, rdir);
776}
777
778inline texpr0::builder sub(const texpr0::builder& a, const texpr0::builder& b,
779 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
780 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
781{
782 return texpr0::builder(AP_TEXPR_SUB, a, b, rtype, rdir);
783}
784
785inline texpr0::builder mul(const texpr0::builder& a, const texpr0::builder& b,
786 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
787 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
788{
789 return texpr0::builder(AP_TEXPR_MUL, a, b, rtype, rdir);
790}
791
792inline texpr0::builder div(const texpr0::builder& a, const texpr0::builder& b,
793 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
794 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
795{
796 return texpr0::builder(AP_TEXPR_DIV, a, b, rtype, rdir);
797}
798
799inline texpr0::builder mod(const texpr0::builder& a, const texpr0::builder& b,
800 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
801 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
802{
803 return texpr0::builder(AP_TEXPR_MOD, a, b, rtype, rdir);
804}
805
806inline texpr0::builder pow(const texpr0::builder& a, const texpr0::builder& b,
807 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
808 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
809{
810 return texpr0::builder(AP_TEXPR_POW, a, b, rtype, rdir);
811}
812
813inline texpr0::builder neg(const texpr0::builder& a,
814 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
815 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
816{
817 return texpr0::builder(AP_TEXPR_NEG, a, rtype, rdir);
818}
819
820inline texpr0::builder cast(const texpr0::builder& a, ap_texpr_rtype_t rtype,
821 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
822{
823 return texpr0::builder(AP_TEXPR_CAST, a, rtype, rdir);
824}
825
826inline texpr0::builder floor(const texpr0::builder& a)
827{
828 return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_DOWN);
829}
830
831inline texpr0::builder ceil(const texpr0::builder& a)
832{
833 return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_UP);
834}
835
836inline texpr0::builder trunc(const texpr0::builder& a)
837{
838 return texpr0::builder(AP_TEXPR_CAST, a, AP_RTYPE_INT, AP_RDIR_ZERO);
839}
840
841inline texpr0::builder sqrt(const texpr0::builder& a,
842 ap_texpr_rtype_t rtype = AP_RTYPE_REAL,
843 ap_texpr_rdir_t rdir = AP_RDIR_NEAREST)
844{
845 return texpr0::builder(AP_TEXPR_SQRT, a, rtype, rdir);
846}
847
848inline texpr0::builder operator+(const texpr0::builder& a)
849{
850 return a;
851}
852
853inline texpr0::builder operator-(const texpr0::builder& a)
854{
855 return neg(a);
856}
857
858inline texpr0::builder operator+(const texpr0::builder& a, const texpr0::builder& b)
859{
860 return add(a,b);
861}
862
863inline texpr0::builder operator-(const texpr0::builder& a, const texpr0::builder& b)
864{
865 return sub(a,b);
866}
867
868inline texpr0::builder operator*(const texpr0::builder& a, const texpr0::builder& b)
869{
870 return mul(a,b);
871}
872
873inline texpr0::builder operator/(const texpr0::builder& a, const texpr0::builder& b)
874{
875 return div(a,b);
876}
877
878inline texpr0::builder operator%(const texpr0::builder& a, const texpr0::builder& b)
879{
880 return mod(a,b);
881}
882
883inline texpr0::builder operator^(const texpr0::builder& a, const texpr0::builder& b)
884{
885 return pow(a,b);
886}
887
888
889/* destructor */
890/* ========== */
891
892inline texpr0::builder::~builder()
893{
894 switch(l->discr){
895 case AP_TEXPR_CST: ap_coeff_clear(&l->val.cst); break;
896 case AP_TEXPR_DIM: break;
897 case AP_TEXPR_NODE: free(l->val.node); break;
898 default: assert(false);
899 }
900 free(l);
901}
902
903inline bool texpr0::builder::is_zero() const
904{
905 return l->discr==AP_TEXPR_CST && ap_coeff_zero(&const_cast<ap_texpr0_t*>(l)->val.cst);
906}
907
908
909/* C-level compatibility */
910/* ===================== */
911
912inline ap_texpr0_t* texpr0::builder::get_ap_texpr0_t()
913{
914 return l;
915}
916
917inline const ap_texpr0_t* texpr0::builder::get_ap_texpr0_t() const
918{
919 return l;
920}
std::vector< std::string > * get_varname(std::basic_ostream< charT, Traits > &os)
Definition apxx_dimension_inline.hh:43
bool is_binop(ap_texpr_op_t op)
Definition apxx_texpr0_inline.hh:37
texpr0::builder floor(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:826
texpr0::builder trunc(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:836
texpr0::builder sqrt(const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0_inline.hh:841
texpr0::builder sub(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_inline.hh:778
texpr0::builder operator/(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:873
texpr0::builder div(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_inline.hh:792
texpr0::builder cast(const texpr0::builder &a, ap_texpr_rtype_t rtype, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0_inline.hh:820
texpr0::builder binary(ap_texpr_op_t op, 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_inline.hh:763
texpr0::builder pow(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_inline.hh:806
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_inline.hh:771
texpr0::builder operator%(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:878
texpr0::builder unary(ap_texpr_op_t op, const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0_inline.hh:756
texpr0::builder operator^(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:883
std::ostream & operator<<(std::ostream &os, const texpr0 &s)
Definition apxx_texpr0_inline.hh:152
void apxx_texpr0_ostream(std::ostream &os, ap_texpr0_t *a, std::vector< std::string > *names)
texpr0::builder operator*(const texpr0::builder &a, const texpr0::builder &b)
Definition apxx_texpr0_inline.hh:868
texpr0::builder mod(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_inline.hh:799
texpr0::builder operator+(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:848
texpr0::builder operator-(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:853
texpr0::builder neg(const texpr0::builder &a, ap_texpr_rtype_t rtype=AP_RTYPE_REAL, ap_texpr_rdir_t rdir=AP_RDIR_NEAREST)
Definition apxx_texpr0_inline.hh:813
texpr0::builder ceil(const texpr0::builder &a)
Definition apxx_texpr0_inline.hh:831
bool is_unop(ap_texpr_op_t op)
Definition apxx_texpr0_inline.hh:32
texpr0::builder mul(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_inline.hh:785