add isl_ast_expr_is_equal
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 5 Jun 2013 12:21:53 +0000 (5 14:21 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 27 Jul 2013 09:04:00 +0000 (27 11:04 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/ast.h
isl_ast.c

index 5b6cc36..c4601ee 100644 (file)
@@ -5994,6 +5994,14 @@ Return the identifier represented by the AST expression.
 
 Return the integer represented by the AST expression.
 
+=head3 Properties of ASTs
+
+       #include <isl/ast.h>
+       int isl_ast_expr_is_equal(__isl_keep isl_ast_expr *expr1,
+               __isl_keep isl_ast_expr *expr2);
+
+Check if two C<isl_ast_expr>s are equal to each other.
+
 =head3 Manipulating and printing the AST
 
 AST nodes can be copied and freed using the following functions.
index 5ac28ed..76f1d38 100644 (file)
@@ -96,6 +96,9 @@ int isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr);
 __isl_give isl_ast_expr *isl_ast_expr_get_op_arg(__isl_keep isl_ast_expr *expr,
        int pos);
 
+int isl_ast_expr_is_equal(__isl_keep isl_ast_expr *expr1,
+       __isl_keep isl_ast_expr *expr2);
+
 __isl_give isl_printer *isl_printer_print_ast_expr(__isl_take isl_printer *p,
        __isl_keep isl_ast_expr *expr);
 void isl_ast_expr_dump(__isl_keep isl_ast_expr *expr);
index 4e294fe..b52041f 100644 (file)
--- a/isl_ast.c
+++ b/isl_ast.c
@@ -1,3 +1,12 @@
+/*
+ * Copyright 2012-2013 Ecole Normale Superieure
+ *
+ * Use of this software is governed by the MIT license
+ *
+ * Written by Sven Verdoolaege,
+ * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
+ */
+
 #include <isl_ast_private.h>
 
 #undef BASE
@@ -312,6 +321,44 @@ error:
        return isl_ast_expr_free(expr);
 }
 
+/* Is "expr1" equal to "expr2"?
+ */
+int isl_ast_expr_is_equal(__isl_keep isl_ast_expr *expr1,
+       __isl_keep isl_ast_expr *expr2)
+{
+       int i;
+
+       if (!expr1 || !expr2)
+               return -1;
+
+       if (expr1 == expr2)
+               return 1;
+       if (expr1->type != expr2->type)
+               return 0;
+       switch (expr1->type) {
+       case isl_ast_expr_int:
+               return isl_val_eq(expr1->u.v, expr2->u.v);
+       case isl_ast_expr_id:
+               return expr1->u.id == expr2->u.id;
+       case isl_ast_expr_op:
+               if (expr1->u.op.op != expr2->u.op.op)
+                       return 0;
+               if (expr1->u.op.n_arg != expr2->u.op.n_arg)
+                       return 0;
+               for (i = 0; i < expr1->u.op.n_arg; ++i) {
+                       int equal;
+                       equal = isl_ast_expr_is_equal(expr1->u.op.args[i],
+                                                       expr2->u.op.args[i]);
+                               return 0;
+                       if (equal < 0 || !equal)
+                               return equal;
+               }
+               return 1;
+       case isl_ast_expr_error:
+               return -1;
+       }
+}
+
 /* Create a new operation expression of operation type "op",
  * with "n_arg" as yet unspecified arguments.
  */