C++ PATCH: More parser tweaks

Mark Mitchell mark@codesourcery.com
Wed Jul 10 11:22:00 GMT 2002


Another change to make code accessible in the new parser, and cleaner
in the old parser.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-07-10  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (unqualified_name_lookup_error): Declare it.
	(begin_function_definition): Adjust prototype.
	* lex.c (unqualified_name_lookup_error): New function, split out
	from ...
	(do_identifier): ... here.
	* parse.y (parse_begin_function_definition): New function.
	(fn.def1): Use it.
	* semantics.c (begin_function_definition): Accept decl-specifiers
	and attributes as separate parameters.

Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.728
diff -c -p -r1.728 cp-tree.h
*** cp-tree.h	9 Jul 2002 23:31:27 -0000	1.728
--- cp-tree.h	10 Jul 2002 18:06:17 -0000
*************** extern void note_got_semicolon			PARAMS 
*** 4062,4067 ****
--- 4062,4068 ----
  extern void note_list_got_semicolon		PARAMS ((tree));
  extern void do_pending_lang_change		PARAMS ((void));
  extern void see_typename			PARAMS ((void));
+ extern void unqualified_name_lookup_error       PARAMS ((tree));
  extern tree do_identifier			PARAMS ((tree, int, tree));
  extern tree do_scoped_id			PARAMS ((tree, tree));
  extern tree identifier_typedecl_value		PARAMS ((tree));
*************** extern tree finish_fname                
*** 4285,4291 ****
  extern void save_type_access_control		PARAMS ((tree));
  extern void reset_type_access_control           PARAMS ((void));
  extern void decl_type_access_control		PARAMS ((tree));
! extern int begin_function_definition            PARAMS ((tree, tree));
  extern tree begin_constructor_declarator        PARAMS ((tree, tree));
  extern tree finish_declarator                   PARAMS ((tree, tree, tree, tree, int));
  extern void finish_translation_unit             PARAMS ((void));
--- 4286,4292 ----
  extern void save_type_access_control		PARAMS ((tree));
  extern void reset_type_access_control           PARAMS ((void));
  extern void decl_type_access_control		PARAMS ((tree));
! extern int begin_function_definition            (tree, tree, tree);
  extern tree begin_constructor_declarator        PARAMS ((tree, tree));
  extern tree finish_declarator                   PARAMS ((tree, tree, tree, tree, int));
  extern void finish_translation_unit             PARAMS ((void));
Index: lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.286
diff -c -p -r1.286 lex.c
*** lex.c	24 Jun 2002 19:18:42 -0000	1.286
--- lex.c	10 Jul 2002 18:06:18 -0000
*************** is_global (d)
*** 1125,1130 ****
--- 1125,1164 ----
        }
  }
  
+ /* Issue an error message indicating that the lookup of NAME (an
+    IDENTIFIER_NODE) failed.  */
+ 
+ void
+ unqualified_name_lookup_error (tree name)
+ {
+   if (IDENTIFIER_OPNAME_P (name))
+     {
+       if (name != ansi_opname (ERROR_MARK))
+ 	error ("`%D' not defined", name);
+     }
+   else if (current_function_decl == 0)
+     error ("`%D' was not declared in this scope", name);
+   else
+     {
+       if (IDENTIFIER_NAMESPACE_VALUE (name) != error_mark_node
+ 	  || IDENTIFIER_ERROR_LOCUS (name) != current_function_decl)
+ 	{
+ 	  static int undeclared_variable_notice;
+ 
+ 	  error ("`%D' undeclared (first use this function)", name);
+ 
+ 	  if (! undeclared_variable_notice)
+ 	    {
+ 	      error ("(Each undeclared identifier is reported only once for each function it appears in.)");
+ 	      undeclared_variable_notice = 1;
+ 	    }
+ 	}
+       /* Prevent repeated error messages.  */
+       SET_IDENTIFIER_NAMESPACE_VALUE (name, error_mark_node);
+       SET_IDENTIFIER_ERROR_LOCUS (name, current_function_decl);
+     }
+ }
+ 
  tree
  do_identifier (token, parsing, args)
       register tree token;
*************** do_identifier (token, parsing, args)
*** 1175,1210 ****
        else if (IDENTIFIER_TYPENAME_P (token))
  	/* A templated conversion operator might exist.  */
  	return token;
-       else if (IDENTIFIER_OPNAME_P (token))
- 	{
- 	  if (token != ansi_opname (ERROR_MARK))
- 	    error ("`%D' not defined", token);
- 	  id = error_mark_node;
- 	}
-       else if (current_function_decl == 0)
- 	{
- 	  error ("`%D' was not declared in this scope", token);
- 	  id = error_mark_node;
- 	}
        else
  	{
! 	  if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
! 	      || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
! 	    {
! 	      static int undeclared_variable_notice;
! 
! 	      error ("`%D' undeclared (first use this function)", token);
! 
! 	      if (! undeclared_variable_notice)
! 		{
! 		  error ("(Each undeclared identifier is reported only once for each function it appears in.)");
! 		  undeclared_variable_notice = 1;
! 		}
! 	    }
! 	  id = error_mark_node;
! 	  /* Prevent repeated error messages.  */
! 	  SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
! 	  SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
  	}
      }
  
--- 1209,1218 ----
        else if (IDENTIFIER_TYPENAME_P (token))
  	/* A templated conversion operator might exist.  */
  	return token;
        else
  	{
! 	  unqualified_name_lookup_error (token);
! 	  return error_mark_node;
  	}
      }
  
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parse.y,v
retrieving revision 1.270
diff -c -p -r1.270 parse.y
*** parse.y	9 Jul 2002 23:31:28 -0000	1.270
--- parse.y	10 Jul 2002 18:06:18 -0000
*************** static tree parse_scoped_id PARAMS ((tre
*** 130,135 ****
--- 130,136 ----
  static tree parse_xref_tag (tree, tree, int);
  static tree parse_handle_class_head (tree, tree, tree, int, int *);
  static void parse_decl_instantiation (tree, tree, tree);
+ static int parse_begin_function_definition (tree, tree);
  
  /* Cons up an empty parameter list.  */
  static inline tree
*************** constructor_declarator:
*** 856,874 ****
  fn.def1:
  	  typed_declspecs declarator
  		{ check_for_new_type ("return type", $1);
! 		  if (!begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| declmods notype_declarator
! 		{ if (!begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| notype_declarator
! 		{ if (!begin_function_definition (NULL_TREE, $1))
  		    YYERROR1; }
  	| declmods constructor_declarator
! 		{ if (!begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| constructor_declarator
! 		{ if (!begin_function_definition (NULL_TREE, $1))
  		    YYERROR1; }
  	;
  
--- 857,875 ----
  fn.def1:
  	  typed_declspecs declarator
  		{ check_for_new_type ("return type", $1);
! 		  if (!parse_begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| declmods notype_declarator
! 		{ if (!parse_begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| notype_declarator
! 		{ if (!parse_begin_function_definition (NULL_TREE, $1))
  		    YYERROR1; }
  	| declmods constructor_declarator
! 		{ if (!parse_begin_function_definition ($1.t, $2))
  		    YYERROR1; }
  	| constructor_declarator
! 		{ if (!parse_begin_function_definition (NULL_TREE, $1))
  		    YYERROR1; }
  	;
  
*************** parse_decl_instantiation (tree declspecs
*** 4083,4088 ****
--- 4084,4102 ----
  {
    tree decl = grokdeclarator (declarator, declspecs, NORMAL, 0, NULL);
    do_decl_instantiation (decl, storage);
+ }
+ 
+ /* Like begin_function_definition, but SPECS_ATTRS is a combined list
+    containing both a decl-specifier-seq and attributes.  */
+ 
+ static int
+ parse_begin_function_definition (tree specs_attrs, tree declarator)
+ {
+   tree specs;
+   tree attrs;
+   
+   split_specs_attrs (specs_attrs, &specs, &attrs);
+   return begin_function_definition (specs, attrs, declarator);
  }
  
  #include "gt-cp-parse.h"
Index: semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.267
diff -c -p -r1.267 semantics.c
*** semantics.c	9 Jul 2002 23:31:28 -0000	1.267
--- semantics.c	10 Jul 2002 18:06:19 -0000
*************** reset_type_access_control ()
*** 1517,1536 ****
    current_type_lookups = NULL_TREE;
  }
  
! /* Begin a function definition declared with DECL_SPECS and
!    DECLARATOR.  Returns non-zero if the function-declaration is
     legal.  */
  
  int
! begin_function_definition (decl_specs, declarator)
       tree decl_specs;
       tree declarator;
  {
!   tree specs;
!   tree attrs;
! 
!   split_specs_attrs (decl_specs, &specs, &attrs);
!   if (!start_function (specs, declarator, attrs, SF_DEFAULT))
      return 0;
  
    deferred_type_access_control ();
--- 1517,1533 ----
    current_type_lookups = NULL_TREE;
  }
  
! /* Begin a function definition declared with DECL_SPECS, ATTRIBUTES,
!    and DECLARATOR.  Returns non-zero if the function-declaration is
     legal.  */
  
  int
! begin_function_definition (decl_specs, attributes, declarator)
       tree decl_specs;
+      tree attributes;
       tree declarator;
  {
!   if (!start_function (decl_specs, declarator, attributes, SF_DEFAULT))
      return 0;
  
    deferred_type_access_control ();



More information about the Gcc-patches mailing list