add isl_union_map_flat_range_product
[isl.git] / isl_obj.c
blobfb9fe9758ec634a95ebdd053e381afbe4df2ca3b
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/obj.h>
13 struct isl_int_obj {
14 int ref;
15 isl_ctx *ctx;
16 isl_int v;
19 __isl_give isl_int_obj *isl_int_obj_alloc(isl_ctx *ctx, isl_int v)
21 isl_int_obj *i;
23 i = isl_alloc_type(ctx, isl_int_obj);
24 if (!i)
25 return NULL;
27 i->ctx = ctx;
28 isl_ctx_ref(ctx);
29 i->ref = 1;
30 isl_int_init(i->v);
31 isl_int_set(i->v, v);
33 return i;
36 __isl_give isl_int_obj *isl_int_obj_copy(__isl_keep isl_int_obj *i)
38 if (!i)
39 return NULL;
41 i->ref++;
42 return i;
45 __isl_give isl_int_obj *isl_int_obj_dup(__isl_keep isl_int_obj *i)
47 if (!i)
48 return NULL;
50 return isl_int_obj_alloc(i->ctx, i->v);
53 __isl_give isl_int_obj *isl_int_obj_cow(__isl_take isl_int_obj *i)
55 if (!i)
56 return NULL;
58 if (i->ref == 1)
59 return i;
60 i->ref--;
61 return isl_int_obj_dup(i);
64 void isl_int_obj_free(__isl_take isl_int_obj *i)
66 if (!i)
67 return;
69 if (--i->ref > 0)
70 return;
72 isl_ctx_deref(i->ctx);
73 isl_int_clear(i->v);
74 free(i);
77 __isl_give isl_int_obj *isl_int_obj_add(__isl_take isl_int_obj *i1,
78 __isl_take isl_int_obj *i2)
80 i1 = isl_int_obj_cow(i1);
81 if (!i1 || !i2)
82 goto error;
84 isl_int_add(i1->v, i1->v, i2->v);
86 isl_int_obj_free(i2);
87 return i1;
88 error:
89 isl_int_obj_free(i1);
90 isl_int_obj_free(i2);
91 return NULL;
94 __isl_give isl_int_obj *isl_int_obj_sub(__isl_take isl_int_obj *i1,
95 __isl_take isl_int_obj *i2)
97 i1 = isl_int_obj_cow(i1);
98 if (!i1 || !i2)
99 goto error;
101 isl_int_sub(i1->v, i1->v, i2->v);
103 isl_int_obj_free(i2);
104 return i1;
105 error:
106 isl_int_obj_free(i1);
107 isl_int_obj_free(i2);
108 return NULL;
111 __isl_give isl_int_obj *isl_int_obj_mul(__isl_take isl_int_obj *i1,
112 __isl_take isl_int_obj *i2)
114 i1 = isl_int_obj_cow(i1);
115 if (!i1 || !i2)
116 goto error;
118 isl_int_mul(i1->v, i1->v, i2->v);
120 isl_int_obj_free(i2);
121 return i1;
122 error:
123 isl_int_obj_free(i1);
124 isl_int_obj_free(i2);
125 return NULL;
128 void isl_int_obj_get_int(__isl_keep isl_int_obj *i, isl_int *v)
130 if (!i)
131 return;
132 isl_int_set(*v, i->v);
135 static void *isl_obj_int_copy(void *v)
137 return isl_int_obj_copy((isl_int_obj *)v);
140 static void isl_obj_int_free(void *v)
142 isl_int_obj_free((isl_int_obj *)v);
145 static __isl_give isl_printer *isl_obj_int_print(__isl_take isl_printer *p,
146 void *v)
148 isl_int_obj *i = v;
149 return isl_printer_print_isl_int(p, i->v);
152 static void *isl_obj_int_add(void *v1, void *v2)
154 return isl_int_obj_add((isl_int_obj *)v1, (isl_int_obj *)v2);
157 struct isl_obj_vtable isl_obj_int_vtable = {
158 isl_obj_int_copy,
159 isl_obj_int_add,
160 isl_obj_int_print,
161 isl_obj_int_free
164 static void *isl_obj_map_copy(void *v)
166 return isl_map_copy((struct isl_map *)v);
169 static void isl_obj_map_free(void *v)
171 isl_map_free((struct isl_map *)v);
174 static __isl_give isl_printer *isl_obj_map_print(__isl_take isl_printer *p,
175 void *v)
177 return isl_printer_print_map(p, (struct isl_map *)v);
180 static void *isl_obj_map_add(void *v1, void *v2)
182 return isl_map_union((struct isl_map *)v1, (struct isl_map *)v2);
185 struct isl_obj_vtable isl_obj_map_vtable = {
186 isl_obj_map_copy,
187 isl_obj_map_add,
188 isl_obj_map_print,
189 isl_obj_map_free
192 static void *isl_obj_union_map_copy(void *v)
194 return isl_union_map_copy((isl_union_map *)v);
197 static void isl_obj_union_map_free(void *v)
199 isl_union_map_free((isl_union_map *)v);
202 static __isl_give isl_printer *isl_obj_union_map_print(__isl_take isl_printer *p,
203 void *v)
205 return isl_printer_print_union_map(p, (isl_union_map *)v);
208 static void *isl_obj_union_map_add(void *v1, void *v2)
210 return isl_union_map_union((isl_union_map *)v1, (isl_union_map *)v2);
213 struct isl_obj_vtable isl_obj_union_map_vtable = {
214 isl_obj_union_map_copy,
215 isl_obj_union_map_add,
216 isl_obj_union_map_print,
217 isl_obj_union_map_free
220 static void *isl_obj_set_copy(void *v)
222 return isl_set_copy((struct isl_set *)v);
225 static void isl_obj_set_free(void *v)
227 isl_set_free((struct isl_set *)v);
230 static __isl_give isl_printer *isl_obj_set_print(__isl_take isl_printer *p,
231 void *v)
233 return isl_printer_print_set(p, (struct isl_set *)v);
236 static void *isl_obj_set_add(void *v1, void *v2)
238 return isl_set_union((struct isl_set *)v1, (struct isl_set *)v2);
241 struct isl_obj_vtable isl_obj_set_vtable = {
242 isl_obj_set_copy,
243 isl_obj_set_add,
244 isl_obj_set_print,
245 isl_obj_set_free
248 static void *isl_obj_union_set_copy(void *v)
250 return isl_union_set_copy((isl_union_set *)v);
253 static void isl_obj_union_set_free(void *v)
255 isl_union_set_free((isl_union_set *)v);
258 static __isl_give isl_printer *isl_obj_union_set_print(__isl_take isl_printer *p,
259 void *v)
261 return isl_printer_print_union_set(p, (isl_union_set *)v);
264 static void *isl_obj_union_set_add(void *v1, void *v2)
266 return isl_union_set_union((isl_union_set *)v1, (isl_union_set *)v2);
269 struct isl_obj_vtable isl_obj_union_set_vtable = {
270 isl_obj_union_set_copy,
271 isl_obj_union_set_add,
272 isl_obj_union_set_print,
273 isl_obj_union_set_free
276 static void *isl_obj_none_copy(void *v)
278 return v;
281 static void isl_obj_none_free(void *v)
285 static __isl_give isl_printer *isl_obj_none_print(__isl_take isl_printer *p,
286 void *v)
288 return p;
291 static void *isl_obj_none_add(void *v1, void *v2)
293 return NULL;
296 struct isl_obj_vtable isl_obj_none_vtable = {
297 isl_obj_none_copy,
298 isl_obj_none_add,
299 isl_obj_none_print,
300 isl_obj_none_free
303 static void *isl_obj_pw_qp_copy(void *v)
305 return isl_pw_qpolynomial_copy((struct isl_pw_qpolynomial *)v);
308 static void isl_obj_pw_qp_free(void *v)
310 isl_pw_qpolynomial_free((struct isl_pw_qpolynomial *)v);
313 static __isl_give isl_printer *isl_obj_pw_qp_print(__isl_take isl_printer *p,
314 void *v)
316 return isl_printer_print_pw_qpolynomial(p,
317 (struct isl_pw_qpolynomial *)v);
320 static void *isl_obj_pw_qp_add(void *v1, void *v2)
322 return isl_pw_qpolynomial_add((struct isl_pw_qpolynomial *)v1,
323 (struct isl_pw_qpolynomial *)v2);
326 struct isl_obj_vtable isl_obj_pw_qpolynomial_vtable = {
327 isl_obj_pw_qp_copy,
328 isl_obj_pw_qp_add,
329 isl_obj_pw_qp_print,
330 isl_obj_pw_qp_free
333 static void *isl_obj_union_pw_qp_copy(void *v)
335 return isl_union_pw_qpolynomial_copy((struct isl_union_pw_qpolynomial *)v);
338 static void isl_obj_union_pw_qp_free(void *v)
340 isl_union_pw_qpolynomial_free((struct isl_union_pw_qpolynomial *)v);
343 static __isl_give isl_printer *isl_obj_union_pw_qp_print(
344 __isl_take isl_printer *p, void *v)
346 return isl_printer_print_union_pw_qpolynomial(p,
347 (struct isl_union_pw_qpolynomial *)v);
350 static void *isl_obj_union_pw_qp_add(void *v1, void *v2)
352 return isl_union_pw_qpolynomial_add(
353 (struct isl_union_pw_qpolynomial *)v1,
354 (struct isl_union_pw_qpolynomial *)v2);
357 struct isl_obj_vtable isl_obj_union_pw_qpolynomial_vtable = {
358 isl_obj_union_pw_qp_copy,
359 isl_obj_union_pw_qp_add,
360 isl_obj_union_pw_qp_print,
361 isl_obj_union_pw_qp_free
364 static void *isl_obj_pw_qpf_copy(void *v)
366 return isl_pw_qpolynomial_fold_copy((struct isl_pw_qpolynomial_fold *)v);
369 static void isl_obj_pw_qpf_free(void *v)
371 isl_pw_qpolynomial_fold_free((struct isl_pw_qpolynomial_fold *)v);
374 static __isl_give isl_printer *isl_obj_pw_qpf_print(__isl_take isl_printer *p,
375 void *v)
377 return isl_printer_print_pw_qpolynomial_fold(p,
378 (struct isl_pw_qpolynomial_fold *)v);
381 static void *isl_obj_pw_qpf_add(void *v1, void *v2)
383 return isl_pw_qpolynomial_fold_fold((struct isl_pw_qpolynomial_fold *)v1,
384 (struct isl_pw_qpolynomial_fold *)v2);
387 struct isl_obj_vtable isl_obj_pw_qpolynomial_fold_vtable = {
388 isl_obj_pw_qpf_copy,
389 isl_obj_pw_qpf_add,
390 isl_obj_pw_qpf_print,
391 isl_obj_pw_qpf_free
394 static void *isl_obj_union_pw_qpf_copy(void *v)
396 return isl_union_pw_qpolynomial_fold_copy((struct isl_union_pw_qpolynomial_fold *)v);
399 static void isl_obj_union_pw_qpf_free(void *v)
401 isl_union_pw_qpolynomial_fold_free((struct isl_union_pw_qpolynomial_fold *)v);
404 static __isl_give isl_printer *isl_obj_union_pw_qpf_print(
405 __isl_take isl_printer *p, void *v)
407 return isl_printer_print_union_pw_qpolynomial_fold(p,
408 (struct isl_union_pw_qpolynomial_fold *)v);
411 static void *isl_obj_union_pw_qpf_add(void *v1, void *v2)
413 return isl_union_pw_qpolynomial_fold_fold(
414 (struct isl_union_pw_qpolynomial_fold *)v1,
415 (struct isl_union_pw_qpolynomial_fold *)v2);
418 struct isl_obj_vtable isl_obj_union_pw_qpolynomial_fold_vtable = {
419 isl_obj_union_pw_qpf_copy,
420 isl_obj_union_pw_qpf_add,
421 isl_obj_union_pw_qpf_print,
422 isl_obj_union_pw_qpf_free