This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 01/11] C++: Add location wrappers for all constants and decls
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Nathan Sidwell <nathan at acm dot org>, Jakub Jelinek <jakub at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 17 Nov 2017 21:52:33 -0500
- Subject: [PATCH 01/11] C++: Add location wrappers for all constants and decls
- Authentication-results: sourceware.org; auth=none
- References: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> <1510973563-10046-1-git-send-email-dmalcolm@redhat.com>
This redoes the approach in the v1 patch, doing it for all constants
and decls, rather than just at callsite args.
gcc/cp/ChangeLog:
* parser.c (cp_parser_primary_expression): Add location wrappers
to constants.
(cp_parser_postfix_expression): Remove the "wrap_locations_p"
param to cp_parser_parenthesized_expression_list from the earlier
patch.
(cp_parser_parenthesized_expression_list): Likewise; don't add
location wrappers.
* semantics.c (finish_id_expression): Rename to...
(finish_id_expression_1): ...this.
(finish_id_expression): Reintroduce, wrapping the result in a
location wrapper, if necessary.
---
gcc/cp/parser.c | 29 ++++++++++++----------------
gcc/cp/semantics.c | 56 ++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 54 insertions(+), 31 deletions(-)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 15489c1..8834542 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2054,8 +2054,7 @@ static tree cp_parser_postfix_open_square_expression
static tree cp_parser_postfix_dot_deref_expression
(cp_parser *, enum cpp_ttype, cp_expr, bool, cp_id_kind *, location_t);
static vec<tree, va_gc> *cp_parser_parenthesized_expression_list
- (cp_parser *, int, bool, bool, bool *, location_t * = NULL,
- bool = false);
+ (cp_parser *, int, bool, bool, bool *, location_t * = NULL);
/* Values for the second parameter of cp_parser_parenthesized_expression_list. */
enum { non_attr = 0, normal_attr = 1, id_attr = 2 };
static void cp_parser_pseudo_destructor_name
@@ -5066,7 +5065,8 @@ cp_parser_primary_expression (cp_parser *parser,
if (!cast_p)
cp_parser_non_integral_constant_expression (parser, NIC_FLOAT);
}
- return cp_expr (token->u.value, token->location);
+ return (cp_expr (token->u.value, token->location)
+ .maybe_add_location_wrapper ());
case CPP_CHAR_USERDEF:
case CPP_CHAR16_USERDEF:
@@ -5088,9 +5088,10 @@ cp_parser_primary_expression (cp_parser *parser,
/* ??? Should wide strings be allowed when parser->translate_strings_p
is false (i.e. in attributes)? If not, we can kill the third
argument to cp_parser_string_literal. */
- return cp_parser_string_literal (parser,
- parser->translate_strings_p,
- true);
+ return (cp_parser_string_literal (parser,
+ parser->translate_strings_p,
+ true)
+ .maybe_add_location_wrapper ());
case CPP_OPEN_PAREN:
/* If we see `( { ' then we are looking at the beginning of
@@ -7099,8 +7100,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
(parser, non_attr,
/*cast_p=*/false, /*allow_expansion_p=*/true,
/*non_constant_p=*/NULL,
- /*close_paren_loc=*/&close_paren_loc,
- /*wrap_locations_p=*/true));
+ /*close_paren_loc=*/&close_paren_loc));
if (is_builtin_constant_p)
{
parser->integral_constant_expression_p
@@ -7764,8 +7764,7 @@ cp_parser_parenthesized_expression_list (cp_parser* parser,
bool cast_p,
bool allow_expansion_p,
bool *non_constant_p,
- location_t *close_paren_loc,
- bool wrap_locations_p)
+ location_t *close_paren_loc)
{
vec<tree, va_gc> *expression_list;
bool fold_expr_p = is_attribute_list != non_attr;
@@ -7788,12 +7787,12 @@ cp_parser_parenthesized_expression_list (cp_parser* parser,
= parser->greater_than_is_operator_p;
parser->greater_than_is_operator_p = true;
- cp_expr expr (NULL_TREE);
-
/* Consume expressions until there are no more. */
if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN))
while (true)
{
+ tree expr;
+
/* At the beginning of attribute lists, check to see if the
next token is an identifier. */
if (is_attribute_list == id_attr
@@ -7847,15 +7846,11 @@ cp_parser_parenthesized_expression_list (cp_parser* parser,
expr = make_pack_expansion (expr);
}
- if (wrap_locations_p)
- if (!processing_template_decl)
- expr.maybe_add_location_wrapper ();
-
/* Add it to the list. We add error_mark_node
expressions to the list, so that we can still tell if
the correct form for a parenthesized expression-list
is found. That gives better errors. */
- vec_safe_push (expression_list, expr.get_value ());
+ vec_safe_push (expression_list, expr);
if (expr == error_mark_node)
goto skip_comma;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 51489d1..dfdc458 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -3453,20 +3453,20 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
the use of "this" explicit.
Upon return, *IDK will be filled in appropriately. */
-cp_expr
-finish_id_expression (tree id_expression,
- tree decl,
- tree scope,
- cp_id_kind *idk,
- bool integral_constant_expression_p,
- bool allow_non_integral_constant_expression_p,
- bool *non_integral_constant_expression_p,
- bool template_p,
- bool done,
- bool address_p,
- bool template_arg_p,
- const char **error_msg,
- location_t location)
+static cp_expr
+finish_id_expression_1 (tree id_expression,
+ tree decl,
+ tree scope,
+ cp_id_kind *idk,
+ bool integral_constant_expression_p,
+ bool allow_non_integral_constant_expression_p,
+ bool *non_integral_constant_expression_p,
+ bool template_p,
+ bool done,
+ bool address_p,
+ bool template_arg_p,
+ const char **error_msg,
+ location_t location)
{
decl = strip_using_decl (decl);
@@ -3766,6 +3766,34 @@ finish_id_expression (tree id_expression,
return cp_expr (decl, location);
}
+/* As per finish_id_expression_1, but adding a wrapper node
+ around the result if needed to express LOCATION. */
+
+cp_expr
+finish_id_expression (tree id_expression,
+ tree decl,
+ tree scope,
+ cp_id_kind *idk,
+ bool integral_constant_expression_p,
+ bool allow_non_integral_constant_expression_p,
+ bool *non_integral_constant_expression_p,
+ bool template_p,
+ bool done,
+ bool address_p,
+ bool template_arg_p,
+ const char **error_msg,
+ location_t location)
+{
+ cp_expr result
+ = finish_id_expression_1 (id_expression, decl, scope, idk,
+ integral_constant_expression_p,
+ allow_non_integral_constant_expression_p,
+ non_integral_constant_expression_p,
+ template_p, done, address_p, template_arg_p,
+ error_msg, location);
+ return result.maybe_add_location_wrapper ();
+}
+
/* Implement the __typeof keyword: Return the type of EXPR, suitable for
use as a type-specifier. */
--
1.8.5.3