New C parser patch, version 6

Joseph S. Myers joseph@codesourcery.com
Wed Jan 5 20:41:00 GMT 2005


As there have been various changes to the existing C parser in the
past couple of months, here is a sixth version of my new one which is
updated to current CVS.  Bootstrapped with no regressions on
x86_64-unknown-linux-gnu.  More test coverage is still needed.

Full patch attached compressed, below are the changes to the parser
only from the previously sent version.  (Copyright notices would also be 
updated as required to include 2005 with a final commit, but not in 
interim patch versions to avoid conflicts with subsequent changes to 
affected files in mainline.)

Changes within the parser:

* Update to correspond with changes to old parser.

* Adjustments to error recovery.

* Corrections to handling missing semicolon at end of struct, as
  detected by testcases I added to mainline since the last version.

Other changes (mainly testsuite) which went into mainline are also no
longer in this patch.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2005-01-05  Joseph S. Myers  <joseph@codesourcery.com>

	* c-parser.c: New file.
	* c-parse.in: Remove.
	* Makefile.in (c-parse.o-warn, c-parse.o, c-parse.c, c-parse.y):
	Remove.
	(c-parser.o): Add dependencies.
	(C_AND_OBJC_OBJC, C_OBJS, gcc.srcextra, GTFILES, distclean,
	maintainer-clean, TAGS): Update.
	* c-config-lang.in (gtfiles): Update.
	* gengtype-lex.l: Don't handle "@@".
	* stub-objc.c (objc_get_class_ivars, objc_build_throw_stmt,
	objc_build_synchronized, objc_begin_try_stmt,
	objc_begin_catch_clause, objc_finish_catch_clause,
	objc_build_finally_clause, objc_finish_try_stmt): New.
	* c-tree.h (struct c_declspecs): Add declspecs_seen_p and
	type_seen_p.
	(c_parse_init): Update comment.
	* c-decl.c (c_init_decl_processing): Update comment.
	(build_null_declspecs, declspecs_add_qual, declspecs_add_type,
	declspecs_add_scspec, declspecs_add_attrs): Initialize and update
	new c_declspecs members.

objc:
2005-01-05  Joseph S. Myers  <joseph@codesourcery.com>

	* Make-lang.in (objc/objc-parse.o-warn, objc/objc-parse.o,
	objc/objc-parse.c, objc/objc-parse.y): Remove
	(OBJC_OBJS, objc.srcextra, objc.tags, objc.mostlyclean,
	objc.distclean, objc.maintainer-clean): Update for new parser.
	* config-lang.in (gtfiles): Update for new parser.

testsuite:
2005-01-05  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/cpp/separate-1.c, gcc.dg/noncompile/971104-1.c,
	gcc.dg/noncompile/990416-1.c: Adjust expected messages for new
	parser.

--- c-parser.c-v5	2004-11-04 20:50:17.000000000 +0000
+++ c-parser.c-v6	2005-01-05 16:56:22.000000000 +0000
@@ -725,7 +725,7 @@ c_parser_skip_until_found (c_parser *par
       if (token->type == type && !nesting_depth)
 	{
 	  c_parser_consume_token (parser);
-	  return;
+	  break;
 	}
       /* If we've run out of tokens, stop.  */
       if (token->type == CPP_EOF)
@@ -739,15 +739,12 @@ c_parser_skip_until_found (c_parser *par
 	       || token->type == CPP_CLOSE_SQUARE)
 	{
 	  if (nesting_depth-- == 0)
-	    {
-	      parser->error = false;
-	      return;
-	    }
+	    break;
 	}
       /* Consume this token.  */
       c_parser_consume_token (parser);
-      parser->error = false;
     }
+  parser->error = false;
 }
 
 /* Skip tokens until the end of a parameter is found, but do not
@@ -763,10 +760,7 @@ c_parser_skip_to_end_of_parameter (c_par
       c_token *token = c_parser_peek_token (parser);
       if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON)
 	  && !nesting_depth)
-	{
-	  parser->error = false;
-	  return;
-	}
+	break;
       /* If we've run out of tokens, stop.  */
       if (token->type == CPP_EOF)
 	return;
@@ -779,15 +773,12 @@ c_parser_skip_to_end_of_parameter (c_par
 	       || token->type == CPP_CLOSE_SQUARE)
 	{
 	  if (nesting_depth-- == 0)
-	    {
-	      parser->error = false;
-	      return;
-	    }
+	    break;
 	}
       /* Consume this token.  */
       c_parser_consume_token (parser);
-      parser->error = false;
     }
+  parser->error = false;
 }
 
 /* Skip tokens until we have consumed an entire block, or until we
@@ -806,7 +797,7 @@ c_parser_skip_to_end_of_block_or_stateme
       token = c_parser_peek_token (parser);
       /* If we've run out of tokens, stop.  */
       if (token->type == CPP_EOF)
-	break;
+	return;
       /* If the next token is a ';', we have reached the end of the
 	 statement.  */
       if (token->type == CPP_SEMICOLON && !nesting_depth)
@@ -1220,18 +1211,24 @@ c_parser_declaration_or_fndef (c_parser 
 		 its initializer is parsed.  */
 	      d = start_decl (declarator, specs, true,
 			      chainon (postfix_attrs, all_prefix_attrs));
+	      if (!d)
+		d = error_mark_node;
 	      start_init (d, asm_name, global_bindings_p ());
 	      init = c_parser_initializer (parser);
 	      finish_init ();
-	      maybe_warn_string_init (TREE_TYPE (d), init);
-	      finish_decl (d, init.value, asm_name);
+	      if (d != error_mark_node)
+		{
+		  maybe_warn_string_init (TREE_TYPE (d), init);
+		  finish_decl (d, init.value, asm_name);
+		}
 	    }
 	  else
 	    {
 	      tree d = start_decl (declarator, specs, false,
 				   chainon (postfix_attrs,
 					    all_prefix_attrs));
-	      finish_decl (d, NULL_TREE, asm_name);
+	      if (d)
+		finish_decl (d, NULL_TREE, asm_name);
 	    }
 	  if (c_parser_next_token_is (parser, CPP_COMMA))
 	    {
@@ -1936,6 +1933,7 @@ c_parser_struct_declaration (c_parser *p
       if (c_parser_next_token_is (parser, CPP_COLON)
 	  || c_parser_next_token_is (parser, CPP_COMMA)
 	  || c_parser_next_token_is (parser, CPP_SEMICOLON)
+	  || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)
 	  || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
 	{
 	  tree postfix_attrs = NULL_TREE;
@@ -1960,21 +1958,23 @@ c_parser_struct_declaration (c_parser *p
 	    all_prefix_attrs = prefix_attrs;
 	  if (c_parser_next_token_is (parser, CPP_COMMA))
 	    c_parser_consume_token (parser);
-	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
+	  else if (c_parser_next_token_is (parser, CPP_SEMICOLON)
+		   || c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
 	    {
 	      /* Semicolon consumed in caller.  */
 	      break;
 	    }
 	  else
 	    {
-	      c_parser_error (parser, "expected %<,%> or %<;%>");
+	      c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>");
 	      break;
 	    }
 	}
       else
 	{
 	  c_parser_error (parser,
-			  "expected %<:%>, %<,%>, %<;%> or %<__attribute__%>");
+			  "expected %<:%>, %<,%>, %<;%>, %<}%> or "
+			  "%<__attribute__%>");
 	  break;
 	}
     }
@@ -2583,9 +2583,8 @@ c_parser_asm_string_literal (c_parser *p
     }
   else if (c_parser_next_token_is (parser, CPP_WSTRING))
     {
-      /* ??? At present, following the old parser, wide strings are
-	 handled like narrow strings here.  */
-      str = c_parser_peek_token (parser)->value;
+      error ("wide string literal in %<asm%>");
+      str = build_string (1, "");
       c_parser_consume_token (parser);
     }
   else
@@ -3220,6 +3219,9 @@ c_parser_compound_statement_nostart (c_p
 	    }
 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 	}
+      /* ??? Locating this diagnostic on the token after the
+	 declarations end follows the old parser, but it might be
+	 better to locate it where the declarations start instead.  */
       if (pedantic)
 	pedwarn ("ISO C forbids label declarations");
     }
@@ -5008,7 +5010,7 @@ c_parser_postfix_expression (c_parser *p
 	    c = fold (e1.value);
 	    STRIP_NOPS (c);
 	    if (TREE_CODE (c) != INTEGER_CST)
-	      error ("first argument to __builtin_choose_expr not"
+	      error ("first argument to %<__builtin_choose_expr%> not"
 		     " a constant");
 	    expr = integer_zerop (c) ? e3 : e2;
 	  }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c-parser-patch-version-6.gz
Type: application/octet-stream
Size: 62989 bytes
Desc: 
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20050105/5ce724b5/attachment.obj>


More information about the Gcc-patches mailing list