diff options
author | Etienne Servais <servais@adacore.com> | 2021-10-01 17:04:11 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-11-10 08:57:38 +0000 |
commit | f51d1dde83fd4b6b2730a2b6b45e5966245e0561 (patch) | |
tree | b69cbe6c1ff34a3e772929f82abce84232ce92ed | |
parent | 8c787be254c50d208a15a18033d29de419c7c165 (diff) | |
download | gcc-f51d1dde83fd4b6b2730a2b6b45e5966245e0561.zip gcc-f51d1dde83fd4b6b2730a2b6b45e5966245e0561.tar.gz gcc-f51d1dde83fd4b6b2730a2b6b45e5966245e0561.tar.bz2 |
[Ada] Warn when interfaces swapped between full and partial view
gcc/ada/
* sem_ch3.adb (Derived_Type_Declaration): Introduce a subprogram
for tree transformation. If a tree transformation is performed,
then warn that it would be better to reorder the interfaces.
-rw-r--r-- | gcc/ada/sem_ch3.adb | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index e854bb3..569e019 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -17258,10 +17258,46 @@ package body Sem_Ch3 is and then Is_Interface (Parent_Type) then declare - Iface : Node_Id; Partial_View : Entity_Id; Partial_View_Parent : Entity_Id; - New_Iface : Node_Id; + + function Reorder_Interfaces return Boolean; + -- Look for an interface in the full view's interface list that + -- matches the parent type of the partial view, and when found, + -- rewrite the full view's parent with the partial view's parent, + -- append the full view's original parent to the interface list, + -- recursively call Derived_Type_Definition on the full type, and + -- return True. If a match is not found, return False. + -- ??? This seems broken in the case of generic packages. + + ------------------------ + -- Reorder_Interfaces -- + ------------------------ + + function Reorder_Interfaces return Boolean is + Iface : Node_Id; + New_Iface : Node_Id; + begin + Iface := First (Interface_List (Def)); + while Present (Iface) loop + if Etype (Iface) = Etype (Partial_View) then + Rewrite (Subtype_Indication (Def), + New_Copy (Subtype_Indication (Parent (Partial_View)))); + + New_Iface := + Make_Identifier (Sloc (N), Chars (Parent_Type)); + Append (New_Iface, Interface_List (Def)); + + -- Analyze the transformed code + + Derived_Type_Declaration (T, N, Is_Completion); + return True; + end if; + + Next (Iface); + end loop; + return False; + end Reorder_Interfaces; begin -- Look for the associated private type declaration @@ -17282,30 +17318,26 @@ package body Sem_Ch3 is then null; - -- Traverse the list of interfaces of the full-view to look - -- for the parent of the partial-view and perform the tree - -- transformation. + -- Traverse the list of interfaces of the full view to look + -- for the parent of the partial view and reorder the + -- interfaces to match the order in the partial view, + -- if needed. else - Iface := First (Interface_List (Def)); - while Present (Iface) loop - if Etype (Iface) = Etype (Partial_View) then - Rewrite (Subtype_Indication (Def), - New_Copy (Subtype_Indication - (Parent (Partial_View)))); - - New_Iface := - Make_Identifier (Sloc (N), Chars (Parent_Type)); - Append (New_Iface, Interface_List (Def)); - -- Analyze the transformed code + if Reorder_Interfaces then + -- Having the interfaces listed in any order is legal. + -- However, the compiler does not properly handle + -- different orders between partial and full views in + -- generic units. We give a warning about the order + -- mismatch, so the user can work around this problem. - Derived_Type_Declaration (T, N, Is_Completion); - return; - end if; + Error_Msg_N ("??full declaration does not respect " & + "partial declaration order", T); + Error_Msg_N ("\??consider reordering", T); - Next (Iface); - end loop; + return; + end if; end if; end if; end; |