Re: [GSoC][match-and-simplify] include is-a.h

2014-07-30 Thread Richard Biener
On Tue, Jul 29, 2014 at 4:10 PM, Prathamesh Kulkarni
bilbotheelffri...@gmail.com wrote:
 On Mon, Jul 28, 2014 at 7:30 PM, David Malcolm dmalc...@redhat.com wrote:
 On Mon, 2014-07-28 at 02:35 +0530, Prathamesh Kulkarni wrote:
 -  if (o-type == operand::OP_CAPTURE)
 +  if (is_acapture * (o))
  {
 -  capture *c = static_castcapture * (o);
 -  fprintf (f, @%s, (static_castcapture * (o))-where);
 +  capture *c = as_acapture * (o);

 FWIW, if you're doing an is_aT followed by a new declaration with an
 as_aT, that can be done in one line with is-a.h as:

  if (capture *c = dyn_cast capture * (o))



 Thanks, fixed in this patch.

 * genmatch.c (print_operand): Adjust to use dyn_cast.

Committed.

Richard.

 Regards,
 Prathamesh


Re: [GSoC][match-and-simplify] include is-a.h

2014-07-29 Thread Prathamesh Kulkarni
On Mon, Jul 28, 2014 at 7:30 PM, David Malcolm dmalc...@redhat.com wrote:
 On Mon, 2014-07-28 at 02:35 +0530, Prathamesh Kulkarni wrote:
 -  if (o-type == operand::OP_CAPTURE)
 +  if (is_acapture * (o))
  {
 -  capture *c = static_castcapture * (o);
 -  fprintf (f, @%s, (static_castcapture * (o))-where);
 +  capture *c = as_acapture * (o);

 FWIW, if you're doing an is_aT followed by a new declaration with an
 as_aT, that can be done in one line with is-a.h as:

  if (capture *c = dyn_cast capture * (o))



Thanks, fixed in this patch.

* genmatch.c (print_operand): Adjust to use dyn_cast.

Regards,
Prathamesh
Index: genmatch.c
===
--- genmatch.c	(revision 213124)
+++ genmatch.c	(working copy)
@@ -448,9 +448,8 @@ struct decision_tree
 DEBUG_FUNCTION void
 print_operand (operand *o, FILE *f = stderr, bool flattened = false)
 {
-  if (is_acapture * (o))
+  if (capture *c = dyn_castcapture * (o))
 {
-  capture *c = as_acapture * (o); 
   fprintf (f, @%s, c-where);
   if (c-what  flattened == false) 
 	{
@@ -460,15 +459,14 @@ print_operand (operand *o, FILE *f = std
 	}
 }
 
-  else if (is_apredicate * (o))
-fprintf (f, %s, (as_apredicate * (o))-ident);
+  else if (predicate *p = dyn_castpredicate * (o))
+fprintf (f, %s, p-ident);
 
   else if (is_ac_expr * (o))
 fprintf (f, c_expr);
 
-  else if (is_aexpr * (o))
+  else if (expr *e = dyn_castexpr * (o))
 {
-  expr *e = as_aexpr * (o); 
   fprintf (f, (%s, e-operation-op-id);
 
   if (flattened == false)


Re: [GSoC][match-and-simplify] include is-a.h

2014-07-28 Thread Richard Biener
On Sun, Jul 27, 2014 at 11:05 PM, Prathamesh Kulkarni
bilbotheelffri...@gmail.com wrote:
 Is it okay to include is-a.h ?
 I have adjusted print_operand to use is_a and as_a in this patch.

 * genmatch.c (is-a.h): Include.
 (is_a_helper::test): Specialize for operand subclasses.
 (print_operand): Adjust to use is_a and as_a.

Yes, this is fine.

Applied.

Thanks,
Richard.

 Thanks,
 Prathamesh.


Re: [GSoC][match-and-simplify] include is-a.h

2014-07-28 Thread David Malcolm
On Mon, 2014-07-28 at 02:35 +0530, Prathamesh Kulkarni wrote:
 -  if (o-type == operand::OP_CAPTURE)
 +  if (is_acapture * (o))
  {
 -  capture *c = static_castcapture * (o);
 -  fprintf (f, @%s, (static_castcapture * (o))-where);
 +  capture *c = as_acapture * (o); 

FWIW, if you're doing an is_aT followed by a new declaration with an
as_aT, that can be done in one line with is-a.h as:

 if (capture *c = dyn_cast capture * (o))





[GSoC][match-and-simplify] include is-a.h

2014-07-27 Thread Prathamesh Kulkarni
Is it okay to include is-a.h ?
I have adjusted print_operand to use is_a and as_a in this patch.

* genmatch.c (is-a.h): Include.
(is_a_helper::test): Specialize for operand subclasses.
(print_operand): Adjust to use is_a and as_a.

Thanks,
Prathamesh.
Index: genmatch.c
===
--- genmatch.c	(revision 212928)
+++ genmatch.c	(working copy)
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.
 #include hashtab.h
 #include hash-table.h
 #include vec.h
+#include is-a.h
 
 /* libccp helpers.  */
 
@@ -256,6 +257,39 @@ struct capture : public operand
   virtual void gen_transform (FILE *f, const char *, bool);
 };
 
+template
+template
+inline bool
+is_a_helper capture *::test (operand *op)
+{
+  return op-type == operand::OP_CAPTURE;
+}
+
+template
+template
+inline bool
+is_a_helper predicate *::test (operand *op)
+{
+  return op-type == operand::OP_PREDICATE;
+}
+
+template
+template
+inline bool
+is_a_helper c_expr *::test (operand *op)
+{
+  return op-type == operand::OP_C_EXPR;
+}
+
+template
+template
+inline bool
+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)
 {
   is_commutative = is_commutative_;
@@ -415,10 +449,10 @@ struct decision_tree
 DEBUG_FUNCTION void
 print_operand (operand *o, FILE *f = stderr, bool flattened = false)
 {
-  if (o-type == operand::OP_CAPTURE)
+  if (is_acapture * (o))
 {
-  capture *c = static_castcapture * (o);
-  fprintf (f, @%s, (static_castcapture * (o))-where);
+  capture *c = as_acapture * (o); 
+  fprintf (f, @%s, c-where);
   if (c-what  flattened == false) 
 	{
 	  putc (':', f);
@@ -427,15 +461,15 @@ print_operand (operand *o, FILE *f = std
 	}
 }
 
-  else if (o-type == operand::OP_PREDICATE)
-fprintf (f, %s, (static_castpredicate * (o))-ident);
+  else if (is_apredicate * (o))
+fprintf (f, %s, (as_apredicate * (o))-ident);
 
-  else if (o-type == operand::OP_C_EXPR)
+  else if (is_ac_expr * (o))
 fprintf (f, c_expr);
 
-  else if (o-type == operand::OP_EXPR)
+  else if (is_aexpr * (o))
 {
-  expr *e = static_castexpr * (o);
+  expr *e = as_aexpr * (o); 
   fprintf (f, (%s, e-operation-op-id);
 
   if (flattened == false)