summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_prag.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-25 15:05:39 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-25 15:05:39 +0000
commit334d1dbea30a398c5095983f7b6dfdd851bfee12 (patch)
tree48f255ef070ad622be4207d83e6991472e576211 /gcc/ada/sem_prag.adb
parent2e44583dfbd498287b4f3d0b486a16eda9f8f9e7 (diff)
downloadgcc-334d1dbea30a398c5095983f7b6dfdd851bfee12.tar.gz
2014-02-25 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch6.adb (Add_Or_Save_Precondition): New routine. (Collect_Body_Postconditions_In_Decls): New routine. (Collect_Body_Postconditions_Of_Kind): Factor out code. Handle postcondition aspects or pragmas that appear on a subprogram body stub. (Collect_Spec_Preconditions): Factor out code. Handle precondition aspects or pragmas that appear on a subprogram body stub. * sem_ch6.adb (Analyze_Subprogram_Body_Helper): The analysis of aspects that apply to a subprogram body stub is no longer delayed, the aspects are analyzed on the spot. (SPARK_Aspect_Error): Aspects that apply to a subprogram declaration cannot appear in a subunit. * sem_ch10.adb Remove with and use clause for Sem_Ch13. (Analyze_Proper_Body): Add local variable Comp_Unit. Unum is now a local variable. Code cleanup. Analysis related to the aspects of a subprogram body stub is now carried out by Analyze_Subprogram_Body_Helper. Do not propagate the aspects and/or pragmas of a subprogram body stub to the proper body as this is no longer needed. Do not analyze the aspects of a subprogram stub when the corresponding source unit is missing. (Analyze_Protected_Body_Stub): Flag the illegal use of aspects on a stub. (Analyze_Task_Body_Stub): Flag the illegal use of aspects on a stub. (Optional_Subunit): Add local variable Unum. * sem_ch13.adb (Insert_Delayed_Pragma): Do not analyze a generated pragma when it applies to a subprogram body stub. * sem_prag.adb (Analyze_Pragma): Pragmas Contract_Cases, Depends and Global can now apply to a subprogram body stub as long as it acts as its own spec. (Analyze_Refined_Pragma): Code reformatting. Refinement pragmas cannot apply to a subunit. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@208134 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/sem_prag.adb')
-rw-r--r--gcc/ada/sem_prag.adb98
1 files changed, 71 insertions, 27 deletions
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index 2b095eabbf6..a5eaf1304bd 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -3601,40 +3601,42 @@ package body Sem_Prag is
Body_Decl := Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
- if not Nkind_In (Body_Decl, N_Subprogram_Body,
- N_Subprogram_Body_Stub)
- then
- Pragma_Misplaced;
- return;
- end if;
-
- Body_Id := Defining_Entity (Body_Decl);
-
- -- The body [stub] must not act as a spec, in other words it has to
- -- be paired with a corresponding spec.
+ -- Extract the entities of the spec and body
if Nkind (Body_Decl) = N_Subprogram_Body then
+ Body_Id := Defining_Entity (Body_Decl);
Spec_Id := Corresponding_Spec (Body_Decl);
- else
+
+ elsif Nkind (Body_Decl) = N_Subprogram_Body_Stub then
+ Body_Id := Defining_Entity (Body_Decl);
Spec_Id := Corresponding_Spec_Of_Stub (Body_Decl);
+
+ else
+ Pragma_Misplaced;
+ return;
end if;
+ -- The pragma must apply to the second declaration of a subprogram.
+ -- In other words, the body [stub] cannot acts as a spec.
+
if No (Spec_Id) then
Error_Pragma ("pragma % cannot apply to a stand alone body");
return;
+
+ -- Catch the case where the subprogram body is a subunit and acts as
+ -- the third declaration of the subprogram.
+
+ elsif Nkind (Parent (Body_Decl)) = N_Subunit then
+ Error_Pragma ("pragma % cannot apply to a subunit");
+ return;
end if;
- -- The pragma may only apply to the body [stub] of a subprogram
+ -- The pragma can only apply to the body [stub] of a subprogram
-- declared in the visible part of a package. Retrieve the context of
-- the subprogram declaration.
Spec_Decl := Parent (Parent (Spec_Id));
- pragma Assert
- (Nkind_In (Spec_Decl, N_Abstract_Subprogram_Declaration,
- N_Generic_Subprogram_Declaration,
- N_Subprogram_Declaration));
-
if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then
Error_Pragma
("pragma % must apply to the body of a subprogram declared in a "
@@ -12445,10 +12447,24 @@ package body Sem_Prag is
Subp_Decl :=
Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
- if Nkind (Subp_Decl) /= N_Subprogram_Declaration
- and then (Nkind (Subp_Decl) /= N_Subprogram_Body
- or else not Acts_As_Spec (Subp_Decl))
+ if Nkind (Subp_Decl) = N_Subprogram_Declaration then
+ null;
+
+ -- Body acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body
+ and then No (Corresponding_Spec (Subp_Decl))
+ then
+ null;
+
+ -- Body stub acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
+ and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
then
+ null;
+
+ else
Pragma_Misplaced;
return;
end if;
@@ -12969,10 +12985,24 @@ package body Sem_Prag is
Subp_Decl :=
Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
- if Nkind (Subp_Decl) /= N_Subprogram_Declaration
- and then (Nkind (Subp_Decl) /= N_Subprogram_Body
- or else not Acts_As_Spec (Subp_Decl))
+ if Nkind (Subp_Decl) = N_Subprogram_Declaration then
+ null;
+
+ -- Body acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body
+ and then No (Corresponding_Spec (Subp_Decl))
then
+ null;
+
+ -- Body stub acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
+ and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
+ then
+ null;
+
+ else
Pragma_Misplaced;
return;
end if;
@@ -14239,10 +14269,24 @@ package body Sem_Prag is
Subp_Decl :=
Find_Related_Subprogram_Or_Body (N, Do_Checks => True);
- if Nkind (Subp_Decl) /= N_Subprogram_Declaration
- and then (Nkind (Subp_Decl) /= N_Subprogram_Body
- or else not Acts_As_Spec (Subp_Decl))
+ if Nkind (Subp_Decl) = N_Subprogram_Declaration then
+ null;
+
+ -- Body acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body
+ and then No (Corresponding_Spec (Subp_Decl))
then
+ null;
+
+ -- Body stub acts as spec
+
+ elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
+ and then No (Corresponding_Spec_Of_Stub (Subp_Decl))
+ then
+ null;
+
+ else
Pragma_Misplaced;
return;
end if;