isl_map_print: add primes to duplicate names
authorSven Verdoolaege <sven@nestor.cs.kuleuven.be>
Thu, 18 Feb 2010 16:29:09 +0000 (17:29 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 18 Feb 2010 20:38:01 +0000 (21:38 +0100)
And, conversely, accept primes in identifier names in isl_map_read.

isl_input.c
isl_output.c
isl_stream.c

index 6b0921e..dc2b2fd 100644 (file)
@@ -912,8 +912,14 @@ static struct isl_dim *set_names(struct isl_dim *dim, struct vars *vars,
 
        for (i = 0, v = vars->v; i < offset; ++i, v = v->next)
                ;
-       for (i = n - 1; i >= 0; --i, v = v->next)
+       for (i = n - 1; i >= 0; --i, v = v->next) {
+               char *prime = strchr(v->name, '\'');
+               if (prime)
+                       *prime = '\0';
                dim = isl_dim_set_name(dim, type, i, v->name);
+               if (prime)
+                       *prime = '\'';
+       }
 
        return dim;
 }
index 6c1af1a..558ec8a 100644 (file)
@@ -10,6 +10,7 @@
  * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France 
  */
 
+#include <string.h>
 #include <isl_set.h>
 #include <isl_seq.h>
 
@@ -100,16 +101,34 @@ static void isl_set_print_polylib(struct isl_set *set, FILE *out, int indent)
        isl_map_print_polylib((struct isl_map *)set, out, indent);
 }
 
-static print_name(struct isl_dim *dim, FILE *out,
+static int count_same_name(__isl_keep isl_dim *dim,
+       enum isl_dim_type type, unsigned pos, const char *name)
+{
+       enum isl_dim_type t;
+       unsigned p, s;
+       int count = 0;
+
+       for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
+               s = t == type ? pos : isl_dim_size(dim, t);
+               for (p = 0; p < s; ++p) {
+                       const char *n = isl_dim_get_name(dim, t, p);
+                       if (n && !strcmp(n, name))
+                               count++;
+               }
+       }
+       return count;
+}
+
+static void print_name(struct isl_dim *dim, FILE *out,
        enum isl_dim_type type, unsigned pos, int set)
 {
        const char *name;
+       char buffer[20];
+       int primes;
 
        name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
 
-       if (name)
-               fprintf(out, "%s", name);
-       else {
+       if (!name) {
                const char *prefix;
                if (type == isl_dim_param)
                        prefix = "p";
@@ -119,8 +138,14 @@ static print_name(struct isl_dim *dim, FILE *out,
                        prefix = "i";
                else
                        prefix = "o";
-               fprintf(out, "%s%d", prefix, pos);
+               snprintf(buffer, sizeof(buffer), "%s%d", prefix, pos);
+               name = buffer;
        }
+       primes = count_same_name(dim, name == buffer ? isl_dim_div : type,
+                                pos, name);
+       fprintf(out, "%s", name);
+       while (primes-- > 0)
+               fputc('\'', out);
 }
 
 static void print_var_list(struct isl_dim *dim, FILE *out,
index 8715b4f..8d4fca7 100644 (file)
@@ -241,6 +241,10 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                        isl_stream_push_char(s, c);
                if (c != -1)
                        isl_stream_ungetc(s, c);
+               while ((c = isl_stream_getc(s)) != -1 && c == '\'')
+                       isl_stream_push_char(s, c);
+               if (c != -1)
+                       isl_stream_ungetc(s, c);
                isl_stream_push_char(s, '\0');
                if (!strcasecmp(s->buffer, "exists"))
                        tok->type = ISL_TOKEN_EXISTS;