end if;
end Node_Parent;
+ -------------------------------
+ -- Parent_Or_List_Containing --
+ -------------------------------
+
+ function Parent_Or_List_Containing (X : Union_Id) return Union_Id is
+ begin
+ if X in Node_Range then
+ return Link (Node_Id (X));
+ elsif X in List_Range then
+ return Union_Id (List_Parent (List_Id (X)));
+ else
+ raise Program_Error;
+ end if;
+ end Parent_Or_List_Containing;
+
-------------
-- Present --
-------------
-- Parent has the same name as the one in Nlists; Node_Parent can be used
-- more easily in the debugger.
+ function Parent_Or_List_Containing (X : Union_Id) return Union_Id;
+ -- X must be in Node_Range or in List_Range. If X is in Node_Range and is
+ -- contained in a list, returns that list, otherwise return the parent of
+ -- the list or node represented by X.
+
function Paren_Count (N : Node_Id) return Nat;
pragma Inline (Paren_Count);
-- Number of parentheses that surround an expression
If ``Path`` is a relative path, it is interpreted relatively to the directory of the file that contains the aspect specification.
.. attention:: The maximum size of loaded files is limited to 2\ :sup:`31` bytes.
+
+
+Finally construct
+-----------------
+
+The ``finally`` keyword makes it possible to have a sequence of statements be executed when
+another sequence of statements is completed, whether normally or abnormally.
+
+This feature is similar to the one with the same name in other languages such as Java.
+
+Syntax
+^^^^^^
+
+.. code-block:: text
+
+ handled_sequence_of_statements ::=
+ sequence_of_statements
+ [exception
+ exception_handler
+ {exception_handler}]
+ [finally
+ sequence_of_statements]
+
+Legality Rules
+^^^^^^^^^^^^^^
+
+Return statements in the ``sequence_of_statements`` attached to the finally that would cause control
+to be transferred outside the finally part are forbidden.
+
+Goto & exit where the target is outside of the finally's ``sequence_of_statements`` are forbidden
+
+Dynamic Semantics
+^^^^^^^^^^^^^^^^^
+
+Statements in the optional ``sequence_of_statements`` contained in the ``finally`` branch will be
+executed unconditionally, after the main ``sequence_of_statements`` is executed, and after any
+potential ``exception_handler`` is executed.
+
+If an exception is raised in the finally part, it cannot be caught by the ``exception_handler``.
+
+Abort/ATC (asynchronous transfer of control) cannot interrupt a finally block, nor prevent its
+execution, that is the finally block must be executed in full even if the containing task is
+aborted, or if the control is transferred out of the block.
pragma Assert (not Is_Thunk (Current_Scope));
Expand_Cleanup_Actions (Parent (N));
end if;
+
+ if Present (Finally_Statements (N)) then
+ Prepend_To
+ (Finally_Statements (N),
+ Build_Runtime_Call (Sloc (N), RE_Abort_Defer));
+
+ Append_To
+ (Finally_Statements (N),
+ Build_Runtime_Call (Sloc (N), RE_Abort_Undefer));
+
+ Analyze_List (Finally_Statements (N));
+ end if;
end Expand_N_Handled_Sequence_Of_Statements;
-------------------------------------
set_expr_location_from_node (gnu_result, gnat_node, true);
}
+ if (Present (Finally_Statements (gnat_node)))
+ {
+ tree finally_stmts;
+ location_t locus;
+
+ start_stmt_group ();
+ for (gnat_temp = First_Non_Pragma (Finally_Statements (gnat_node));
+ Present (gnat_temp);
+ gnat_temp = Next_Non_Pragma (gnat_temp))
+ add_stmt (gnat_to_gnu (gnat_temp));
+ finally_stmts = end_stmt_group ();
+
+ gnu_result
+ = build2 (TRY_FINALLY_EXPR, void_type_node, gnu_result, finally_stmts);
+
+ /* Do as above for the TRY_CATCH_EXPR case. */
+ if (Present (End_Label (gnat_node))
+ && Sloc_to_locus (Sloc (End_Label (gnat_node)), &locus))
+ SET_EXPR_LOCATION (gnu_result, locus);
+ else
+ set_expr_location_from_node (gnu_result, gnat_node, true);
+ }
+
/* Process the At_End_Proc, if any. */
if (at_end)
{
Expression_Copy,
Expressions,
File_Index,
+ Finally_Statements,
First_Bit,
First_Inlined_Subprogram,
First_Name,
(Sy (Statements, List_Id, Default_Empty_List),
Sy (End_Label, Node_Id, Default_Empty),
Sy (Exception_Handlers, List_Id, Default_No_List),
+ Sy (Finally_Statements, List_Id, Default_No_List),
Sy (At_End_Proc, Node_Id, Default_Empty)));
Cc (N_Index_Or_Discriminant_Constraint, Node_Kind,
* No_Raise aspect::
* Inference of Dependent Types in Generic Instantiations::
* External_Initialization Aspect::
+* Finally construct::
Storage Model
* Composite types::
* Interoperability with controlled types::
+Finally construct
+
+* Syntax: Syntax<2>.
+* Legality Rules: Legality Rules<2>.
+* Dynamic Semantics: Dynamic Semantics<2>.
+
Security Hardening Features
* Register Scrubbing::
* No_Raise aspect::
* Inference of Dependent Types in Generic Instantiations::
* External_Initialization Aspect::
+* Finally construct::
@end menu
Array_Type => Int_Array);
@end example
-@node External_Initialization Aspect,,Inference of Dependent Types in Generic Instantiations,Experimental Language Extensions
+@node External_Initialization Aspect,Finally construct,Inference of Dependent Types in Generic Instantiations,Experimental Language Extensions
@anchor{gnat_rm/gnat_language_extensions external-initialization-aspect}@anchor{469}
@subsection External_Initialization Aspect
@end quotation
@end cartouche
+@node Finally construct,,External_Initialization Aspect,Experimental Language Extensions
+@anchor{gnat_rm/gnat_language_extensions finally-construct}@anchor{46a}
+@subsection Finally construct
+
+
+The @code{finally} keyword makes it possible to have a sequence of statements be executed when
+another sequence of statements is completed, whether normally or abnormally.
+
+This feature is similar to the one with the same name in other languages such as Java.
+
+@menu
+* Syntax: Syntax<2>.
+* Legality Rules: Legality Rules<2>.
+* Dynamic Semantics: Dynamic Semantics<2>.
+
+@end menu
+
+@node Syntax<2>,Legality Rules<2>,,Finally construct
+@anchor{gnat_rm/gnat_language_extensions id4}@anchor{46b}
+@subsubsection Syntax
+
+
+@example
+handled_sequence_of_statements ::=
+ sequence_of_statements
+ [exception
+ exception_handler
+ @{exception_handler@}]
+ [finally
+ sequence_of_statements]
+@end example
+
+@node Legality Rules<2>,Dynamic Semantics<2>,Syntax<2>,Finally construct
+@anchor{gnat_rm/gnat_language_extensions id5}@anchor{46c}
+@subsubsection Legality Rules
+
+
+Return statements in the @code{sequence_of_statements} attached to the finally that would cause control
+to be transferred outside the finally part are forbidden.
+
+Goto & exit where the target is outside of the finally’s @code{sequence_of_statements} are forbidden
+
+@node Dynamic Semantics<2>,,Legality Rules<2>,Finally construct
+@anchor{gnat_rm/gnat_language_extensions id6}@anchor{46d}
+@subsubsection Dynamic Semantics
+
+
+Statements in the optional @code{sequence_of_statements} contained in the @code{finally} branch will be
+executed unconditionally, after the main @code{sequence_of_statements} is executed, and after any
+potential @code{exception_handler} is executed.
+
+If an exception is raised in the finally part, it cannot be caught by the @code{exception_handler}.
+
+Abort/ATC (asynchronous transfer of control) cannot interrupt a finally block, nor prevent its
+execution, that is the finally block must be executed in full even if the containing task is
+aborted, or if the control is transferred out of the block.
+
@node Security Hardening Features,Obsolescent Features,GNAT language extensions,Top
-@anchor{gnat_rm/security_hardening_features doc}@anchor{46a}@anchor{gnat_rm/security_hardening_features id1}@anchor{46b}@anchor{gnat_rm/security_hardening_features security-hardening-features}@anchor{15}
+@anchor{gnat_rm/security_hardening_features doc}@anchor{46e}@anchor{gnat_rm/security_hardening_features id1}@anchor{46f}@anchor{gnat_rm/security_hardening_features security-hardening-features}@anchor{15}
@chapter Security Hardening Features
@end menu
@node Register Scrubbing,Stack Scrubbing,,Security Hardening Features
-@anchor{gnat_rm/security_hardening_features register-scrubbing}@anchor{46c}
+@anchor{gnat_rm/security_hardening_features register-scrubbing}@anchor{470}
@section Register Scrubbing
@c Stack Scrubbing:
@node Stack Scrubbing,Hardened Conditionals,Register Scrubbing,Security Hardening Features
-@anchor{gnat_rm/security_hardening_features stack-scrubbing}@anchor{46d}
+@anchor{gnat_rm/security_hardening_features stack-scrubbing}@anchor{471}
@section Stack Scrubbing
@c Hardened Conditionals:
@node Hardened Conditionals,Hardened Booleans,Stack Scrubbing,Security Hardening Features
-@anchor{gnat_rm/security_hardening_features hardened-conditionals}@anchor{46e}
+@anchor{gnat_rm/security_hardening_features hardened-conditionals}@anchor{472}
@section Hardened Conditionals
@c Hardened Booleans:
@node Hardened Booleans,Control Flow Redundancy,Hardened Conditionals,Security Hardening Features
-@anchor{gnat_rm/security_hardening_features hardened-booleans}@anchor{46f}
+@anchor{gnat_rm/security_hardening_features hardened-booleans}@anchor{473}
@section Hardened Booleans
@c Control Flow Redundancy:
@node Control Flow Redundancy,,Hardened Booleans,Security Hardening Features
-@anchor{gnat_rm/security_hardening_features control-flow-redundancy}@anchor{470}
+@anchor{gnat_rm/security_hardening_features control-flow-redundancy}@anchor{474}
@section Control Flow Redundancy
can be used with other programming languages supported by GCC.
@node Obsolescent Features,Compatibility and Porting Guide,Security Hardening Features,Top
-@anchor{gnat_rm/obsolescent_features doc}@anchor{471}@anchor{gnat_rm/obsolescent_features id1}@anchor{472}@anchor{gnat_rm/obsolescent_features obsolescent-features}@anchor{16}
+@anchor{gnat_rm/obsolescent_features doc}@anchor{475}@anchor{gnat_rm/obsolescent_features id1}@anchor{476}@anchor{gnat_rm/obsolescent_features obsolescent-features}@anchor{16}
@chapter Obsolescent Features
@end menu
@node pragma No_Run_Time,pragma Ravenscar,,Obsolescent Features
-@anchor{gnat_rm/obsolescent_features id2}@anchor{473}@anchor{gnat_rm/obsolescent_features pragma-no-run-time}@anchor{474}
+@anchor{gnat_rm/obsolescent_features id2}@anchor{477}@anchor{gnat_rm/obsolescent_features pragma-no-run-time}@anchor{478}
@section pragma No_Run_Time
includes just those features that are to be made accessible.
@node pragma Ravenscar,pragma Restricted_Run_Time,pragma No_Run_Time,Obsolescent Features
-@anchor{gnat_rm/obsolescent_features id3}@anchor{475}@anchor{gnat_rm/obsolescent_features pragma-ravenscar}@anchor{476}
+@anchor{gnat_rm/obsolescent_features id3}@anchor{479}@anchor{gnat_rm/obsolescent_features pragma-ravenscar}@anchor{47a}
@section pragma Ravenscar
is part of the new Ada 2005 standard.
@node pragma Restricted_Run_Time,pragma Task_Info,pragma Ravenscar,Obsolescent Features
-@anchor{gnat_rm/obsolescent_features id4}@anchor{477}@anchor{gnat_rm/obsolescent_features pragma-restricted-run-time}@anchor{478}
+@anchor{gnat_rm/obsolescent_features id4}@anchor{47b}@anchor{gnat_rm/obsolescent_features pragma-restricted-run-time}@anchor{47c}
@section pragma Restricted_Run_Time
this kind of implementation dependent addition.
@node pragma Task_Info,package System Task_Info s-tasinf ads,pragma Restricted_Run_Time,Obsolescent Features
-@anchor{gnat_rm/obsolescent_features id5}@anchor{479}@anchor{gnat_rm/obsolescent_features pragma-task-info}@anchor{47a}
+@anchor{gnat_rm/obsolescent_features id5}@anchor{47d}@anchor{gnat_rm/obsolescent_features pragma-task-info}@anchor{47e}
@section pragma Task_Info
library.
@node package System Task_Info s-tasinf ads,,pragma Task_Info,Obsolescent Features
-@anchor{gnat_rm/obsolescent_features package-system-task-info}@anchor{47b}@anchor{gnat_rm/obsolescent_features package-system-task-info-s-tasinf-ads}@anchor{47c}
+@anchor{gnat_rm/obsolescent_features package-system-task-info}@anchor{47f}@anchor{gnat_rm/obsolescent_features package-system-task-info-s-tasinf-ads}@anchor{480}
@section package System.Task_Info (@code{s-tasinf.ads})
standard replacement for GNAT’s @code{Task_Info} functionality.
@node Compatibility and Porting Guide,GNU Free Documentation License,Obsolescent Features,Top
-@anchor{gnat_rm/compatibility_and_porting_guide doc}@anchor{47d}@anchor{gnat_rm/compatibility_and_porting_guide compatibility-and-porting-guide}@anchor{17}@anchor{gnat_rm/compatibility_and_porting_guide id1}@anchor{47e}
+@anchor{gnat_rm/compatibility_and_porting_guide doc}@anchor{481}@anchor{gnat_rm/compatibility_and_porting_guide compatibility-and-porting-guide}@anchor{17}@anchor{gnat_rm/compatibility_and_porting_guide id1}@anchor{482}
@chapter Compatibility and Porting Guide
@end menu
@node Writing Portable Fixed-Point Declarations,Compatibility with Ada 83,,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide id2}@anchor{47f}@anchor{gnat_rm/compatibility_and_porting_guide writing-portable-fixed-point-declarations}@anchor{480}
+@anchor{gnat_rm/compatibility_and_porting_guide id2}@anchor{483}@anchor{gnat_rm/compatibility_and_porting_guide writing-portable-fixed-point-declarations}@anchor{484}
@section Writing Portable Fixed-Point Declarations
types will be portable.
@node Compatibility with Ada 83,Compatibility between Ada 95 and Ada 2005,Writing Portable Fixed-Point Declarations,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-ada-83}@anchor{481}@anchor{gnat_rm/compatibility_and_porting_guide id3}@anchor{482}
+@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-ada-83}@anchor{485}@anchor{gnat_rm/compatibility_and_porting_guide id3}@anchor{486}
@section Compatibility with Ada 83
@end menu
@node Legal Ada 83 programs that are illegal in Ada 95,More deterministic semantics,,Compatibility with Ada 83
-@anchor{gnat_rm/compatibility_and_porting_guide id4}@anchor{483}@anchor{gnat_rm/compatibility_and_porting_guide legal-ada-83-programs-that-are-illegal-in-ada-95}@anchor{484}
+@anchor{gnat_rm/compatibility_and_porting_guide id4}@anchor{487}@anchor{gnat_rm/compatibility_and_porting_guide legal-ada-83-programs-that-are-illegal-in-ada-95}@anchor{488}
@subsection Legal Ada 83 programs that are illegal in Ada 95
@end itemize
@node More deterministic semantics,Changed semantics,Legal Ada 83 programs that are illegal in Ada 95,Compatibility with Ada 83
-@anchor{gnat_rm/compatibility_and_porting_guide id5}@anchor{485}@anchor{gnat_rm/compatibility_and_porting_guide more-deterministic-semantics}@anchor{486}
+@anchor{gnat_rm/compatibility_and_porting_guide id5}@anchor{489}@anchor{gnat_rm/compatibility_and_porting_guide more-deterministic-semantics}@anchor{48a}
@subsection More deterministic semantics
@end itemize
@node Changed semantics,Other language compatibility issues,More deterministic semantics,Compatibility with Ada 83
-@anchor{gnat_rm/compatibility_and_porting_guide changed-semantics}@anchor{487}@anchor{gnat_rm/compatibility_and_porting_guide id6}@anchor{488}
+@anchor{gnat_rm/compatibility_and_porting_guide changed-semantics}@anchor{48b}@anchor{gnat_rm/compatibility_and_porting_guide id6}@anchor{48c}
@subsection Changed semantics
@end itemize
@node Other language compatibility issues,,Changed semantics,Compatibility with Ada 83
-@anchor{gnat_rm/compatibility_and_porting_guide id7}@anchor{489}@anchor{gnat_rm/compatibility_and_porting_guide other-language-compatibility-issues}@anchor{48a}
+@anchor{gnat_rm/compatibility_and_porting_guide id7}@anchor{48d}@anchor{gnat_rm/compatibility_and_porting_guide other-language-compatibility-issues}@anchor{48e}
@subsection Other language compatibility issues
@end itemize
@node Compatibility between Ada 95 and Ada 2005,Implementation-dependent characteristics,Compatibility with Ada 83,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide compatibility-between-ada-95-and-ada-2005}@anchor{48b}@anchor{gnat_rm/compatibility_and_porting_guide id8}@anchor{48c}
+@anchor{gnat_rm/compatibility_and_porting_guide compatibility-between-ada-95-and-ada-2005}@anchor{48f}@anchor{gnat_rm/compatibility_and_porting_guide id8}@anchor{490}
@section Compatibility between Ada 95 and Ada 2005
@end itemize
@node Implementation-dependent characteristics,Compatibility with Other Ada Systems,Compatibility between Ada 95 and Ada 2005,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide id9}@anchor{48d}@anchor{gnat_rm/compatibility_and_porting_guide implementation-dependent-characteristics}@anchor{48e}
+@anchor{gnat_rm/compatibility_and_porting_guide id9}@anchor{491}@anchor{gnat_rm/compatibility_and_porting_guide implementation-dependent-characteristics}@anchor{492}
@section Implementation-dependent characteristics
@end menu
@node Implementation-defined pragmas,Implementation-defined attributes,,Implementation-dependent characteristics
-@anchor{gnat_rm/compatibility_and_porting_guide id10}@anchor{48f}@anchor{gnat_rm/compatibility_and_porting_guide implementation-defined-pragmas}@anchor{490}
+@anchor{gnat_rm/compatibility_and_porting_guide id10}@anchor{493}@anchor{gnat_rm/compatibility_and_porting_guide implementation-defined-pragmas}@anchor{494}
@subsection Implementation-defined pragmas
relevant in a GNAT context and hence are not otherwise implemented.
@node Implementation-defined attributes,Libraries,Implementation-defined pragmas,Implementation-dependent characteristics
-@anchor{gnat_rm/compatibility_and_porting_guide id11}@anchor{491}@anchor{gnat_rm/compatibility_and_porting_guide implementation-defined-attributes}@anchor{492}
+@anchor{gnat_rm/compatibility_and_porting_guide id11}@anchor{495}@anchor{gnat_rm/compatibility_and_porting_guide implementation-defined-attributes}@anchor{496}
@subsection Implementation-defined attributes
@code{Type_Class}.
@node Libraries,Elaboration order,Implementation-defined attributes,Implementation-dependent characteristics
-@anchor{gnat_rm/compatibility_and_porting_guide id12}@anchor{493}@anchor{gnat_rm/compatibility_and_porting_guide libraries}@anchor{494}
+@anchor{gnat_rm/compatibility_and_porting_guide id12}@anchor{497}@anchor{gnat_rm/compatibility_and_porting_guide libraries}@anchor{498}
@subsection Libraries
@end itemize
@node Elaboration order,Target-specific aspects,Libraries,Implementation-dependent characteristics
-@anchor{gnat_rm/compatibility_and_porting_guide elaboration-order}@anchor{495}@anchor{gnat_rm/compatibility_and_porting_guide id13}@anchor{496}
+@anchor{gnat_rm/compatibility_and_porting_guide elaboration-order}@anchor{499}@anchor{gnat_rm/compatibility_and_porting_guide id13}@anchor{49a}
@subsection Elaboration order
@end itemize
@node Target-specific aspects,,Elaboration order,Implementation-dependent characteristics
-@anchor{gnat_rm/compatibility_and_porting_guide id14}@anchor{497}@anchor{gnat_rm/compatibility_and_porting_guide target-specific-aspects}@anchor{498}
+@anchor{gnat_rm/compatibility_and_porting_guide id14}@anchor{49b}@anchor{gnat_rm/compatibility_and_porting_guide target-specific-aspects}@anchor{49c}
@subsection Target-specific aspects
Ada 2005 and Ada 2012) are sometimes
incompatible with typical Ada 83 compiler practices regarding implicit
packing, the meaning of the Size attribute, and the size of access values.
-GNAT’s approach to these issues is described in @ref{499,,Representation Clauses}.
+GNAT’s approach to these issues is described in @ref{49d,,Representation Clauses}.
@node Compatibility with Other Ada Systems,Representation Clauses,Implementation-dependent characteristics,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-other-ada-systems}@anchor{49a}@anchor{gnat_rm/compatibility_and_porting_guide id15}@anchor{49b}
+@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-other-ada-systems}@anchor{49e}@anchor{gnat_rm/compatibility_and_porting_guide id15}@anchor{49f}
@section Compatibility with Other Ada Systems
@end itemize
@node Representation Clauses,Compatibility with HP Ada 83,Compatibility with Other Ada Systems,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide id16}@anchor{49c}@anchor{gnat_rm/compatibility_and_porting_guide representation-clauses}@anchor{499}
+@anchor{gnat_rm/compatibility_and_porting_guide id16}@anchor{4a0}@anchor{gnat_rm/compatibility_and_porting_guide representation-clauses}@anchor{49d}
@section Representation Clauses
@end itemize
@node Compatibility with HP Ada 83,,Representation Clauses,Compatibility and Porting Guide
-@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-hp-ada-83}@anchor{49d}@anchor{gnat_rm/compatibility_and_porting_guide id17}@anchor{49e}
+@anchor{gnat_rm/compatibility_and_porting_guide compatibility-with-hp-ada-83}@anchor{4a1}@anchor{gnat_rm/compatibility_and_porting_guide id17}@anchor{4a2}
@section Compatibility with HP Ada 83
@end itemize
@node GNU Free Documentation License,Index,Compatibility and Porting Guide,Top
-@anchor{share/gnu_free_documentation_license doc}@anchor{49f}@anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{4a0}
+@anchor{share/gnu_free_documentation_license doc}@anchor{4a3}@anchor{share/gnu_free_documentation_license gnu-fdl}@anchor{1}@anchor{share/gnu_free_documentation_license gnu-free-documentation-license}@anchor{4a4}
@chapter GNU Free Documentation License
@printindex ge
-@anchor{d2}@w{ }
@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{ }
+@anchor{d2}@w{ }
@c %**end of body
@bye
Handled_Stmt_Seq_Node :=
New_Node (N_Handled_Sequence_Of_Statements, Token_Ptr);
Set_Statements
- (Handled_Stmt_Seq_Node, P_Sequence_Of_Statements (SS_Extm_Sreq));
+ (Handled_Stmt_Seq_Node, P_Sequence_Of_Statements (SS_Extm_Fitm_Sreq));
if Token = Tok_Exception then
Scan; -- past EXCEPTION
(Handled_Stmt_Seq_Node, Parse_Exception_Handlers);
end if;
+ if Token = Tok_Finally then
+ Scan; -- past FINALLY
+ Set_Finally_Statements
+ (Handled_Stmt_Seq_Node, P_Sequence_Of_Statements (SS_Sreq));
+ end if;
+
return Handled_Stmt_Seq_Node;
end P_Handled_Sequence_Of_Statements;
end loop;
TF_Arrow;
- Set_Statements (Handler_Node, P_Sequence_Of_Statements (SS_Sreq_Whtm));
+ Set_Statements
+ (Handler_Node, P_Sequence_Of_Statements (SS_Sreq_Fitm_Whtm));
return Handler_Node;
end P_Exception_Handler;
exit;
+ -- Case of finally
+
+ when Tok_Finally =>
+ Test_Statement_Required;
+
+ -- See the analogous comment in the Tok_Exception branch.
+
+ if not SS_Flags.Fitm
+ and then Start_Column >= Scopes (Scope.Last).Ecol
+ then
+ Error_Msg_SC ("finally construct not permitted here");
+ Scan; -- past FINALLY
+ Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
+ end if;
+
+ -- We exit like in the exception branch, should we really???
+
+ exit;
+
-- Case of OR
when Tok_Or =>
end if;
end if;
+ if Ada_Version < Ada_With_All_Extensions then
+ if Token_Name = Name_Finally then
+ Error_Msg_N
+ ("& is a reserved word with all extensions enabled?",
+ Token_Node);
+ end if;
+ end if;
+
-- Note: we deliberately do not emit these warnings when operating in
-- Ada 83 mode because in that case we assume the user is building
-- legacy code anyway and is not interested in updating Ada versions.
Eftm : Boolean; -- ELSIF can terminate sequence
Eltm : Boolean; -- ELSE can terminate sequence
Extm : Boolean; -- EXCEPTION can terminate sequence
+ Fitm : Boolean; -- FINALLY can terminate sequence
Ortm : Boolean; -- OR can terminate sequence
Sreq : Boolean; -- at least one statement required
Tatm : Boolean; -- THEN ABORT can terminate sequence
end record;
pragma Pack (SS_Rec);
- SS_Eftm_Eltm_Sreq : constant SS_Rec := (T, T, F, F, T, F, F, F);
- SS_Eltm_Ortm_Tatm : constant SS_Rec := (F, T, F, T, F, T, F, F);
- SS_Extm_Sreq : constant SS_Rec := (F, F, T, F, T, F, F, F);
- SS_None : constant SS_Rec := (F, F, F, F, F, F, F, F);
- SS_Ortm_Sreq : constant SS_Rec := (F, F, F, T, T, F, F, F);
- SS_Sreq : constant SS_Rec := (F, F, F, F, T, F, F, F);
- SS_Sreq_Whtm : constant SS_Rec := (F, F, F, F, T, F, T, F);
- SS_Whtm : constant SS_Rec := (F, F, F, F, F, F, T, F);
- SS_Unco : constant SS_Rec := (F, F, F, F, F, F, F, T);
+ SS_Eftm_Eltm_Sreq : constant SS_Rec := (T, T, F, F, F, T, F, F, F);
+ SS_Eltm_Ortm_Tatm : constant SS_Rec := (F, T, F, F, T, F, T, F, F);
+ SS_Extm_Fitm_Sreq : constant SS_Rec := (F, F, T, T, F, T, F, F, F);
+ SS_None : constant SS_Rec := (F, F, F, F, F, F, F, F, F);
+ SS_Ortm_Sreq : constant SS_Rec := (F, F, F, F, T, T, F, F, F);
+ SS_Sreq : constant SS_Rec := (F, F, F, F, F, T, F, F, F);
+ SS_Sreq_Whtm : constant SS_Rec := (F, F, F, F, F, T, F, T, F);
+ SS_Sreq_Fitm_Whtm : constant SS_Rec := (F, F, F, T, F, T, F, T, F);
+ SS_Whtm : constant SS_Rec := (F, F, F, F, F, F, F, T, F);
+ SS_Unco : constant SS_Rec := (F, F, F, F, F, F, F, F, T);
Goto_List : Elist_Id;
-- List of goto nodes appearing in the current compilation. Used to
-- Ada 2012 reserved words
Set_Reserved (Name_Some, Tok_Some);
+
+ -- GNAT extensions reserved words
+ Set_Reserved (Name_Finally, Tok_Finally);
end Initialize_Ada_Keywords;
------------------
Tok_End, -- END Eterm, Sterm, After_SM
Tok_Exception, -- EXCEPTION Eterm, Sterm, After_SM
Tok_Exit, -- EXIT Eterm, Sterm, After_SM
+ Tok_Finally, -- FINALLY Eterm, Sterm, After_SM
Tok_Goto, -- GOTO Eterm, Sterm, After_SM
Tok_If, -- IF Eterm, Sterm, After_SM
Tok_Pragma, -- PRAGMA Eterm, Sterm, After_SM
elsif Present (At_End_Proc (N)) then
Analyze (At_End_Proc (N));
end if;
+
+ if Present (Finally_Statements (N)) then
+ Analyze_Statements (Finally_Statements (N));
+ end if;
end Analyze_Handled_Statements;
------------------------------
begin
-- Initialize unblocked exit count for statements of begin block
- -- plus one for each exception handler that is present.
+ -- plus one for each exception handler that is present, plus one for
+ -- the finally part if it present.
- Unblocked_Exit_Count := 1 + List_Length (EH);
+ Unblocked_Exit_Count :=
+ 1 + List_Length (EH)
+ + (if Present (Finally_Statements (HSS)) then 1 else 0);
-- If a label is present analyze it and mark it as referenced
end if;
end loop;
+ Finally_Legality_Check : declare
+ -- The following value can actually be a block statement due to
+ -- expansion, but we call it Target_Loop_Statement because it was
+ -- originally a loop statement.
+ Target_Loop_Statement : constant Node_Id :=
+ (if Present (U_Name) then Label_Construct ((Parent (U_Name)))
+ else Empty);
+
+ X : Node_Id := N;
+ begin
+ while Present (X) loop
+ if Nkind (X) = N_Loop_Statement
+ and then (No (Target_Loop_Statement)
+ or else X = Target_Loop_Statement)
+ then
+ exit;
+ elsif Nkind (Parent (X)) = N_Handled_Sequence_Of_Statements
+ and then Is_List_Member (X)
+ and then List_Containing (X) = Finally_Statements (Parent (X))
+ then
+ Error_Msg_N ("cannot exit out of finally part", N);
+ exit;
+ end if;
+ X := Parent (X);
+ end loop;
+ end Finally_Legality_Check;
+
-- Verify that if present the condition is a Boolean expression
if Present (Cond) then
return;
end if;
+ Finally_Legality_Check : declare
+ LCA : constant Union_Id :=
+ Lowest_Common_Ancestor (N, Label_Construct (Parent (Label_Ent)));
+
+ N1 : Union_Id := Union_Id (N);
+ N2 : Union_Id;
+ begin
+ while N1 /= LCA loop
+ N2 := Parent_Or_List_Containing (N1);
+
+ if N2 in Node_Range
+ and then Nkind (Node_Id (N2)) = N_Handled_Sequence_Of_Statements
+ and then Union_Id (Finally_Statements (Node_Id (N2))) = N1
+ then
+ Error_Msg_N ("cannot goto out of finally part", N);
+ exit;
+ end if;
+
+ N1 := N2;
+ end loop;
+ end Finally_Legality_Check;
+
-- Here if goto passes initial validity checks
Label_Scope := Enclosing_Scope (Label_Ent);
End_Scope;
end if;
+ Finally_Legality_Check : declare
+ X : Node_Id := N;
+ begin
+ while Present (X) loop
+ if Nkind (X) in N_Proper_Body then
+ exit;
+ elsif Nkind (Parent (X)) = N_Handled_Sequence_Of_Statements
+ and then Is_List_Member (X)
+ and then List_Containing (X) = Finally_Statements (Parent (X))
+ then
+ Error_Msg_N ("cannot return out of finally part", N);
+ exit;
+ end if;
+ X := Parent (X);
+ end loop;
+ end Finally_Legality_Check;
+
Kill_Current_Values (Last_Assignment_Only => True);
Check_Unreachable_Code (N);
with Atree; use Atree;
with Debug; use Debug;
+with GNAT.Lists;
with Output; use Output;
with Seinfo;
with Sinput; use Sinput;
end if;
end Get_Pragma_Arg;
+ procedure Destroy_Element (Elem : in out Union_Id);
+ -- Does not do anything but is used to instantiate
+ -- GNAT.Lists.Doubly_Linked_Lists.
+
+ ---------------------
+ -- Destroy_Element --
+ ---------------------
+
+ procedure Destroy_Element (Elem : in out Union_Id) is
+ begin
+ null;
+ end Destroy_Element;
+
+ package Lists is
+ new GNAT.Lists.Doubly_Linked_Lists
+ (Element_Type => Union_Id, "=" => "=",
+ Destroy_Element => Destroy_Element, Check_Tampering => False);
+
+ ----------------------------
+ -- Lowest_Common_Ancestor --
+ ----------------------------
+
+ function Lowest_Common_Ancestor (N1, N2 : Node_Id) return Union_Id is
+ function Path_From_Root (N : Node_Id) return Lists.Doubly_Linked_List;
+
+ --------------------
+ -- Path_From_Root --
+ --------------------
+
+ function Path_From_Root (N : Node_Id) return Lists.Doubly_Linked_List is
+ L : constant Lists.Doubly_Linked_List := Lists.Create;
+
+ X : Union_Id := Union_Id (N);
+ begin
+ while X /= Union_Id (Empty) loop
+ Lists.Prepend (L, X);
+ X := Parent_Or_List_Containing (X);
+ end loop;
+
+ return L;
+ end Path_From_Root;
+
+ L1 : Lists.Doubly_Linked_List := Path_From_Root (N1);
+ L2 : Lists.Doubly_Linked_List := Path_From_Root (N2);
+
+ X1, X2 : Union_Id;
+
+ Common_Ancestor : Union_Id := Union_Id (Empty);
+ begin
+ while not Lists.Is_Empty (L1) and then not Lists.Is_Empty (L2) loop
+ X1 := Lists.First (L1);
+ Lists.Delete_First (L1);
+
+ X2 := Lists.First (L2);
+ Lists.Delete_First (L2);
+
+ exit when X1 /= X2;
+
+ Common_Ancestor := X1;
+ end loop;
+
+ Lists.Destroy (L1);
+ Lists.Destroy (L2);
+
+ return Common_Ancestor;
+ end Lowest_Common_Ancestor;
+
----------------------
-- Set_End_Location --
----------------------
-- for the argument. This is Arg itself, or, in the case where Arg is a
-- pragma argument association node, the expression from this node.
+ function Lowest_Common_Ancestor (N1, N2 : Node_Id) return Union_Id;
+ -- Returns the list or node that is the lowest common ancestor of N1 and
+ -- N2 in the syntax tree.
+
-----------------------
-- Utility Functions --
-----------------------
-- Present in N_External_Initializer nodes. Contains a Source_File_Index
-- that references the file the external initializer points to.
+ -- Finally_Statements
+ -- Present in N_Handled_Statement_Sequences nodes. Points to a list
+ -- containing statements.
+
-- First_Inlined_Subprogram
-- Present in the N_Compilation_Unit node for the main program. Points
-- to a chain of entities for subprograms that are to be inlined. The
-- for compatibility with Ada 95 compilers implementing
-- only this Ada 2005 extension.
and then (Ada_Version >= Ada_2012
- or else N not in Ada_2012_Reserved_Words);
+ or else N not in Ada_2012_Reserved_Words)
+ and then (Ada_Version >= Ada_With_All_Extensions
+ or else N not in GNAT_Extensions_Reserved_Words);
end Is_Keyword_Name;
--------------------------------
subtype Ada_2012_Reserved_Words is Name_Id
range First_2012_Reserved_Word .. Last_2012_Reserved_Word;
+ -- GNAT extensions reserved words
+
+ First_GNAT_Extensions_Reserved_Word : constant Name_Id := N + $;
+ Name_Finally : constant Name_Id := N + $;
+ Last_GNAT_Extensions_Reserved_Word : constant Name_Id := N + $;
+
+ subtype GNAT_Extensions_Reserved_Words is Name_Id
+ range First_GNAT_Extensions_Reserved_Word ..
+ Last_GNAT_Extensions_Reserved_Word;
+
-- Mark last defined name for consistency check in Snames body
Last_Predefined_Name : constant Name_Id := N + $;
X.Warning_Doc_Switch |
X.Warn_On_Ada_2022_Compatibility |
X.Warn_On_Elab_Access |
+ X.Warn_On_GNAT_Extension_Compatibility |
X.No_Warn_On_Non_Local_Exception => False,
others => True);
-- Warning_Doc_Switch is not really a warning to be enabled, but controls
Warn_On_Dereference,
Warn_On_Elab_Access,
Warn_On_Export_Import,
+ Warn_On_GNAT_Extension_Compatibility,
Warn_On_Hiding,
Warn_On_Ignored_Equality,
Warn_On_Ineffective_Predicate_Test,
Warn_On_Assumed_Low_Bound |
Warn_On_Biased_Representation |
Warn_On_Export_Import |
+ Warn_On_GNAT_Extension_Compatibility |
Warn_On_No_Value_Assigned |
Warn_On_Questionable_Missing_Parens |
Warn_On_Reverse_Bit_Order |
-- Set to True to generate warnings for suspicious use of export or
-- import pragmas. Modified by use of -gnatwx/X.
+ Warn_On_GNAT_Extension_Compatibility : Boolean renames F (X.Warn_On_GNAT_Extension_Compatibility);
+ -- Set to True to generate all warnings on GNAT extension compatibility
+ -- issues. There is no switch controlling this option.
+
Warn_On_Hiding : Boolean renames F (X.Warn_On_Hiding);
-- Set to True to generate warnings if a declared entity hides another
-- entity. The default is that this warning is suppressed. Modified by
-- which the numbers are all written as $, and generates a new version of the
-- spec file snames.ads (written to snames.ns). It also reads snames.adb-tmpl
-- and generates an updated body (written to snames.nb), and snames.h-tmpl and
--- generates an updated C header file (written to snames.nh).
+-- generates an updated C header file (written to snames.h).
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;