diff options
Diffstat (limited to 'gcc/ada/sem_ch6.adb')
-rw-r--r-- | gcc/ada/sem_ch6.adb | 87 |
1 files changed, 39 insertions, 48 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 5ace348..8c88d8f 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -11087,6 +11087,9 @@ package body Sem_Ch6 is -- references to parameters of the inherited subprogram to point to the -- corresponding parameters of the current subprogram. + procedure Insert_Before_First_Source_Declaration (Nod : Node_Id); + -- Insert node Nod before the first source declaration of the context + function Invariants_Or_Predicates_Present return Boolean; -- Determines if any invariants or predicates are present for any OUT -- or IN OUT parameters of the subprogram, or (for a function) if the @@ -11101,9 +11104,6 @@ package body Sem_Ch6 is -- that an invariant check is required (for an IN OUT parameter, or -- the returned value of a function. - function Last_Implicit_Declaration return Node_Id; - -- Return the last internally-generated declaration of N - ------------- -- Grab_CC -- ------------- @@ -11281,6 +11281,36 @@ package body Sem_Ch6 is return CP; end Grab_PPC; + -------------------------------------------- + -- Insert_Before_First_Source_Declaration -- + -------------------------------------------- + + procedure Insert_Before_First_Source_Declaration (Nod : Node_Id) is + Decls : constant List_Id := Declarations (N); + Decl : Node_Id; + + begin + if No (Decls) then + Set_Declarations (N, New_List (Nod)); + else + Decl := First (Decls); + + while Present (Decl) loop + if Comes_From_Source (Decl) then + exit; + end if; + + Next (Decl); + end loop; + + if No (Decl) then + Append_To (Decls, Nod); + else + Insert_Before (Decl, Nod); + end if; + end if; + end Insert_Before_First_Source_Declaration; + -------------------------------------- -- Invariants_Or_Predicates_Present -- -------------------------------------- @@ -11358,50 +11388,6 @@ package body Sem_Ch6 is end if; end Is_Public_Subprogram_For; - ------------------------------- - -- Last_Implicit_Declaration -- - ------------------------------- - - function Last_Implicit_Declaration return Node_Id is - Loc : constant Source_Ptr := Sloc (N); - Decls : List_Id := Declarations (N); - Decl : Node_Id; - Succ : Node_Id; - - begin - if No (Decls) then - Decls := New_List (Make_Null_Statement (Loc)); - Set_Declarations (N, Decls); - - elsif Is_Empty_List (Declarations (N)) then - Append_To (Decls, Make_Null_Statement (Loc)); - end if; - - -- Implicit and source declarations may be interspersed. Search for - -- the last implicit declaration which is either succeeded by a - -- source construct or is the last node in the declarative list. - - Decl := First (Declarations (N)); - while Present (Decl) loop - Succ := Next (Decl); - - -- The current declaration is the last one, do not return Empty - - if No (Succ) then - exit; - - -- The successor is a source construct - - elsif Comes_From_Source (Succ) then - exit; - end if; - - Next (Decl); - end loop; - - return Decl; - end Last_Implicit_Declaration; - -- Start of processing for Process_PPCs begin @@ -11807,7 +11793,12 @@ package body Sem_Ch6 is -- The entity for the _Postconditions procedure begin - Insert_After (Last_Implicit_Declaration, + -- Insert the corresponding body of a post condition pragma before + -- the first source declaration of the context. This ensures that + -- any [sub]types generated in relation to the formals of the + -- subprogram are still visible in the _postcondition body. + + Insert_Before_First_Source_Declaration ( Make_Subprogram_Body (Loc, Specification => Make_Procedure_Specification (Loc, |