diff options
Diffstat (limited to 'gcc/ada/par-ch6.adb')
-rw-r--r-- | gcc/ada/par-ch6.adb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb index f527dbe81cb..a05e79b51d6 100644 --- a/gcc/ada/par-ch6.adb +++ b/gcc/ada/par-ch6.adb @@ -154,6 +154,7 @@ package body Ch6 is function P_Subprogram (Pf_Flags : Pf_Rec) return Node_Id is Specification_Node : Node_Id; Name_Node : Node_Id; + Aspects : List_Id; Fpart_List : List_Id; Fpart_Sloc : Source_Ptr; Result_Not_Null : Boolean := False; @@ -186,6 +187,8 @@ package body Ch6 is Scope.Table (Scope.Last).Ecol := Start_Column; Scope.Table (Scope.Last).Lreq := False; + Aspects := Empty_List; + -- Ada 2005: Scan leading NOT OVERRIDING indicator if Token = Tok_Not then @@ -810,6 +813,16 @@ package body Ch6 is New_Node (N_Subprogram_Body, Sloc (Specification_Node)); Set_Specification (Body_Node, Specification_Node); + -- If aspects are present, the specification is parsed as + -- a subprogram declaration, and we jump here after seeing + -- the keyword IS. Attach asspects previously collected to + -- the body. + + if Is_Non_Empty_List (Aspects) then + Set_Parent (Aspects, Body_Node); + Set_Aspect_Specifications (Body_Node, Aspects); + end if; + -- In SPARK, a HIDE directive can be placed at the beginning -- of a subprogram implementation, thus hiding the -- subprogram body from SPARK tool-set. No violation of the @@ -841,7 +854,24 @@ package body Ch6 is Decl_Node := New_Node (N_Subprogram_Declaration, Sloc (Specification_Node)); Set_Specification (Decl_Node, Specification_Node); - P_Aspect_Specifications (Decl_Node); + Aspects := Get_Aspect_Specifications (Semicolon => False); + + -- Aspects may be present on a subprogram body. The source parsed + -- so far is that of its specification, go parse the body and attach + -- the collected aspects, if any, to the body. + + if Token = Tok_Is then + Scan; + goto Subprogram_Body; + + else + if Is_Non_Empty_List (Aspects) then + Set_Parent (Aspects, Decl_Node); + Set_Aspect_Specifications (Decl_Node, Aspects); + end if; + + TF_Semicolon; + end if; -- If this is a context in which a subprogram body is permitted, -- set active SIS entry in case (see section titled "Handling |