isl_stream: treat "-" as operator rather than as -1
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 1 Feb 2010 13:04:17 +0000 (14:04 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 3 Feb 2010 17:29:52 +0000 (18:29 +0100)
isl_input.c
isl_stream.c

index e3cc97a..06267b2 100644 (file)
@@ -140,6 +140,7 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
 {
        struct isl_token *tok = NULL;
        struct isl_vec *aff;
+       int sign = 1;
 
        aff = isl_vec_alloc(v->ctx, 1 + v->n);
        isl_seq_clr(aff->el, aff->size);
@@ -161,7 +162,13 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                                isl_stream_error(s, tok, "unknown identifier");
                                goto error;
                        }
-                       isl_int_add_ui(aff->el[1 + pos], aff->el[1 + pos], 1);
+                       if (sign > 0)
+                               isl_int_add_ui(aff->el[1 + pos],
+                                              aff->el[1 + pos], 1);
+                       else
+                               isl_int_sub_ui(aff->el[1 + pos],
+                                              aff->el[1 + pos], 1);
+                       sign = 1;
                } else if (tok->type == ISL_TOKEN_VALUE) {
                        struct isl_token *tok2;
                        int n = v->n;
@@ -180,8 +187,13 @@ static struct isl_vec *accept_affine(struct isl_stream *s, struct vars *v)
                                isl_token_free(tok2);
                        } else if (tok2)
                                isl_stream_push_token(s, tok2);
+                       if (sign < 0)
+                               isl_int_neg(tok->u.v, tok->u.v);
                        isl_int_add(aff->el[1 + pos],
                                        aff->el[1 + pos], tok->u.v);
+                       sign = 1;
+               } else if (tok->type == '-') {
+                       sign = -sign;
                } else if (tok->type == '+') {
                        /* nothing */
                } else {
index bad3085..192546e 100644 (file)
@@ -204,6 +204,13 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                }
                if (c != -1)
                        isl_stream_ungetc(s, c);
+               if (!isdigit(c)) {
+                       tok = isl_token_new(s->ctx, line, col, old_line != line);
+                       if (!tok)
+                               return NULL;
+                       tok->type = (enum isl_token_type) '-';
+                       return tok;
+               }
        }
        if (c == '-' || isdigit(c)) {
                tok = isl_token_new(s->ctx, line, col, old_line != line);
@@ -218,12 +225,8 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                                goto error;
                if (c != -1)
                        isl_stream_ungetc(s, c);
-               if (s->len == 1 && s->buffer[0] == '-')
-                       isl_int_set_si(tok->u.v, -1);
-               else {
-                       isl_stream_push_char(s, '\0');
-                       isl_int_read(tok->u.v, s->buffer);
-               }
+               isl_stream_push_char(s, '\0');
+               isl_int_read(tok->u.v, s->buffer);
                return tok;
        }
        if (isalpha(c)) {