isl_stream_read_map: accept rational affine expressions
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 1 Mar 2012 10:02:01 +0000 (11:02 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 2 Aug 2012 10:20:09 +0000 (12:20 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_input.c
isl_test.c

index 1282224..b3a845d 100644 (file)
@@ -283,7 +283,6 @@ static __isl_give isl_pw_aff *accept_div(struct isl_stream *s,
        __isl_take isl_space *dim, struct vars *v)
 {
        struct isl_token *tok;
-       int seen_paren = 0;
        int f = 0;
        int c = 0;
        isl_pw_aff *pwaff = NULL;
@@ -298,8 +297,6 @@ static __isl_give isl_pw_aff *accept_div(struct isl_stream *s,
        } else {
                if (isl_stream_eat(s, '['))
                        goto error;
-               if (isl_stream_eat_if_available(s, '('))
-                       seen_paren = 1;
        }
 
        pwaff = accept_affine(s, isl_space_copy(dim), v);
@@ -307,24 +304,19 @@ static __isl_give isl_pw_aff *accept_div(struct isl_stream *s,
        if (f || c) {
                if (isl_stream_eat(s, ','))
                        goto error;
-       } else {
-               if (seen_paren && isl_stream_eat(s, ')'))
+
+               tok = next_token(s);
+               if (!tok)
                        goto error;
-               if (isl_stream_eat(s, '/'))
+               if (tok->type != ISL_TOKEN_VALUE) {
+                       isl_stream_error(s, tok, "expected denominator");
+                       isl_stream_push_token(s, tok);
                        goto error;
+               }
+               isl_pw_aff_scale_down(pwaff,  tok->u.v);
+               isl_token_free(tok);
        }
 
-       tok = next_token(s);
-       if (!tok)
-               goto error;
-       if (tok->type != ISL_TOKEN_VALUE) {
-               isl_stream_error(s, tok, "expected denominator");
-               isl_stream_push_token(s, tok);
-               goto error;
-       }
-       isl_pw_aff_scale_down(pwaff,  tok->u.v);
-       isl_token_free(tok);
-
        if (c)
                pwaff = isl_pw_aff_ceil(pwaff);
        else
@@ -430,6 +422,17 @@ static __isl_give isl_pw_aff *accept_affine_factor(struct isl_stream *s,
                res = isl_pw_aff_scale(res, f);
                isl_int_clear(f);
        }
+       if (isl_stream_eat_if_available(s, '/')) {
+               isl_int f;
+               isl_int_init(f);
+               isl_int_set_si(f, 1);
+               if (accept_cst_factor(s, &f) < 0) {
+                       isl_int_clear(f);
+                       goto error2;
+               }
+               res = isl_pw_aff_scale_down(res, f);
+               isl_int_clear(f);
+       }
 
        isl_space_free(dim);
        return res;
index d9cf3cc..45f8c97 100644 (file)
@@ -196,6 +196,10 @@ int test_parse(struct isl_ctx *ctx)
                                      "{ [a] -> [b] : true }") < 0)
                return -1;
 
+       if (test_parse_map_equal(ctx, "{ [i] : i/2 <= 5 }",
+                                     "{ [i] : i <= 10 }") < 0)
+               return -1;
+
        return 0;
 }