Commit c56f494f by Richard Biener Committed by Richard Biener

genmatch.c (c_expr::gen_transform): Error on unknown captures.

2015-07-29  Richard Biener  <rguenther@suse.de>

	* genmatch.c (c_expr::gen_transform): Error on unknown captures.
	(parser::parse_capture): Add bool argument on whether to reject
	unknown captures.
	(parser::parse_expr): Adjust.
	(parser::parse_op): Likewise.
	(parser::parse_pattern): Likewise.

From-SVN: r226344
parent 89a79e96
2015-07-29 Richard Biener <rguenther@suse.de> 2015-07-29 Richard Biener <rguenther@suse.de>
* genmatch.c (c_expr::gen_transform): Error on unknown captures.
(parser::parse_capture): Add bool argument on whether to reject
unknown captures.
(parser::parse_expr): Adjust.
(parser::parse_op): Likewise.
(parser::parse_pattern): Likewise.
2015-07-29 Richard Biener <rguenther@suse.de>
* gimple-fold.c (has_use_on_stmt): New function. * gimple-fold.c (has_use_on_stmt): New function.
(replace_stmt_with_simplification): Use it to allow (replace_stmt_with_simplification): Use it to allow
abnormals originally referenced in the stmt. abnormals originally referenced in the stmt.
......
...@@ -2048,7 +2048,10 @@ c_expr::gen_transform (FILE *f, int indent, const char *dest, ...@@ -2048,7 +2048,10 @@ c_expr::gen_transform (FILE *f, int indent, const char *dest,
id = (const char *)n->val.str.text; id = (const char *)n->val.str.text;
else else
id = (const char *)CPP_HASHNODE (n->val.node.node)->ident.str; id = (const char *)CPP_HASHNODE (n->val.node.node)->ident.str;
fprintf (f, "captures[%u]", *capture_ids->get(id)); unsigned *cid = capture_ids->get (id);
if (!cid)
fatal_at (token, "unknown capture id");
fprintf (f, "captures[%u]", *cid);
++i; ++i;
continue; continue;
} }
...@@ -3153,7 +3156,7 @@ private: ...@@ -3153,7 +3156,7 @@ private:
const char *get_number (); const char *get_number ();
id_base *parse_operation (); id_base *parse_operation ();
operand *parse_capture (operand *); operand *parse_capture (operand *, bool);
operand *parse_expr (); operand *parse_expr ();
c_expr *parse_c_expr (cpp_ttype); c_expr *parse_c_expr (cpp_ttype);
operand *parse_op (); operand *parse_op ();
...@@ -3383,7 +3386,7 @@ parser::parse_operation () ...@@ -3383,7 +3386,7 @@ parser::parse_operation ()
capture = '@'<number> */ capture = '@'<number> */
struct operand * struct operand *
parser::parse_capture (operand *op) parser::parse_capture (operand *op, bool require_existing)
{ {
source_location src_loc = eat_token (CPP_ATSIGN)->src_loc; source_location src_loc = eat_token (CPP_ATSIGN)->src_loc;
const cpp_token *token = peek (); const cpp_token *token = peek ();
...@@ -3398,7 +3401,11 @@ parser::parse_capture (operand *op) ...@@ -3398,7 +3401,11 @@ parser::parse_capture (operand *op)
bool existed; bool existed;
unsigned &num = capture_ids->get_or_insert (id, &existed); unsigned &num = capture_ids->get_or_insert (id, &existed);
if (!existed) if (!existed)
{
if (require_existing)
fatal_at (src_loc, "unknown capture id");
num = next_id; num = next_id;
}
return new capture (src_loc, num, op); return new capture (src_loc, num, op);
} }
...@@ -3452,7 +3459,7 @@ parser::parse_expr () ...@@ -3452,7 +3459,7 @@ parser::parse_expr ()
if (token->type == CPP_ATSIGN if (token->type == CPP_ATSIGN
&& !(token->flags & PREV_WHITE)) && !(token->flags & PREV_WHITE))
op = parse_capture (e); op = parse_capture (e, !parsing_match_operand);
else if (force_capture) else if (force_capture)
{ {
unsigned num = capture_ids->elements (); unsigned num = capture_ids->elements ();
...@@ -3604,7 +3611,7 @@ parser::parse_op () ...@@ -3604,7 +3611,7 @@ parser::parse_op ()
if (token->type == CPP_COLON) if (token->type == CPP_COLON)
fatal_at (token, "not implemented: predicate on leaf operand"); fatal_at (token, "not implemented: predicate on leaf operand");
if (token->type == CPP_ATSIGN) if (token->type == CPP_ATSIGN)
op = parse_capture (op); op = parse_capture (op, !parsing_match_operand);
} }
return op; return op;
...@@ -4074,7 +4081,7 @@ parser::parse_pattern () ...@@ -4074,7 +4081,7 @@ parser::parse_pattern ()
capture_ids = new cid_map_t; capture_ids = new cid_map_t;
e = new expr (p, e_loc); e = new expr (p, e_loc);
while (peek ()->type == CPP_ATSIGN) while (peek ()->type == CPP_ATSIGN)
e->append_op (parse_capture (NULL)); e->append_op (parse_capture (NULL, false));
eat_token (CPP_CLOSE_PAREN); eat_token (CPP_CLOSE_PAREN);
} }
if (p->nargs != -1 if (p->nargs != -1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment