if Present (Items) then
Prag := Contract_Test_Cases (Items);
while Present (Prag) loop
- if Pragma_Name (Prag) = Name_Contract_Cases then
+ if Pragma_Name (Prag) = Name_Contract_Cases
+ and then Is_Checked (Prag)
+ then
Expand_Pragma_Contract_Cases
(CCs => Prag,
Subp_Id => Subp_Id,
if Present (Items) then
Prag := Pre_Post_Conditions (Items);
while Present (Prag) loop
- if Pragma_Name (Prag) = Post_Nam then
+ if Pragma_Name (Prag) = Post_Nam
+ and then Is_Checked (Prag)
+ then
Append_Enabled_Item
(Item => Build_Pragma_Check_Equivalent (Prag),
List => Stmts);
-- Note that non-matching pragmas are skipped
if Nkind (Decl) = N_Pragma then
- if Pragma_Name (Decl) = Post_Nam then
+ if Pragma_Name (Decl) = Post_Nam
+ and then Is_Checked (Decl)
+ then
Append_Enabled_Item
(Item => Build_Pragma_Check_Equivalent (Decl),
List => Stmts);
procedure Process_Spec_Postconditions is
Subps : constant Subprogram_List :=
Inherited_Subprograms (Spec_Id);
+ Item : Node_Id;
Items : Node_Id;
Prag : Node_Id;
Subp_Id : Entity_Id;
if Present (Items) then
Prag := Pre_Post_Conditions (Items);
while Present (Prag) loop
- if Pragma_Name (Prag) = Name_Postcondition then
+ if Pragma_Name (Prag) = Name_Postcondition
+ and then Is_Checked (Prag)
+ then
Append_Enabled_Item
(Item => Build_Pragma_Check_Equivalent (Prag),
List => Stmts);
if Pragma_Name (Prag) = Name_Postcondition
and then Class_Present (Prag)
then
- Append_Enabled_Item
- (Item =>
- Build_Pragma_Check_Equivalent
- (Prag => Prag,
- Subp_Id => Spec_Id,
- Inher_Id => Subp_Id),
- List => Stmts);
+ Item :=
+ Build_Pragma_Check_Equivalent
+ (Prag => Prag,
+ Subp_Id => Spec_Id,
+ Inher_Id => Subp_Id);
+
+ -- The pragma Check equivalent of the class-wide
+ -- postcondition is still created even though the
+ -- pragma may be ignored because the equivalent
+ -- performs semantic checks.
+
+ if Is_Checked (Prag) then
+ Append_Enabled_Item (Item, Stmts);
+ end if;
end if;
Prag := Next_Pragma (Prag);
----------------------
procedure Prepend_To_Decls (Item : Node_Id) is
- Decls : List_Id := Declarations (Body_Decl);
+ Decls : List_Id;
begin
+ Decls := Declarations (Body_Decl);
+
-- Ensure that the body has a declarative list
if No (Decls) then
-------------------------------------
procedure Process_Inherited_Preconditions is
- Subps : constant Subprogram_List :=
- Inherited_Subprograms (Spec_Id);
- Check_Prag : Node_Id;
- Items : Node_Id;
- Prag : Node_Id;
- Subp_Id : Entity_Id;
+ Subps : constant Subprogram_List :=
+ Inherited_Subprograms (Spec_Id);
+
+ Item : Node_Id;
+ Items : Node_Id;
+ Prag : Node_Id;
+ Subp_Id : Entity_Id;
begin
-- Process the contracts of all inherited subprograms, looking for
if Pragma_Name (Prag) = Name_Precondition
and then Class_Present (Prag)
then
- Check_Prag :=
+ Item :=
Build_Pragma_Check_Equivalent
(Prag => Prag,
Subp_Id => Spec_Id,
Inher_Id => Subp_Id);
- -- The spec of an inherited subprogram already yielded
- -- a class-wide precondition. Merge the existing
- -- precondition with the current one using "or else".
+ -- The pragma Check equivalent of the class-wide
+ -- precondition is still created even though the
+ -- pragma may be ignored because the equivalent
+ -- performs semantic checks.
- if Present (Class_Pre) then
- Merge_Preconditions (Check_Prag, Class_Pre);
- else
- Class_Pre := Check_Prag;
+ if Is_Checked (Prag) then
+
+ -- The spec of an inherited subprogram already
+ -- yielded a class-wide precondition. Merge the
+ -- existing precondition with the current one
+ -- using "or else".
+
+ if Present (Class_Pre) then
+ Merge_Preconditions (Item, Class_Pre);
+ else
+ Class_Pre := Item;
+ end if;
end if;
end if;
-------------------------------
procedure Process_Preconditions_For (Subp_Id : Entity_Id) is
- Items : constant Node_Id := Contract (Subp_Id);
+ Items : constant Node_Id := Contract (Subp_Id);
+
Decl : Node_Id;
Prag : Node_Id;
Subp_Decl : Node_Id;
if Present (Items) then
Prag := Pre_Post_Conditions (Items);
while Present (Prag) loop
- if Pragma_Name (Prag) = Name_Precondition then
+ if Pragma_Name (Prag) = Name_Precondition
+ and then Is_Checked (Prag)
+ then
Prepend_To_Decls_Or_Save (Prag);
end if;
-- Note that non-matching pragmas are skipped
if Nkind (Decl) = N_Pragma then
- if Pragma_Name (Decl) = Name_Precondition then
+ if Pragma_Name (Decl) = Name_Precondition
+ and then Is_Checked (Decl)
+ then
Prepend_To_Decls_Or_Save (Decl);
end if;
elsif Is_Ignored_Ghost_Entity (Subp_Id) then
return;
- end if;
-- Do not re-expand the same contract. This scenario occurs when a
-- construct is rewritten into something else during its analysis
-- (expression functions for instance).
- if Has_Expanded_Contract (Subp_Id) then
+ elsif Has_Expanded_Contract (Subp_Id) then
return;
+ end if;
- -- Otherwise mark the subprogram
+ -- Prevent multiple expansion attempts of the same contract
- else
- Set_Has_Expanded_Contract (Subp_Id);
- end if;
+ Set_Has_Expanded_Contract (Subp_Id);
-- Ensure that the formal parameters are visible when expanding all
-- contract items.
with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch8; use Sem_Ch8;
+with Sem_Prag; use Sem_Prag;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinput; use Sinput;
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname);
begin
- -- Rewrite pragma ignored by Ignore_Pragma to null statement, so that
- -- the back end doesn't see it. The same goes for pragma
- -- Default_Scalar_Storage_Order if the -gnatI switch was given.
+ -- Suppress the expansion of an ignored assertion pragma. Such a pragma
+ -- should not be transformed into a null statment because:
+ --
+ -- * The pragma may be part of the rep item chain of a type, in which
+ -- case rewriting it will destroy the chain.
+ --
+ -- * The analysis of the pragma may involve two parts (see routines
+ -- Analyze_xxx_In_Decl_Part). The second part of the analysis will
+ -- not happen if the pragma is rewritten.
+
+ if Assertion_Expression_Pragma (Prag_Id) and then Is_Ignored (N) then
+ return;
+
+ -- Rewrite the pragma into a null statement when it is ignored using
+ -- pragma Ignore_Pragma, or denotes Default_Scalar_Storage_Order and
+ -- compilation switch -gnatI is in effect.
- if Should_Ignore_Pragma_Sem (N)
+ elsif Should_Ignore_Pragma_Sem (N)
or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
and then Ignore_Rep_Clauses)
then