export isl_pw_aff_coalesce
[isl.git] / isl_obj.c
blob928982daad210425f2f65efceea9b92eb886291b
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8 * 91893 Orsay, France
9 */
11 #include <isl/set.h>
12 #include <isl/map.h>
13 #include <isl/obj.h>
15 struct isl_int_obj {
16 int ref;
17 isl_ctx *ctx;
18 isl_int v;
21 __isl_give isl_int_obj *isl_int_obj_alloc(isl_ctx *ctx, isl_int v)
23 isl_int_obj *i;
25 i = isl_alloc_type(ctx, isl_int_obj);
26 if (!i)
27 return NULL;
29 i->ctx = ctx;
30 isl_ctx_ref(ctx);
31 i->ref = 1;
32 isl_int_init(i->v);
33 isl_int_set(i->v, v);
35 return i;
38 __isl_give isl_int_obj *isl_int_obj_copy(__isl_keep isl_int_obj *i)
40 if (!i)
41 return NULL;
43 i->ref++;
44 return i;
47 __isl_give isl_int_obj *isl_int_obj_dup(__isl_keep isl_int_obj *i)
49 if (!i)
50 return NULL;
52 return isl_int_obj_alloc(i->ctx, i->v);
55 __isl_give isl_int_obj *isl_int_obj_cow(__isl_take isl_int_obj *i)
57 if (!i)
58 return NULL;
60 if (i->ref == 1)
61 return i;
62 i->ref--;
63 return isl_int_obj_dup(i);
66 void isl_int_obj_free(__isl_take isl_int_obj *i)
68 if (!i)
69 return;
71 if (--i->ref > 0)
72 return;
74 isl_ctx_deref(i->ctx);
75 isl_int_clear(i->v);
76 free(i);
79 __isl_give isl_int_obj *isl_int_obj_add(__isl_take isl_int_obj *i1,
80 __isl_take isl_int_obj *i2)
82 i1 = isl_int_obj_cow(i1);
83 if (!i1 || !i2)
84 goto error;
86 isl_int_add(i1->v, i1->v, i2->v);
88 isl_int_obj_free(i2);
89 return i1;
90 error:
91 isl_int_obj_free(i1);
92 isl_int_obj_free(i2);
93 return NULL;
96 __isl_give isl_int_obj *isl_int_obj_sub(__isl_take isl_int_obj *i1,
97 __isl_take isl_int_obj *i2)
99 i1 = isl_int_obj_cow(i1);
100 if (!i1 || !i2)
101 goto error;
103 isl_int_sub(i1->v, i1->v, i2->v);
105 isl_int_obj_free(i2);
106 return i1;
107 error:
108 isl_int_obj_free(i1);
109 isl_int_obj_free(i2);
110 return NULL;
113 __isl_give isl_int_obj *isl_int_obj_mul(__isl_take isl_int_obj *i1,
114 __isl_take isl_int_obj *i2)
116 i1 = isl_int_obj_cow(i1);
117 if (!i1 || !i2)
118 goto error;
120 isl_int_mul(i1->v, i1->v, i2->v);
122 isl_int_obj_free(i2);
123 return i1;
124 error:
125 isl_int_obj_free(i1);
126 isl_int_obj_free(i2);
127 return NULL;
130 void isl_int_obj_get_int(__isl_keep isl_int_obj *i, isl_int *v)
132 if (!i)
133 return;
134 isl_int_set(*v, i->v);
137 static void *isl_obj_int_copy(void *v)
139 return isl_int_obj_copy((isl_int_obj *)v);
142 static void isl_obj_int_free(void *v)
144 isl_int_obj_free((isl_int_obj *)v);
147 static __isl_give isl_printer *isl_obj_int_print(__isl_take isl_printer *p,
148 void *v)
150 isl_int_obj *i = v;
151 return isl_printer_print_isl_int(p, i->v);
154 static void *isl_obj_int_add(void *v1, void *v2)
156 return isl_int_obj_add((isl_int_obj *)v1, (isl_int_obj *)v2);
159 struct isl_obj_vtable isl_obj_int_vtable = {
160 isl_obj_int_copy,
161 isl_obj_int_add,
162 isl_obj_int_print,
163 isl_obj_int_free
166 static void *isl_obj_map_copy(void *v)
168 return isl_map_copy((struct isl_map *)v);
171 static void isl_obj_map_free(void *v)
173 isl_map_free((struct isl_map *)v);
176 static __isl_give isl_printer *isl_obj_map_print(__isl_take isl_printer *p,
177 void *v)
179 return isl_printer_print_map(p, (struct isl_map *)v);
182 static void *isl_obj_map_add(void *v1, void *v2)
184 return isl_map_union((struct isl_map *)v1, (struct isl_map *)v2);
187 struct isl_obj_vtable isl_obj_map_vtable = {
188 isl_obj_map_copy,
189 isl_obj_map_add,
190 isl_obj_map_print,
191 isl_obj_map_free
194 static void *isl_obj_union_map_copy(void *v)
196 return isl_union_map_copy((isl_union_map *)v);
199 static void isl_obj_union_map_free(void *v)
201 isl_union_map_free((isl_union_map *)v);
204 static __isl_give isl_printer *isl_obj_union_map_print(__isl_take isl_printer *p,
205 void *v)
207 return isl_printer_print_union_map(p, (isl_union_map *)v);
210 static void *isl_obj_union_map_add(void *v1, void *v2)
212 return isl_union_map_union((isl_union_map *)v1, (isl_union_map *)v2);
215 struct isl_obj_vtable isl_obj_union_map_vtable = {
216 isl_obj_union_map_copy,
217 isl_obj_union_map_add,
218 isl_obj_union_map_print,
219 isl_obj_union_map_free
222 static void *isl_obj_set_copy(void *v)
224 return isl_set_copy((struct isl_set *)v);
227 static void isl_obj_set_free(void *v)
229 isl_set_free((struct isl_set *)v);
232 static __isl_give isl_printer *isl_obj_set_print(__isl_take isl_printer *p,
233 void *v)
235 return isl_printer_print_set(p, (struct isl_set *)v);
238 static void *isl_obj_set_add(void *v1, void *v2)
240 return isl_set_union((struct isl_set *)v1, (struct isl_set *)v2);
243 struct isl_obj_vtable isl_obj_set_vtable = {
244 isl_obj_set_copy,
245 isl_obj_set_add,
246 isl_obj_set_print,
247 isl_obj_set_free
250 static void *isl_obj_union_set_copy(void *v)
252 return isl_union_set_copy((isl_union_set *)v);
255 static void isl_obj_union_set_free(void *v)
257 isl_union_set_free((isl_union_set *)v);
260 static __isl_give isl_printer *isl_obj_union_set_print(__isl_take isl_printer *p,
261 void *v)
263 return isl_printer_print_union_set(p, (isl_union_set *)v);
266 static void *isl_obj_union_set_add(void *v1, void *v2)
268 return isl_union_set_union((isl_union_set *)v1, (isl_union_set *)v2);
271 struct isl_obj_vtable isl_obj_union_set_vtable = {
272 isl_obj_union_set_copy,
273 isl_obj_union_set_add,
274 isl_obj_union_set_print,
275 isl_obj_union_set_free
278 static void *isl_obj_none_copy(void *v)
280 return v;
283 static void isl_obj_none_free(void *v)
287 static __isl_give isl_printer *isl_obj_none_print(__isl_take isl_printer *p,
288 void *v)
290 return p;
293 static void *isl_obj_none_add(void *v1, void *v2)
295 return NULL;
298 struct isl_obj_vtable isl_obj_none_vtable = {
299 isl_obj_none_copy,
300 isl_obj_none_add,
301 isl_obj_none_print,
302 isl_obj_none_free
305 static void *isl_obj_pw_qp_copy(void *v)
307 return isl_pw_qpolynomial_copy((struct isl_pw_qpolynomial *)v);
310 static void isl_obj_pw_qp_free(void *v)
312 isl_pw_qpolynomial_free((struct isl_pw_qpolynomial *)v);
315 static __isl_give isl_printer *isl_obj_pw_qp_print(__isl_take isl_printer *p,
316 void *v)
318 return isl_printer_print_pw_qpolynomial(p,
319 (struct isl_pw_qpolynomial *)v);
322 static void *isl_obj_pw_qp_add(void *v1, void *v2)
324 return isl_pw_qpolynomial_add((struct isl_pw_qpolynomial *)v1,
325 (struct isl_pw_qpolynomial *)v2);
328 struct isl_obj_vtable isl_obj_pw_qpolynomial_vtable = {
329 isl_obj_pw_qp_copy,
330 isl_obj_pw_qp_add,
331 isl_obj_pw_qp_print,
332 isl_obj_pw_qp_free
335 static void *isl_obj_union_pw_qp_copy(void *v)
337 return isl_union_pw_qpolynomial_copy((struct isl_union_pw_qpolynomial *)v);
340 static void isl_obj_union_pw_qp_free(void *v)
342 isl_union_pw_qpolynomial_free((struct isl_union_pw_qpolynomial *)v);
345 static __isl_give isl_printer *isl_obj_union_pw_qp_print(
346 __isl_take isl_printer *p, void *v)
348 return isl_printer_print_union_pw_qpolynomial(p,
349 (struct isl_union_pw_qpolynomial *)v);
352 static void *isl_obj_union_pw_qp_add(void *v1, void *v2)
354 return isl_union_pw_qpolynomial_add(
355 (struct isl_union_pw_qpolynomial *)v1,
356 (struct isl_union_pw_qpolynomial *)v2);
359 struct isl_obj_vtable isl_obj_union_pw_qpolynomial_vtable = {
360 isl_obj_union_pw_qp_copy,
361 isl_obj_union_pw_qp_add,
362 isl_obj_union_pw_qp_print,
363 isl_obj_union_pw_qp_free
366 static void *isl_obj_pw_qpf_copy(void *v)
368 return isl_pw_qpolynomial_fold_copy((struct isl_pw_qpolynomial_fold *)v);
371 static void isl_obj_pw_qpf_free(void *v)
373 isl_pw_qpolynomial_fold_free((struct isl_pw_qpolynomial_fold *)v);
376 static __isl_give isl_printer *isl_obj_pw_qpf_print(__isl_take isl_printer *p,
377 void *v)
379 return isl_printer_print_pw_qpolynomial_fold(p,
380 (struct isl_pw_qpolynomial_fold *)v);
383 static void *isl_obj_pw_qpf_add(void *v1, void *v2)
385 return isl_pw_qpolynomial_fold_fold((struct isl_pw_qpolynomial_fold *)v1,
386 (struct isl_pw_qpolynomial_fold *)v2);
389 struct isl_obj_vtable isl_obj_pw_qpolynomial_fold_vtable = {
390 isl_obj_pw_qpf_copy,
391 isl_obj_pw_qpf_add,
392 isl_obj_pw_qpf_print,
393 isl_obj_pw_qpf_free
396 static void *isl_obj_union_pw_qpf_copy(void *v)
398 return isl_union_pw_qpolynomial_fold_copy((struct isl_union_pw_qpolynomial_fold *)v);
401 static void isl_obj_union_pw_qpf_free(void *v)
403 isl_union_pw_qpolynomial_fold_free((struct isl_union_pw_qpolynomial_fold *)v);
406 static __isl_give isl_printer *isl_obj_union_pw_qpf_print(
407 __isl_take isl_printer *p, void *v)
409 return isl_printer_print_union_pw_qpolynomial_fold(p,
410 (struct isl_union_pw_qpolynomial_fold *)v);
413 static void *isl_obj_union_pw_qpf_add(void *v1, void *v2)
415 return isl_union_pw_qpolynomial_fold_fold(
416 (struct isl_union_pw_qpolynomial_fold *)v1,
417 (struct isl_union_pw_qpolynomial_fold *)v2);
420 struct isl_obj_vtable isl_obj_union_pw_qpolynomial_fold_vtable = {
421 isl_obj_union_pw_qpf_copy,
422 isl_obj_union_pw_qpf_add,
423 isl_obj_union_pw_qpf_print,
424 isl_obj_union_pw_qpf_free