This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Changes for v3 of the C++ patch


For reference, here's the diff of the v3 C++ patch to the v2 patch,
in case it's useful:

gcc/cp/ChangeLog:
	* parser.c (token_pair::require_open): Use tabs rather than spaces.
	(token_pair::peek_open): Delete.
	(token_pair::require_close): Use tabs rather than spaces.
	(cp_parser_compound_literal_p): Remove consumption of opening
	paren.
	(cp_parser_postfix_expression): Add matching_parens instance.  Use
	it to consume the opening paren previously consumed by
	cp_parser_compound_literal_p.  Convert call to cp_parser_require
	to parens.require_close.
	(cp_parser_sizeof_operand): Convert call to parens.peek_open to
	call to consume_open to consume the opening paren previously
	consumed by cp_parser_compound_literal_p.
---
 gcc/cp/parser.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3037ac7..0da92ab 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4527,7 +4527,7 @@ class token_pair
   {
     m_open_loc = cp_lexer_peek_token (parser->lexer)->location;
     return cp_parser_require (parser, traits_t::open_token_type,
-                              traits_t::required_token_open);
+			      traits_t::required_token_open);
   }
 
   /* Consume the next token from PARSER, recording its location as
@@ -4541,16 +4541,6 @@ class token_pair
     return tok;
   }
 
-  /* Peek the next token from PARSER, recording its location as
-     that of the opening token within the pair.  */
-
-  void peek_open (cp_parser *parser)
-  {
-    cp_token *tok = cp_lexer_peek_token (parser->lexer);
-    gcc_assert (tok->type == traits_t::open_token_type);
-    m_open_loc = tok->location;
-  }
-
   /* If the next token is the closing symbol for this pair, consume it
      and return it.
      Otherwise, issue an error, highlighting the location of the
@@ -4559,8 +4549,8 @@ class token_pair
   cp_token *require_close (cp_parser *parser) const
   {
     return cp_parser_require (parser, traits_t::close_token_type,
-                              traits_t::required_token_close,
-                              m_open_loc);
+			      traits_t::required_token_close,
+			      m_open_loc);
   }
 
  private:
@@ -6443,9 +6433,6 @@ cp_parser_qualifying_entity (cp_parser *parser,
 static bool
 cp_parser_compound_literal_p (cp_parser *parser)
 {
-  /* Consume the `('.  */
-  cp_lexer_consume_token (parser->lexer);
-
   cp_lexer_save_tokens (parser->lexer);
 
   /* Skip tokens until the next token is a closing parenthesis.
@@ -6857,6 +6844,9 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 
 	    cp_parser_parse_tentatively (parser);
 
+	    matching_parens parens;
+	    parens.consume_open (parser);
+
 	    /* Avoid calling cp_parser_type_id pointlessly, see comment
 	       in cp_parser_cast_expression about c++/29234.  */
 	    if (!cp_parser_compound_literal_p (parser))
@@ -6868,8 +6858,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 		parser->in_type_id_in_expr_p = true;
 		type = cp_parser_type_id (parser);
 		parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
-		/* Look for the `)'.  */
-		cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+		parens.require_close (parser);
 	      }
 
 	    /* If things aren't going well, there's no need to
@@ -27773,12 +27762,13 @@ cp_parser_sizeof_operand (cp_parser* parser, enum rid keyword)
     {
       tree type = NULL_TREE;
 
-      matching_parens parens;
-      parens.peek_open (parser);
-
       /* We can't be sure yet whether we're looking at a type-id or an
 	 expression.  */
       cp_parser_parse_tentatively (parser);
+
+      matching_parens parens;
+      parens.consume_open (parser);
+
       /* Note: as a GNU Extension, compound literals are considered
 	 postfix-expressions as they are in C99, so they are valid
 	 arguments to sizeof.  See comment in cp_parser_cast_expression
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]