These two interlinked phases have the following purpose:
- <#2749#>Semantic Analysis<#2749#>
- performs name and type resolution, decorates the
AST with various semantic attributes, and as by-product performs all
static legality checks on the program.
- <#2750#>The expander<#2750#>
- modifies de AST in order to simplify its translation
into the GCC tree. Most of the expander activity results in
the construction of additional AST fragments. Given that code generation
requires that such fragments carry all semantic attributes, every expansion
activity must be followed by additional semantic processing on the generated
tree. This recursive structure is carried further: some predefined operations
such as exponentiation are defined by means of a generic procedure. The
expansion of the operation results in the generic instantiation
(and corresponding analysis) of this generic procedure.
There is a further unusual recursive aspect to the structure of GNAT. The
program library (described in greater detail below) does not hold any
intermediate representation of compiled units. As a result, package
declarations are analyzed whenever they appear in a context clause.
Furthermore, if a generic unit, or an inlined unit <#461#>G<#461#>, is defined
in a package <#462#>P<#462#>, then the instantiation or inlining of <#463#>G<#463#> in
the current compilation requires that the body of <#464#>P<#464#> be analyzed as
well. Thus the library manager, the parser, and the semantic analyzer can
be activated from within semantic analysis (note the backward arrows in fig.2).