FreeBSD/contrib/gcc/cp/mangle.c
/* <name> ::= <unscoped-name>
	  ::= <unscoped-template-name> <template-args>
	  ::= <nested-name>
	  ::= <local-name>

   If IGNORE_LOCAL_SCOPE is nonzero, this production of <name> is
   called from <local-name>, which mangles the enclosing scope
   elsewhere and then uses this function to mangle just the part
   underneath the function scope.  So don't use the <local-name>
   production, to avoid an infinite recursion.  */


If IGNORE_LOCAL_SCOPE is nonzero, this production of  is
called from , which mangles the enclosing scope
elsewhere and then uses this function to mangle just the part
underneath the function scope.  So don't use the 
production, to avoid an infinite recursion.
If IGNORE_LOCAL_SCOPE is nonzero this production of is called from which mangles the enclosing scope elsewhere and then uses this function to mangle just the part underneath the function scope . So don ' t use the production to avoid an infinite recursion .
static void
write_name (tree decl, const int ignore_local_scope)
{
  tree context;
  MANGLE_TRACE_TREE ("name", decl);
  if (TREE_CODE (decl) == TYPE_DECL)
    {
      decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
      context = TYPE_CONTEXT (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
    }
  else
    context = (DECL_CONTEXT (decl) == NULL) ? NULL : CP_DECL_CONTEXT (decl);
  if (context == NULL
      || context == global_namespace
      || DECL_NAMESPACE_STD_P (context)
      || (ignore_local_scope && TREE_CODE (context) == FUNCTION_DECL))
    {
      tree template_info;
      if (decl_is_template_id (decl, &template_info))
	{
	  write_unscoped_template_name (TI_TEMPLATE (template_info));
	  write_template_args (TI_ARGS (template_info));
	}
      else
	write_unscoped_name (decl);
    }
  else
    {
      if (!ignore_local_scope)
	{
	  tree local_entity = decl;
	  while (context != NULL && context != global_namespace)
	    {
	      if (context != NULL && TYPE_P (context))
		context = TYPE_NAME (context);
	      if (TREE_CODE (context) == FUNCTION_DECL)
		{
		  write_local_name (context, local_entity, decl);
		  return;
		}
	      local_entity = context;
	      context = CP_DECL_CONTEXT (context);
	    }
	}
      write_nested_name (decl);
    }
}
static void write_name ( tree decl , const int ignore_local_scope ) { tree context ; MANGLE_TRACE_TREE ( " " , decl ) ; if ( TREE_CODE ( decl ) == TYPE_DECL ) { decl = TYPE_NAME ( TYPE_MAIN_VARIANT ( TREE_TYPE ( decl ) ) ) ; context = TYPE_CONTEXT ( TYPE_MAIN_VARIANT ( TREE_TYPE ( decl ) ) ) ; } else context = ( DECL_CONTEXT ( decl ) == NULL ) ? NULL : CP_DECL_CONTEXT ( decl ) ; if ( context == NULL || context == global_namespace || DECL_NAMESPACE_STD_P ( context ) || ( ignore_local_scope && TREE_CODE ( context ) == FUNCTION_DECL ) ) { tree template_info ; if ( decl_is_template_id ( decl , & template_info ) ) { write_unscoped_template_name ( TI_TEMPLATE ( template_info ) ) ; write_template_args ( TI_ARGS ( template_info ) ) ; } else write_unscoped_name ( decl ) ; } else { if ( ! ignore_local_scope ) { tree local_entity = decl ; while ( context != NULL && context != global_namespace ) { if ( context != NULL && TYPE_P ( context ) ) context = TYPE_NAME ( context ) ; if ( TREE_CODE ( context ) == FUNCTION_DECL ) { write_local_name ( context , local_entity , decl ) ; return ; } local_entity = context ; context = CP_DECL_CONTEXT ( context ) ; } } write_nested_name ( decl ) ; } }
<name> ::= <unscoped-name>
::= <unscoped-template-name> <template-args>
::= <nested-name>
::= <local-name>
<name > :: = <unscoped - name > :: = <unscoped - template - name > <template - args > :: = <nested - name > :: = <local - name >
/* In case this is a typedef, fish out the corresponding
	 TYPE_DECL for the main variant.  */ /* A decl in :: or ::std scope is treated specially.  The former is
     mangled using <unscoped-name> or <unscoped-template-name>, the
     latter with a special substitution.  Also, a name that is
     directly in a local function scope is also mangled with
     <unscoped-name> rather than a full <nested-name>.  */ /* Is this a template instance?  */ /* Yes: use <unscoped-template-name>.  */ /* Everything else gets an <unqualified-name>.  */ /* Handle local names, unless we asked not to (that is, invoked
	 under <local-name>, to handle only the part of the name under
	 the local scope).  */ /* Scan up the list of scope context, looking for a
	     function.  If we find one, this entity is in local
	     function scope.  local_entity tracks context one scope
	     level down, so it will contain the element that's
	     directly in that function's scope, either decl or one of
	     its enclosing scopes.  */ /* Make sure we're always dealing with decls.  */ /* Is this a function?  */ /* Yes, we have local scope.  Use the <local-name>
		     production for the innermost function scope.  */ /* Up one scope level.  */ /* No local scope found?  Fall through to <nested-name>.  */ /* Other decls get a <nested-name> to encode their scope.  */