public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [match-and-simplify] allow 't' only in user-defined predicates
@ 2014-12-16 14:32 Prathamesh Kulkarni
  2014-12-16 14:54 ` Prathamesh Kulkarni
  0 siblings, 1 reply; 2+ messages in thread
From: Prathamesh Kulkarni @ 2014-12-16 14:32 UTC (permalink / raw)
  To: rguenther, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

This patch rejects 't' outside user-defined predicates.

2014-12-16  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

        * genmatch.c (parser::parsing_match): New.
        (parser::parser): Initialize parsing_match to false.
        (parser::parse_pattern): Reset parsing_match when parsing
user-defined                       predicate.
        (parser::parse_c_expr): Check if 't' is used when parsing_match is set.

Thanks,
Prathamesh

[-- Attachment #2: t-patch.txt --]
[-- Type: text/plain, Size: 1693 bytes --]

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 218778)
+++ gcc/genmatch.c	(working copy)
@@ -2746,6 +2746,7 @@
   vec<simplify *> simplifiers;
   vec<predicate_id *> user_predicates;
   bool parsing_match_operand;
+  bool parsing_match;
 };
 
 /* Lexing helpers.  */
@@ -3059,8 +3060,11 @@
       /* If this is possibly a user-defined identifier mark it used.  */
       if (token->type == CPP_NAME)
 	{
-	  id_base *idb = get_operator ((const char *)CPP_HASHNODE
-				      (token->val.node.node)->ident.str);
+	  const char *lexeme = (const char *) CPP_HASHNODE (token->val.node.node)->ident.str;
+	  if (strcmp (lexeme, "t") == 0 && !parsing_match)
+	    fatal_at (token, "'t' is allowed only in predicates");
+
+	  id_base *idb = get_operator (lexeme);
 	  user_id *p;
 	  if (idb && (p = dyn_cast<user_id *> (idb)) && p->is_oper_list)
 	    record_operlist (token->src_loc, p);
@@ -3497,6 +3501,7 @@
     parse_simplify (token->src_loc, simplifiers, NULL, NULL);
   else if (strcmp (id, "match") == 0)
     {
+      parsing_match = true;
       bool with_args = false;
       if (peek ()->type == CPP_OPEN_PAREN)
 	{
@@ -3530,6 +3535,7 @@
 	fatal_at (token, "non-matching number of match operands");
       p->nargs = e ? e->ops.length () : 0;
       parse_simplify (token->src_loc, p->matchers, p, e);
+      parsing_match = false;
     }
   else if (strcmp (id, "for") == 0)
     parse_for (token->src_loc);
@@ -3569,6 +3575,7 @@
   oper_lists = vNULL;
   user_predicates = vNULL;
   parsing_match_operand = false;
+  parsing_match = false;
 
   const cpp_token *token = next ();
   while (token->type != CPP_EOF)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [match-and-simplify] allow 't' only in user-defined predicates
  2014-12-16 14:32 [match-and-simplify] allow 't' only in user-defined predicates Prathamesh Kulkarni
@ 2014-12-16 14:54 ` Prathamesh Kulkarni
  0 siblings, 0 replies; 2+ messages in thread
From: Prathamesh Kulkarni @ 2014-12-16 14:54 UTC (permalink / raw)
  To: rguenther, gcc-patches

sorry for the noise. I sent it just before our conversation on IRC.

On 16 December 2014 at 19:58, Prathamesh Kulkarni
<prathamesh.kulkarni@linaro.org> wrote:
> This patch rejects 't' outside user-defined predicates.
>
> 2014-12-16  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
>
>         * genmatch.c (parser::parsing_match): New.
>         (parser::parser): Initialize parsing_match to false.
>         (parser::parse_pattern): Reset parsing_match when parsing
> user-defined                       predicate.
>         (parser::parse_c_expr): Check if 't' is used when parsing_match is set.
>
> Thanks,
> Prathamesh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-16 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-16 14:32 [match-and-simplify] allow 't' only in user-defined predicates Prathamesh Kulkarni
2014-12-16 14:54 ` Prathamesh Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).