From d268147dea8efee7a66e409e7cba492ab4679f29 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 23 Jan 2017 13:31:43 +0000 Subject: [PATCH] sem_prag.adb (Default_Initial_Condition): If the desired type declaration is a derived type declaration with discriminants... 2017-01-23 Ed Schonberg * sem_prag.adb (Default_Initial_Condition): If the desired type declaration is a derived type declaration with discriminants, it is rewritten as a private type declaration. * sem_ch13.adb (Replace_Type_References_Generic, Visible_Component): A discriminated private type with descriminnts has components that must be rewritten as selected components if they appear as identifiers in an aspect expression such as a Default_Initial_Condition. * sem_util.adb (Defining_Entity): support N_Iterator_Specification nodes. From-SVN: r244809 --- gcc/ada/ChangeLog | 13 +++++++++++++ gcc/ada/sem_ch13.adb | 15 ++++++++++----- gcc/ada/sem_prag.adb | 8 ++++++-- gcc/ada/sem_util.adb | 1 + 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b396520ced4..53d4bc31e61 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,16 @@ +2017-01-23 Ed Schonberg + + * sem_prag.adb (Default_Initial_Condition): If the desired type + declaration is a derived type declaration with discriminants, + it is rewritten as a private type declaration. + * sem_ch13.adb (Replace_Type_References_Generic, + Visible_Component): A discriminated private type with descriminnts + has components that must be rewritten as selected components + if they appear as identifiers in an aspect expression such as + a Default_Initial_Condition. + * sem_util.adb (Defining_Entity): support N_Iterator_Specification + nodes. + 2017-01-23 Hristian Kirtchev * ghost.ads, ghost.adb (Is_Ignored_Ghost_Unit): New routine. diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 5ac1c297a91..ac1e02cfee3 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -12688,10 +12688,13 @@ package body Sem_Ch13 is E : Entity_Id; begin - if Ekind (T) /= E_Record_Type then - return Empty; - else + -- Types with nameable components are records and discriminated + -- private types. + + if Ekind (T) = E_Record_Type + or else (Is_Private_Type (T) and then Has_Discriminants (T)) + then E := First_Entity (T); while Present (E) loop if Comes_From_Source (E) and then Chars (E) = Comp then @@ -12700,9 +12703,11 @@ package body Sem_Ch13 is Next_Entity (E); end loop; - - return Empty; end if; + + -- Nothing by that name, or type has no components. + + return Empty; end Visible_Component; -- Start of processing for Replace_Type_References_Generic diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index c44c2ab7ff2..cae36e65caf 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -13840,9 +13840,13 @@ package body Sem_Prag is Error_Msg_N ("pragma % duplicates pragma declared#", N); end if; - -- Skip internally generated code + -- Skip internally generated code. Note that derived type + -- declarations of untagged types with discriminants are + -- rewritten as private type declarations. - elsif not Comes_From_Source (Stmt) then + elsif not Comes_From_Source (Stmt) + and then Nkind (Stmt) /= N_Private_Type_Declaration + then null; -- The associated private type [extension] has been found, stop diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 40a72f7c9ae..c5d5473c37e 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -5238,6 +5238,7 @@ package body Sem_Util is | N_Full_Type_Declaration | N_Implicit_Label_Declaration | N_Incomplete_Type_Declaration + | N_Iterator_Specification | N_Loop_Parameter_Specification | N_Number_Declaration | N_Object_Declaration -- 2.30.2