On Sun, Oct 26, 2014 at 7:40 AM, Prathamesh Kulkarni
<bilbotheelffri...@gmail.com> wrote:
> Fixed a silly mistake in match-bitwise.pd (I had put ')' at wrong place).
> This patch also checks if operator-list is used outside for-pattern
> (in parser::parse_operation).

With recent discussion on how to use operator-lists - thus

(for (oplist1 oplist2 ...)
  (simplify (oplist1 @0 @1)...

it shouldn't be necessary to have an is_oper_list member in user_id
as all user_ids are operator-lists this way (just temporarily defined
in for scope eventually).

-         if (arity == -1)
-           arity = idb->nargs;
-         else if (idb->nargs == -1)
-           ;
-         else if (idb->nargs != arity)
-           fatal_at (token, "operator '%s' with arity %d does not match "
-                     "others with arity %d", oper, idb->nargs, arity);
+         vec<id_base *> substitutes = vNULL;
+         if (idb->kind == id_base::USER)
+           substitutes = (as_a<user_id *> (idb))->substitutes;
+         else
+           substitutes.safe_push (idb);

-         op->substitutes.safe_push (idb);
+         for (unsigned si = 0; si < substitutes.length (); ++si)
+           if (!add_substitute (op, substitutes[si], arity))
+             fatal_at (token, "operator '%s' with arity %d does not match "
+                              "others with arity %d", oper, idb->nargs, arity);

an operator-list user_id should have a proper arity computed.  With
the syntax change this probably will look differently anyway.

+void
+parser::parse_operator_list ()
+{
+  const char *id = get_ident ();
+  user_id *op = new user_id (id, true);
+  vec<const cpp_token *> user_id_tokens = vNULL;
+
+  id_base **slot = operators->find_slot_with_hash (op, op->hashval, INSERT);
+  if (*slot)
+    fatal ("operator %s already defined", id);

use get_operator (id) != NULL, otherwise same issue as with the
other already defined check we just fixed.

+      id_base *p = get_operator (oper);
+      if (p == 0)
+       fatal_at (token, "%s is not defined", oper);

I'd say "no such operator '%s'"

+  flatten_substitutes (ids, op->substitutes);

huh, so you support

(define_operator_list list1 a b)
(define_operator_list list2 list1 c)

?  Well, ok.  Any reason to not splice in during parsing?  I also
miss a check for matching arity and computing arity of the
operator list.  That's all be best done here I think, in the loop
parsing the identifiers.

@@ -23,7 +26,7 @@
    binary operation result instead of to the operands.  This allows
    to combine successive conversions and bitwise binary operations.  */
 /* We combine the above two cases by using a conditional convert.  */
-(for bitop (bit_and bit_ior bit_xor)
+(for bitop (bitwise_ops)

as discussed this will change to

(for (bitwise_ops)

instead.  Btw - I'm not sure that using

(define_operator_list bitwise_ors bit_ior bit_xor)
(define_operator_list bitwise_ops bit_and bitwise_ors)

will improve readability.  I'd like to see it mostly for comparisons
and math builtin variants.  For example we have the well-known
term comparison_class, so

(define_operator_list comparison_class lt le eq ne ge gt unordered
ordered unlt unle ungt unge uneq ltgt)

or rather shorter, 'cc' instead of 'comparison_class'.

Thanks,
Richard.

> * genmatch.c
>     (user_id): Add new member is_oper_list.
>     (user_id::user_id): Add new default argument.
>     (parser::parse_operator_list): New member function in parser.
>     (add_substitute): New function.
>     (flatten_substitutes): Likewise.
>     (parser::parse_for): Call add_substitute.
>     (parser::parse_pattern): Call parser::parse_operator_list.
>     (parser::parse_operation): Put check for operator-list.
>
> * match-bitwise.pd
>     (bitwise_ors): New operator-list.
>     (bitwise_ops): Likewise.
>     Use bitwise_ors and bitwise_ops in patterns.
>
> * match-comparison.pd
>      (eq_ops): New operator-list.
>      (cmp_ops): Likewise.
>      Use cmp_ops and eq_ops in patterns.
>
> Thanks,
> Prathamesh
>
>
>
> On Sat, Oct 25, 2014 at 10:44 PM, Prathamesh Kulkarni
> <bilbotheelffri...@gmail.com> wrote:
>> Hi,
>>     This patch adds support for operator-lists, and uses
>> them in match-bitwise.pd and match-comparison.pd
>>
>> * genmatch.c
>>     (parser::parse_operator_list): New member function in parser.
>>     (add_substitute): New function.
>>     (flatten_substitutes): Likewise.
>>     (parser::parse_for): Call add_substitute.
>>     (parser::parse_pattern): Call parser::parse_operator_list.
>>
>> * match-bitwise.pd
>>     (bitwise_ors): New operator-list.
>>     (bitwise_ops): Likewise.
>>     Use bitwise_ors and bitwise_ops in patterns.
>>
>> * match-comparison.pd
>>      (eq_ops): New operator-list.
>>      (cmp_ops): Likewise.
>>      Use cmp_ops and eq_ops in patterns.
>>
>> Thanks,
>> Prathamesh

Reply via email to