isl_map_print: add parentheses around disjuncts
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 15 Feb 2010 09:14:08 +0000 (10:14 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 15 Feb 2010 09:14:47 +0000 (10:14 +0100)
isl_input.c
isl_output.c

index 1fdbc4e..6b0921e 100644 (file)
@@ -597,16 +597,34 @@ error:
 static struct isl_basic_map *read_disjunct(struct isl_stream *s,
        struct vars *v, __isl_take isl_dim *dim)
 {
+       int seen_paren = 0;
+       struct isl_token *tok;
        struct isl_basic_map *bmap;
 
        bmap = isl_basic_map_alloc_dim(dim, 0, 0, 0);
        if (!bmap)
                return NULL;
 
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               goto error;
+       if (tok->type == '(') {
+               seen_paren = 1;
+               isl_token_free(tok);
+       } else
+               isl_stream_push_token(s, tok);
+
        bmap = add_constraints(s, v, bmap);
        bmap = isl_basic_map_simplify(bmap);
        bmap = isl_basic_map_finalize(bmap);
+
+       if (seen_paren && isl_stream_eat(s, ')'))
+               goto error;
+
        return bmap;
+error:
+       isl_basic_map_free(bmap);
+       return NULL;
 }
 
 static struct isl_map *read_disjuncts(struct isl_stream *s,
index 4ffa027..38dfea0 100644 (file)
@@ -419,7 +419,11 @@ static void isl_map_print_isl(__isl_keep isl_map *map, FILE *out, int indent)
        for (i = 0; i < map->n; ++i) {
                if (i)
                        fprintf(out, " or ");
+               if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
+                       fprintf(out, "(");
                print_disjunct(map->p[i], out, 0);
+               if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
+                       fprintf(out, ")");
        }
        fprintf(out, " }\n");
 }