You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
8.0 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2018 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below). A copy of the license is included in the section entitled
"GNU Free Documentation License".
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development. -->
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Function Basics (GNU Compiler Collection (GCC) Internals)</title>
<meta name="description" content="Function Basics (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Function Basics (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Functions.html#Functions" rel="up" title="Functions">
<link href="Function-Properties.html#Function-Properties" rel="next" title="Function Properties">
<link href="Functions.html#Functions" rel="prev" title="Functions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="Function-Basics"></a>
<div class="header">
<p>
Next: <a href="Function-Properties.html#Function-Properties" accesskey="n" rel="next">Function Properties</a>, Up: <a href="Functions.html#Functions" accesskey="u" rel="up">Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Function-Basics-1"></a>
<h4 class="subsection">11.8.1 Function Basics</h4>
<a name="index-DECL_005fNAME-1"></a>
<a name="index-DECL_005fASSEMBLER_005fNAME"></a>
<a name="index-TREE_005fPUBLIC"></a>
<a name="index-DECL_005fARTIFICIAL-1"></a>
<a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fTARGET"></a>
<a name="index-DECL_005fFUNCTION_005fSPECIFIC_005fOPTIMIZATION"></a>
<p>A function has four core parts: the name, the parameters, the result,
and the body. The following macros and functions access these parts
of a <code>FUNCTION_DECL</code> as well as other basic features:
</p><dl compact="compact">
<dt><code>DECL_NAME</code>
<a name="index-DECL_005fNAME-2"></a>
</dt>
<dd><p>This macro returns the unqualified name of the function, as an
<code>IDENTIFIER_NODE</code>. For an instantiation of a function template,
the <code>DECL_NAME</code> is the unqualified name of the template, not
something like <code>f&lt;int&gt;</code>. The value of <code>DECL_NAME</code> is
undefined when used on a constructor, destructor, overloaded operator,
or type-conversion operator, or any function that is implicitly
generated by the compiler. See below for macros that can be used to
distinguish these cases.
</p>
</dd>
<dt><code>DECL_ASSEMBLER_NAME</code>
<a name="index-DECL_005fASSEMBLER_005fNAME-1"></a>
</dt>
<dd><p>This macro returns the mangled name of the function, also an
<code>IDENTIFIER_NODE</code>. This name does not contain leading underscores
on systems that prefix all identifiers with underscores. The mangled
name is computed in the same way on all platforms; if special processing
is required to deal with the object file format used on a particular
platform, it is the responsibility of the back end to perform those
modifications. (Of course, the back end should not modify
<code>DECL_ASSEMBLER_NAME</code> itself.)
</p>
<p>Using <code>DECL_ASSEMBLER_NAME</code> will cause additional memory to be
allocated (for the mangled name of the entity) so it should be used
only when emitting assembly code. It should not be used within the
optimizers to determine whether or not two declarations are the same,
even though some of the existing optimizers do use it in that way.
These uses will be removed over time.
</p>
</dd>
<dt><code>DECL_ARGUMENTS</code>
<a name="index-DECL_005fARGUMENTS"></a>
</dt>
<dd><p>This macro returns the <code>PARM_DECL</code> for the first argument to the
function. Subsequent <code>PARM_DECL</code> nodes can be obtained by
following the <code>TREE_CHAIN</code> links.
</p>
</dd>
<dt><code>DECL_RESULT</code>
<a name="index-DECL_005fRESULT"></a>
</dt>
<dd><p>This macro returns the <code>RESULT_DECL</code> for the function.
</p>
</dd>
<dt><code>DECL_SAVED_TREE</code>
<a name="index-DECL_005fSAVED_005fTREE"></a>
</dt>
<dd><p>This macro returns the complete body of the function.
</p>
</dd>
<dt><code>TREE_TYPE</code>
<a name="index-TREE_005fTYPE-5"></a>
</dt>
<dd><p>This macro returns the <code>FUNCTION_TYPE</code> or <code>METHOD_TYPE</code> for
the function.
</p>
</dd>
<dt><code>DECL_INITIAL</code>
<a name="index-DECL_005fINITIAL-1"></a>
</dt>
<dd><p>A function that has a definition in the current translation unit will
have a non-<code>NULL</code> <code>DECL_INITIAL</code>. However, back ends should not make
use of the particular value given by <code>DECL_INITIAL</code>.
</p>
<p>It should contain a tree of <code>BLOCK</code> nodes that mirrors the scopes
that variables are bound in the function. Each block contains a list
of decls declared in a basic block, a pointer to a chain of blocks at
the next lower scope level, then a pointer to the next block at the
same level and a backpointer to the parent <code>BLOCK</code> or
<code>FUNCTION_DECL</code>. So given a function as follows:
</p>
<div class="smallexample">
<pre class="smallexample">void foo()
{
int a;
{
int b;
}
int c;
}
</pre></div>
<p>you would get the following:
</p>
<div class="smallexample">
<pre class="smallexample">tree foo = FUNCTION_DECL;
tree decl_a = VAR_DECL;
tree decl_b = VAR_DECL;
tree decl_c = VAR_DECL;
tree block_a = BLOCK;
tree block_b = BLOCK;
tree block_c = BLOCK;
BLOCK_VARS(block_a) = decl_a;
BLOCK_SUBBLOCKS(block_a) = block_b;
BLOCK_CHAIN(block_a) = block_c;
BLOCK_SUPERCONTEXT(block_a) = foo;
BLOCK_VARS(block_b) = decl_b;
BLOCK_SUPERCONTEXT(block_b) = block_a;
BLOCK_VARS(block_c) = decl_c;
BLOCK_SUPERCONTEXT(block_c) = foo;
DECL_INITIAL(foo) = block_a;
</pre></div>
</dd>
</dl>
<hr>
<div class="header">
<p>
Next: <a href="Function-Properties.html#Function-Properties" accesskey="n" rel="next">Function Properties</a>, Up: <a href="Functions.html#Functions" accesskey="u" rel="up">Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>