isl_pw_*_restrict_domain: use isl_pw_*_n_piece
[isl.git] / isl_pw_morph_templ.c
blobb9f7436a4a1b5a3641881acf5e7512701fca592d
1 /*
2 * Copyright 2010 INRIA Saclay
4 * Use of this software is governed by the MIT 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 __isl_give PW *FN(PW,morph_domain)(__isl_take PW *pw,
12 __isl_take isl_morph *morph)
14 int i;
15 isl_size n;
16 isl_ctx *ctx;
17 isl_space *space;
19 n = FN(PW,n_piece)(pw);
20 if (n < 0 || !morph)
21 goto error;
23 ctx = isl_space_get_ctx(pw->dim);
24 isl_assert(ctx, isl_space_is_domain_internal(morph->dom->dim, pw->dim),
25 goto error);
27 space = FN(PW,take_space)(pw);
28 space = isl_space_extend_domain_with_range(
29 isl_space_copy(morph->ran->dim), space);
30 pw = FN(PW,restore_space)(pw, space);
31 pw = FN(PW,cow)(pw);
32 if (!pw)
33 goto error;
35 for (i = 0; i < n; ++i) {
36 EL *el;
38 pw->p[i].set = isl_morph_set(isl_morph_copy(morph), pw->p[i].set);
39 if (!pw->p[i].set)
40 goto error;
41 el = FN(PW,take_base_at)(pw, i);
42 el = FN(EL,morph_domain)(el, isl_morph_copy(morph));
43 pw = FN(PW,restore_base_at)(pw, i, el);
44 if (!pw)
45 goto error;
48 isl_morph_free(morph);
50 return pw;
51 error:
52 FN(PW,free)(pw);
53 isl_morph_free(morph);
54 return NULL;