[Ada] Use pygments for Ada code examples of elaboration control
Only enhancement of formatting. gcc/ada/ * doc/gnat_ugn/elaboration_order_handling_in_gnat.rst: Change blocks from plain code to Ada.
This commit is contained in:
parent
42c0119157
commit
a473646ec8
@ -93,7 +93,7 @@ Elaboration code may appear in two distinct contexts:
|
|||||||
[body] compilation unit, ignoring any other package [body] declarations in
|
[body] compilation unit, ignoring any other package [body] declarations in
|
||||||
between.
|
between.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Server;
|
with Server;
|
||||||
package Client is
|
package Client is
|
||||||
@ -116,7 +116,7 @@ Elaboration code may appear in two distinct contexts:
|
|||||||
bounded by the region starting from the ``begin`` keyword of the package body
|
bounded by the region starting from the ``begin`` keyword of the package body
|
||||||
and ending at the ``end`` keyword of the package body.
|
and ending at the ``end`` keyword of the package body.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Client is
|
package body Client is
|
||||||
procedure Proc is
|
procedure Proc is
|
||||||
@ -142,7 +142,7 @@ executed is referred to as **elaboration order**.
|
|||||||
|
|
||||||
Within a single unit, elaboration code is executed in sequential order.
|
Within a single unit, elaboration code is executed in sequential order.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Client is
|
package body Client is
|
||||||
Result : ... := Server.Func;
|
Result : ... := Server.Func;
|
||||||
@ -190,13 +190,13 @@ factors:
|
|||||||
|
|
||||||
A program may have several elaboration orders depending on its structure.
|
A program may have several elaboration orders depending on its structure.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Server is
|
package Server is
|
||||||
function Func (Index : Integer) return Integer;
|
function Func (Index : Integer) return Integer;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Server is
|
package body Server is
|
||||||
Results : array (1 .. 5) of Integer := (1, 2, 3, 4, 5);
|
Results : array (1 .. 5) of Integer := (1, 2, 3, 4, 5);
|
||||||
@ -207,14 +207,14 @@ A program may have several elaboration orders depending on its structure.
|
|||||||
end Func;
|
end Func;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Server;
|
with Server;
|
||||||
package Client is
|
package Client is
|
||||||
Val : constant Integer := Server.Func (3);
|
Val : constant Integer := Server.Func (3);
|
||||||
end Client;
|
end Client;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Client;
|
with Client;
|
||||||
procedure Main is begin null; end Main;
|
procedure Main is begin null; end Main;
|
||||||
@ -320,7 +320,7 @@ the desired elaboration order and avoiding ABE problems altogether.
|
|||||||
A library package which does not require a completing body does not suffer
|
A library package which does not require a completing body does not suffer
|
||||||
from ABE problems.
|
from ABE problems.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Pack is
|
package Pack is
|
||||||
generic
|
generic
|
||||||
@ -358,7 +358,7 @@ the desired elaboration order and avoiding ABE problems altogether.
|
|||||||
scenario can invoke a server target before the target body has been
|
scenario can invoke a server target before the target body has been
|
||||||
elaborated because the spec and body are effectively "glued" together.
|
elaborated because the spec and body are effectively "glued" together.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Server is
|
package Server is
|
||||||
pragma Elaborate_Body;
|
pragma Elaborate_Body;
|
||||||
@ -366,7 +366,7 @@ the desired elaboration order and avoiding ABE problems altogether.
|
|||||||
function Func return Integer;
|
function Func return Integer;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Server is
|
package body Server is
|
||||||
function Func return Integer is
|
function Func return Integer is
|
||||||
@ -375,7 +375,7 @@ the desired elaboration order and avoiding ABE problems altogether.
|
|||||||
end Func;
|
end Func;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Server;
|
with Server;
|
||||||
package Client is
|
package Client is
|
||||||
@ -425,13 +425,13 @@ depend on.
|
|||||||
be elaborated prior to the unit with the pragma. Note that other unrelated
|
be elaborated prior to the unit with the pragma. Note that other unrelated
|
||||||
units may be elaborated in between the spec and the body.
|
units may be elaborated in between the spec and the body.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Server is
|
package Server is
|
||||||
function Func return Integer;
|
function Func return Integer;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Server is
|
package body Server is
|
||||||
function Func return Integer is
|
function Func return Integer is
|
||||||
@ -440,7 +440,7 @@ depend on.
|
|||||||
end Func;
|
end Func;
|
||||||
end Server;
|
end Server;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Server;
|
with Server;
|
||||||
pragma Elaborate (Server);
|
pragma Elaborate (Server);
|
||||||
@ -479,13 +479,13 @@ depend on.
|
|||||||
|withed| by the spec and body of the argument, recursively. Note that other
|
|withed| by the spec and body of the argument, recursively. Note that other
|
||||||
unrelated units may be elaborated in between the spec and the body.
|
unrelated units may be elaborated in between the spec and the body.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Math is
|
package Math is
|
||||||
function Factorial (Val : Natural) return Natural;
|
function Factorial (Val : Natural) return Natural;
|
||||||
end Math;
|
end Math;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Math is
|
package body Math is
|
||||||
function Factorial (Val : Natural) return Natural is
|
function Factorial (Val : Natural) return Natural is
|
||||||
@ -494,7 +494,7 @@ depend on.
|
|||||||
end Factorial;
|
end Factorial;
|
||||||
end Math;
|
end Math;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package Computer is
|
package Computer is
|
||||||
type Operation_Kind is (None, Op_Factorial);
|
type Operation_Kind is (None, Op_Factorial);
|
||||||
@ -504,7 +504,7 @@ depend on.
|
|||||||
Op : Operation_Kind) return Natural;
|
Op : Operation_Kind) return Natural;
|
||||||
end Computer;
|
end Computer;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Math;
|
with Math;
|
||||||
package body Computer is
|
package body Computer is
|
||||||
@ -520,7 +520,7 @@ depend on.
|
|||||||
end Compute;
|
end Compute;
|
||||||
end Computer;
|
end Computer;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with Computer;
|
with Computer;
|
||||||
pragma Elaborate_All (Computer);
|
pragma Elaborate_All (Computer);
|
||||||
@ -738,7 +738,7 @@ execution. The warnings can be suppressed selectively with ``pragma Warnings
|
|||||||
A *guaranteed ABE* arises when the body of a target is not elaborated early
|
A *guaranteed ABE* arises when the body of a target is not elaborated early
|
||||||
enough, and causes *all* scenarios that directly invoke the target to fail.
|
enough, and causes *all* scenarios that directly invoke the target to fail.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package body Guaranteed_ABE is
|
package body Guaranteed_ABE is
|
||||||
function ABE return Integer;
|
function ABE return Integer;
|
||||||
@ -765,7 +765,7 @@ the declaration of ``Val``. This invokes function ``ABE``, however the body of
|
|||||||
A *conditional ABE* arises when the body of a target is not elaborated early
|
A *conditional ABE* arises when the body of a target is not elaborated early
|
||||||
enough, and causes *some* scenarios that directly invoke the target to fail.
|
enough, and causes *some* scenarios that directly invoke the target to fail.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
1. package body Conditional_ABE is
|
1. package body Conditional_ABE is
|
||||||
2. procedure Force_Body is null;
|
2. procedure Force_Body is null;
|
||||||
@ -850,19 +850,19 @@ clauses, elaboration-control pragmas, or invocations in elaboration code.
|
|||||||
|
|
||||||
The following example exhibits an elaboration circularity.
|
The following example exhibits an elaboration circularity.
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with B; pragma Elaborate (B);
|
with B; pragma Elaborate (B);
|
||||||
package A is
|
package A is
|
||||||
end A;
|
end A;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package B is
|
package B is
|
||||||
procedure Force_Body;
|
procedure Force_Body;
|
||||||
end B;
|
end B;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with C;
|
with C;
|
||||||
package body B is
|
package body B is
|
||||||
@ -871,13 +871,13 @@ The following example exhibits an elaboration circularity.
|
|||||||
Elab : constant Integer := C.Func;
|
Elab : constant Integer := C.Func;
|
||||||
end B;
|
end B;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
package C is
|
package C is
|
||||||
function Func return Integer;
|
function Func return Integer;
|
||||||
end C;
|
end C;
|
||||||
|
|
||||||
::
|
.. code-block:: ada
|
||||||
|
|
||||||
with A;
|
with A;
|
||||||
package body C is
|
package body C is
|
||||||
|
Loading…
Reference in New Issue
Block a user