isl_stream_next_token: treat "-0" as two tokens '-' and '0'
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 15 Sep 2011 12:25:51 +0000 (14:25 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 15 Sep 2011 12:25:51 +0000 (14:25 +0200)
Usually, a '-' followed by a sequence of digits is treated as a single
(negative) number.  When parsing affine expressions, negative numbers
are allowed without a preceding '+'.  However, if "-0" is parsed as '0'
then there is no way of distinguishing between "-0" and "0" and so "-0"
was not allowed in affine expressions.
We now treat "-0" as two tokens, so that it can be used in affine expressions.
The flip side is that "-0" can no longer be used where a single integer
is expected.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_stream.c
isl_test.c

index 01a2caa..3643893 100644 (file)
@@ -391,6 +391,7 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                }
        }
        if (c == '-' || isdigit(c)) {
+               int minus = c == '-';
                tok = isl_token_new(s->ctx, line, col, old_line != line);
                if (!tok)
                        return NULL;
@@ -405,6 +406,15 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                        isl_stream_ungetc(s, c);
                isl_stream_push_char(s, '\0');
                isl_int_read(tok->u.v, s->buffer);
+               if (minus && isl_int_is_zero(tok->u.v)) {
+                       tok->col++;
+                       tok->on_new_line = 0;
+                       isl_stream_push_token(s, tok);
+                       tok = isl_token_new(s->ctx, line, col, old_line != line);
+                       if (!tok)
+                               return NULL;
+                       tok->type = (enum isl_token_type) '-';
+               }
                return tok;
        }
        if (isalpha(c) || c == '_') {
index 075650a..a0173b3 100644 (file)
@@ -140,6 +140,10 @@ void test_parse(struct isl_ctx *ctx)
        str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
        test_parse_map_equal(ctx, str, str2);
 
+       str = "{ [x] : x >= 0 }";
+       str2 = "{ [x] : x-0 >= 0 }";
+       test_parse_map_equal(ctx, str, str2);
+
        test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
        test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
 }