m3-sys/m3cc/gcc-apple/gcc/c-decl.c
/* Subroutine of store_parm_decls which handles old-style function
   definitions (separate parameter list and declarations).  */
Subroutine of store_parm_decls which handles old-style function
definitions (separate parameter list and declarations).
Subroutine of store_parm_decls which handles old - style function definitions ( separate parameter list and declarations ) .
static void
store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
{
  struct c_binding *b;
  tree parm, decl, last;
  tree parmids = arg_info->parms;
  struct pointer_set_t *seen_args = pointer_set_create ();
  if (!in_system_header)
    warning (OPT_Wold_style_definition, "%Jold-style function definition",
	     fndecl);
  for (parm = parmids; parm; parm = TREE_CHAIN (parm))
    {
      if (TREE_VALUE (parm) == 0)
	{
	  error ("%Jparameter name missing from parameter list", fndecl);
	  TREE_PURPOSE (parm) = 0;
	  continue;
	}
      b = I_SYMBOL_BINDING (TREE_VALUE (parm));
      if (b && B_IN_CURRENT_SCOPE (b))
	{
	  decl = b->decl;
	  if (TREE_CODE (decl) != PARM_DECL)
	    error ("%q+D declared as a non-parameter", decl);
	  else if (pointer_set_contains (seen_args, decl))
	    {
	      error ("multiple parameters named %q+D", decl);
	      TREE_PURPOSE (parm) = 0;
	      continue;
	    }
	  else if (VOID_TYPE_P (TREE_TYPE (decl)))
	    {
	      error ("parameter %q+D declared with void type", decl);
	      TREE_TYPE (decl) = integer_type_node;
	      DECL_ARG_TYPE (decl) = integer_type_node;
	      layout_decl (decl, 0);
	    }
	  warn_if_shadowing (decl);
	}
      else
	{
	  decl = build_decl (PARM_DECL, TREE_VALUE (parm), integer_type_node);
	  DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
	  DECL_SOURCE_LOCATION (decl) = DECL_SOURCE_LOCATION (fndecl);
	  pushdecl (decl);
	  warn_if_shadowing (decl);
	  if (flag_isoc99)
	    pedwarn ("type of %q+D defaults to %<int%>", decl);
	  else if (extra_warnings)
	    warning (OPT_Wextra, "type of %q+D defaults to %<int%>", decl);
	}
      TREE_PURPOSE (parm) = decl;
      pointer_set_insert (seen_args, decl);
    }
  for (b = current_scope->bindings; b; b = b->prev)
    {
      parm = b->decl;
      if (TREE_CODE (parm) != PARM_DECL)
	continue;
      if (TREE_TYPE (parm) != error_mark_node
	  && !COMPLETE_TYPE_P (TREE_TYPE (parm)))
	{
	  error ("parameter %q+D has incomplete type", parm);
	  TREE_TYPE (parm) = error_mark_node;
	}
      if (!pointer_set_contains (seen_args, parm))
	{
	  error ("declaration for parameter %q+D but no such parameter", parm);
	  parmids = chainon (parmids, tree_cons (parm, 0, 0));
	}
    }
  DECL_ARGUMENTS (fndecl) = 0;
  for (parm = parmids; parm; parm = TREE_CHAIN (parm))
    if (TREE_PURPOSE (parm))
      break;
  if (parm && TREE_PURPOSE (parm))
    {
      last = TREE_PURPOSE (parm);
      DECL_ARGUMENTS (fndecl) = last;
      for (parm = TREE_CHAIN (parm); parm; parm = TREE_CHAIN (parm))
	if (TREE_PURPOSE (parm))
	  {
	    TREE_CHAIN (last) = TREE_PURPOSE (parm);
	    last = TREE_PURPOSE (parm);
	  }
      TREE_CHAIN (last) = 0;
    }
  pointer_set_destroy (seen_args);
  if (current_function_prototype_arg_types)
    {
      tree type;
      for (parm = DECL_ARGUMENTS (fndecl),
	     type = current_function_prototype_arg_types;
	   parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
			     != void_type_node));
	   parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
	{
	  if (parm == 0 || type == 0
	      || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
	    {
	      if (current_function_prototype_built_in)
		warning (0, "number of arguments doesn%'t match "
			 "built-in prototype");
	      else
		{
		  error ("number of arguments doesn%'t match prototype");
		  error ("%Hprototype declaration",
			 &current_function_prototype_locus);
		}
	      break;
	    }
	  if (!comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
			  TYPE_MAIN_VARIANT (TREE_VALUE (type))))
	    {
	      if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
		  == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
		{
		  DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
		  if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
		      && INTEGRAL_TYPE_P (TREE_TYPE (parm))
		      && TYPE_PRECISION (TREE_TYPE (parm))
		      < TYPE_PRECISION (integer_type_node))
		    DECL_ARG_TYPE (parm) = integer_type_node;
		  if (pedantic)
		    {
		      if (current_function_prototype_built_in)
			warning (0, "promoted argument %qD "
				 "doesn%'t match built-in prototype", parm);
		      else
			{
			  pedwarn ("promoted argument %qD "
				   "doesn%'t match prototype", parm);
			  pedwarn ("%Hprototype declaration",
				   &current_function_prototype_locus);
			}
		    }
		}
	      else
		{
		  if (current_function_prototype_built_in)
		    warning (0, "argument %qD doesn%'t match "
			     "built-in prototype", parm);
		  else
		    {
		      error ("argument %qD doesn%'t match prototype", parm);
		      error ("%Hprototype declaration",
			     &current_function_prototype_locus);
		    }
		}
	    }
	}
      TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
    }
  else
    {
      tree actual = 0, last = 0, type;
      for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
	{
	  type = tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), NULL_TREE);
	  if (last)
	    TREE_CHAIN (last) = type;
	  else
	    actual = type;
	  last = type;
	}
      type = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
      if (last)
	TREE_CHAIN (last) = type;
      else
	actual = type;
      TREE_TYPE (fndecl) = build_variant_type_copy (TREE_TYPE (fndecl));
      TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
    }
}
static void store_parm_decls_oldstyle ( tree fndecl , const struct c_arg_info * arg_info ) { struct c_binding * b ; tree parm , decl , last ; tree parmids = arg_info -> parms ; struct pointer_set_t * seen_args = pointer_set_create ( ) ; if ( ! in_system_header ) warning ( OPT_Wold_style_definition , " " , fndecl ) ; for ( parm = parmids ; parm ; parm = TREE_CHAIN ( parm ) ) { if ( TREE_VALUE ( parm ) == 0 ) { error ( " " , fndecl ) ; TREE_PURPOSE ( parm ) = 0 ; continue ; } b = I_SYMBOL_BINDING ( TREE_VALUE ( parm ) ) ; if ( b && B_IN_CURRENT_SCOPE ( b ) ) { decl = b -> decl ; if ( TREE_CODE ( decl ) != PARM_DECL ) error ( " " , decl ) ; else if ( pointer_set_contains ( seen_args , decl ) ) { error ( " " , decl ) ; TREE_PURPOSE ( parm ) = 0 ; continue ; } else if ( VOID_TYPE_P ( TREE_TYPE ( decl ) ) ) { error ( " " , decl ) ; TREE_TYPE ( decl ) = integer_type_node ; DECL_ARG_TYPE ( decl ) = integer_type_node ; layout_decl ( decl , 0 ) ; } warn_if_shadowing ( decl ) ; } else { decl = build_decl ( PARM_DECL , TREE_VALUE ( parm ) , integer_type_node ) ; DECL_ARG_TYPE ( decl ) = TREE_TYPE ( decl ) ; DECL_SOURCE_LOCATION ( decl ) = DECL_SOURCE_LOCATION ( fndecl ) ; pushdecl ( decl ) ; warn_if_shadowing ( decl ) ; if ( flag_isoc99 ) pedwarn ( " " , decl ) ; else if ( extra_warnings ) warning ( OPT_Wextra , " " , decl ) ; } TREE_PURPOSE ( parm ) = decl ; pointer_set_insert ( seen_args , decl ) ; } for ( b = current_scope -> bindings ; b ; b = b -> prev ) { parm = b -> decl ; if ( TREE_CODE ( parm ) != PARM_DECL ) continue ; if ( TREE_TYPE ( parm ) != error_mark_node && ! COMPLETE_TYPE_P ( TREE_TYPE ( parm ) ) ) { error ( " " , parm ) ; TREE_TYPE ( parm ) = error_mark_node ; } if ( ! pointer_set_contains ( seen_args , parm ) ) { error ( " " , parm ) ; parmids = chainon ( parmids , tree_cons ( parm , 0 , 0 ) ) ; } } DECL_ARGUMENTS ( fndecl ) = 0 ; for ( parm = parmids ; parm ; parm = TREE_CHAIN ( parm ) ) if ( TREE_PURPOSE ( parm ) ) break ; if ( parm && TREE_PURPOSE ( parm ) ) { last = TREE_PURPOSE ( parm ) ; DECL_ARGUMENTS ( fndecl ) = last ; for ( parm = TREE_CHAIN ( parm ) ; parm ; parm = TREE_CHAIN ( parm ) ) if ( TREE_PURPOSE ( parm ) ) { TREE_CHAIN ( last ) = TREE_PURPOSE ( parm ) ; last = TREE_PURPOSE ( parm ) ; } TREE_CHAIN ( last ) = 0 ; } pointer_set_destroy ( seen_args ) ; if ( current_function_prototype_arg_types ) { tree type ; for ( parm = DECL_ARGUMENTS ( fndecl ) , type = current_function_prototype_arg_types ; parm || ( type && ( TYPE_MAIN_VARIANT ( TREE_VALUE ( type ) ) != void_type_node ) ) ; parm = TREE_CHAIN ( parm ) , type = TREE_CHAIN ( type ) ) { if ( parm == 0 || type == 0 || TYPE_MAIN_VARIANT ( TREE_VALUE ( type ) ) == void_type_node ) { if ( current_function_prototype_built_in ) warning ( 0 , " " " " ) ; else { error ( " " ) ; error ( " " , & current_function_prototype_locus ) ; } break ; } if ( ! comptypes ( TYPE_MAIN_VARIANT ( DECL_ARG_TYPE ( parm ) ) , TYPE_MAIN_VARIANT ( TREE_VALUE ( type ) ) ) ) { if ( TYPE_MAIN_VARIANT ( TREE_TYPE ( parm ) ) == TYPE_MAIN_VARIANT ( TREE_VALUE ( type ) ) ) { DECL_ARG_TYPE ( parm ) = TREE_TYPE ( parm ) ; if ( targetm . calls . promote_prototypes ( TREE_TYPE ( current_function_decl ) ) && INTEGRAL_TYPE_P ( TREE_TYPE ( parm ) ) && TYPE_PRECISION ( TREE_TYPE ( parm ) ) < TYPE_PRECISION ( integer_type_node ) ) DECL_ARG_TYPE ( parm ) = integer_type_node ; if ( pedantic ) { if ( current_function_prototype_built_in ) warning ( 0 , " " " " , parm ) ; else { pedwarn ( " " " " , parm ) ; pedwarn ( " " , & current_function_prototype_locus ) ; } } } else { if ( current_function_prototype_built_in ) warning ( 0 , " " " " , parm ) ; else { error ( " " , parm ) ; error ( " " , & current_function_prototype_locus ) ; } } } } TYPE_ACTUAL_ARG_TYPES ( TREE_TYPE ( fndecl ) ) = 0 ; } else { tree actual = 0 , last = 0 , type ; for ( parm = DECL_ARGUMENTS ( fndecl ) ; parm ; parm = TREE_CHAIN ( parm ) ) { type = tree_cons ( NULL_TREE , DECL_ARG_TYPE ( parm ) , NULL_TREE ) ; if ( last ) TREE_CHAIN ( last ) = type ; else actual = type ; last = type ; } type = tree_cons ( NULL_TREE , void_type_node , NULL_TREE ) ; if ( last ) TREE_CHAIN ( last ) = type ; else actual = type ; TREE_TYPE ( fndecl ) = build_variant_type_copy ( TREE_TYPE ( fndecl ) ) ; TYPE_ACTUAL_ARG_TYPES ( TREE_TYPE ( fndecl ) ) = actual ; } }
Subroutine of store_parm_decls which handles old-style function
definitions (separate parameter list and declarations).
Subroutine of store_parm_decls which handles old - style function definitions ( separate parameter list and declarations ) .
/* Match each formal parameter name with its declaration.  Save each
     decl in the appropriate TREE_PURPOSE slot of the parmids chain.  */ /* If we got something other than a PARM_DECL it is an error.  */ /* If the declaration is already marked, we have a duplicate
	     name.  Complain and ignore the duplicate.  */ /* If the declaration says "void", complain and turn it into
	     an int.  */ /* If no declaration found, default to int.  */ /* Now examine the parms chain for incomplete declarations
     and declarations with no corresponding names.  */ /* Pretend the parameter was not missing.
	     This gets us to a standard state and minimizes
	     further error messages.  */ /* Chain the declarations together in the order of the list of
     names.  Store that chain in the function decl, replacing the
     list of names.  Update the current scope to match.  */ /* If there was a previous prototype,
     set the DECL_ARG_TYPE of each argument according to
     the type previously specified, and report any mismatches.  */ /* Type for passing arg must be consistent with that
	     declared for the arg.  ISO C says we take the unqualified
	     type for parameters declared with qualified type.  */ /* Adjust argument to match prototype.  E.g. a previous
		     `int foo(float);' prototype causes
		     `int foo(x) float x; {...}' to be treated like
		     `int foo(float x) {...}'.  This is particularly
		     useful for argument types like uid_t.  */ /* ??? Is it possible to get here with a
			 built-in prototype or will it always have
			 been diagnosed as conflicting with an
			 old-style definition and discarded?  */ /* Otherwise, create a prototype that would match.  */ /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
	 of the type of this function, but we need to avoid having this
	 affect the types of other similarly-typed functions, so we must
	 first force the generation of an identical (but separate) type
	 node for the relevant function type.  The new node we create
	 will be a variant of the main variant of the original function
	 type.  */