add isl_aff_mod_val
[platform/upstream/isl.git] / isl_stream.c
index 01a2caa..68f6e52 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2008-2009 Katholieke Universiteit Leuven
  *
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
  *
  * Written by Sven Verdoolaege, K.U.Leuven, Departement
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
@@ -173,7 +173,10 @@ struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file)
 
 struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str)
 {
-       struct isl_stream *s = isl_stream_new(ctx);
+       struct isl_stream *s;
+       if (!str)
+               return NULL;
+       s = isl_stream_new(ctx);
        if (!s)
                return NULL;
        s->str = str;
@@ -354,7 +357,6 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
            c == '%' ||
            c == '?' ||
            c == '^' ||
-           c == '=' ||
            c == '@' ||
            c == '$' ||
            c == ',' ||
@@ -391,6 +393,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 +408,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 == '_') {
@@ -446,6 +458,21 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                tok->u.s = strdup(s->buffer);
                return tok;
        }
+       if (c == '=') {
+               int c;
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               if ((c = isl_stream_getc(s)) == '=') {
+                       tok->u.s = strdup("==");
+                       tok->type = ISL_TOKEN_EQ_EQ;
+                       return tok;
+               }
+               if (c != -1)
+                       isl_stream_ungetc(s, c);
+               tok->type = (enum isl_token_type) '=';
+               return tok;
+       }
        if (c == ':') {
                int c;
                tok = isl_token_new(s->ctx, line, col, old_line != line);