Re: [GSoC][match-and-simplify] reject builtin operator as for variable

2014-08-08 Thread Richard Biener
On Fri, Aug 8, 2014 at 12:42 AM, Prathamesh Kulkarni
bilbotheelffri...@gmail.com wrote:
 reject operator to be used as variable in for.
 eg:
 (for mult in plus minus)
   

 * genmatch.c (get_operator): New function.
  (e_operation::e_operation): Adjust to call get_operator.
  (parse_for): Add call to get_operator.

Thanks, committed.

Richard.

 Thanks,
 Prathamesh


[GSoC][match-and-simplify] reject builtin operator as for variable

2014-08-07 Thread Prathamesh Kulkarni
reject operator to be used as variable in for.
eg:
(for mult in plus minus)
  

* genmatch.c (get_operator): New function.
 (e_operation::e_operation): Adjust to call get_operator.
 (parse_for): Add call to get_operator.

Thanks,
Prathamesh
Index: genmatch.c
===
--- genmatch.c	(revision 213709)
+++ genmatch.c	(working copy)
@@ -290,17 +290,16 @@ is_a_helper expr *::test (operand *op)
   return op-type == operand::OP_EXPR;
 }
 
-
-e_operation::e_operation (const char *id, bool is_commutative_, bool add_new_id)
+id_base *
+get_operator (const char *id)
 {
-  is_commutative = is_commutative_;
   id_base tem (id_base::CODE, id);
 
-  op = operators-find_with_hash (tem, tem.hashval);
+  id_base *op = operators-find_with_hash (tem, tem.hashval);
   if (op)
-return;
+return op; 
 
-  /* Try all-uppercase.  */
+   /* Try all-uppercase.  */
   char *id2 = xstrdup (id);
   for (unsigned i = 0; i  strlen (id2); ++i)
 id2[i] = TOUPPER (id2[i]);
@@ -309,7 +308,7 @@ e_operation::e_operation (const char *id
   if (op)
 {
   free (id2);
-  return;
+  return op;
 }
 
   /* Try _EXPR appended.  */
@@ -320,9 +319,19 @@ e_operation::e_operation (const char *id
   if (op)
 {
   free (id2);
-  return;
+  return op;
 }
 
+  return 0;
+}
+
+e_operation::e_operation (const char *id, bool is_commutative_, bool add_new_id)
+{
+  is_commutative = is_commutative_;
+  op = get_operator (id);
+  if (op)
+return;
+
   if (add_new_id == false)
 fatal (%s is not an operator/built-in function, id);
 
@@ -2105,6 +2114,9 @@ parse_for (cpp_reader *r, source_locatio
   const char *user_id = get_ident (r);
   eat_ident (r, in);
 
+  if (get_operator (user_id) != 0)
+fatal_at (peek (r), %s is an operator, cannot be used as variable in for, user_id);
+
   vecconst char * opers = vNULL;
 
   const cpp_token *token;