From: Bob Duff Date: Wed, 15 Oct 2025 10:43:32 +0000 (-0400) Subject: ada: Get rid of Sy/Sm mixing (Expression) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39ba3bb91312eaa37fbcfb94e5cb7689df7e690f;p=thirdparty%2Fgcc.git ada: Get rid of Sy/Sm mixing (Expression) We should not mix "syntactic" and "semantic" for the same field in different node kinds. The Expression field was both syntactic (in N_Exception_Declaration) and semantic (in all other node kinds). This patch makes it always syntactic. Expression is the last such field, so we remove all code and comments that allowed for such mixing. The Expression field in N_Exception_Declaration was never properly documented; fix that. No change in overall compiler behavior. An alternative would be to change the name of this Expression field to be something else (Exception_Declaration_Expression?), and keep it as "semantic". That would cause an earthquake in gigi, because gigi wants to treat exception declarations more-or-less like normal object declarations, with the Expression field being the initialization expression. So we don't do that. gcc/ada/ChangeLog: * gen_il-gen-gen_nodes.adb (N_Exception_Declaration): Change Expression from Sm to Sy, to match other Expression fields. * gen_il-gen.adb (Setter_Needs_Parent): Expression no longer needs to be a special case. (Check_For_Syntactic_Field_Mismatch): Do not exempt Expression from the Sy/Sm mixing rule. This was the last such case, so remove all the exemption code. * gen_il-gen.ads: Update comments to match new code. * sinfo.ads (N_Exception_Declaration): Document the meaning of the Expression field, because it doesn't follow from the RM syntax of exception_declaration. * exp_ch11.adb: Minor comment fixes. --- diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb index ee6010a7444..a6b17184cb1 100644 --- a/gcc/ada/exp_ch11.adb +++ b/gcc/ada/exp_ch11.adb @@ -1031,7 +1031,7 @@ package body Exp_Ch11 is -- "hoisted" (i.e., Is_Statically_Allocated and not Is_Library_Level) -- entity must also be either Library_Level or hoisted. It turns out -- that this would be incompatible with the current treatment of an - -- object which is local to a subprogram, subject to an Export pragma, + -- object that is local to a subprogram, subject to an Export pragma, -- not subject to an address clause, and whose declaration contains -- references to other local (non-hoisted) objects (e.g., in the initial -- value expression). @@ -1558,7 +1558,7 @@ package body Exp_Ch11 is Build_Location_String (Buf, Loc); -- If the exception is a renaming, use the exception that it - -- renames (which might be a predefined exception, e.g.). + -- renames (which might be a predefined exception). if Present (Renamed_Entity (Id)) then Id := Renamed_Entity (Id); diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb index e123631bb01..e6e00ff986d 100644 --- a/gcc/ada/gen_il-gen-gen_nodes.adb +++ b/gcc/ada/gen_il-gen-gen_nodes.adb @@ -1290,7 +1290,7 @@ begin -- Gen_IL.Gen.Gen_Nodes Cc (N_Exception_Declaration, N_Declaration, (Sy (Defining_Identifier, Node_Id), Sy (Aspect_Specifications, List_Id, Default_No_List), - Sm (Expression, Node_Id), + Sy (Expression, Node_Id, Default_Empty), Sm (More_Ids, Flag), Sm (Prev_Ids, Flag))); diff --git a/gcc/ada/gen_il-gen.adb b/gcc/ada/gen_il-gen.adb index 26d0193702c..873c3cd7649 100644 --- a/gcc/ada/gen_il-gen.adb +++ b/gcc/ada/gen_il-gen.adb @@ -505,13 +505,11 @@ package body Gen_IL.Gen is Node_Field_Types_Used, Entity_Field_Types_Used : Type_Set; Setter_Needs_Parent : Field_Set := - (Expression | Then_Actions | Else_Actions => True, + (Then_Actions | Else_Actions => True, others => False); -- Set of fields where the setter should set the Parent. True for - -- syntactic fields of type Node_Id and List_Id, but with some - -- exceptions. Expression is syntactic AND semantic, and the Parent - -- is needed. Then_Actions and Else_Actions are not syntactic, but the - -- Parent is needed. + -- syntactic fields of type Node_Id and List_Id. Then_Actions and + -- Else_Actions are not syntactic, but the Parent is needed. -- -- Computed in Check_For_Syntactic_Field_Mismatch. @@ -1296,26 +1294,15 @@ package body Gen_IL.Gen is end if; end loop; - -- ???The following fields violate this rule. We might want - -- to simplify by getting rid of these cases, but we allow - -- them for now. At least, we don't want to add any new - -- cases of syntactic/semantic mismatch. - -- ???Just one case left. - - if F in Expression then - pragma Assert (Syntactic_Seen and Semantic_Seen); - - else - if Syntactic_Seen and Semantic_Seen then - raise Illegal with - "syntactic/semantic mismatch for " & Image (F); - end if; + if Syntactic_Seen and Semantic_Seen then + raise Illegal with + "syntactic/semantic mismatch for " & Image (F); + end if; - if Field_Table (F).Field_Type in Traversed_Field_Type - and then Syntactic_Seen - then - Setter_Needs_Parent (F) := True; - end if; + if Field_Table (F).Field_Type in Traversed_Field_Type + and then Syntactic_Seen + then + Setter_Needs_Parent (F) := True; end if; end; end if; diff --git a/gcc/ada/gen_il-gen.ads b/gcc/ada/gen_il-gen.ads index cb364ad65e2..149afe1dda9 100644 --- a/gcc/ada/gen_il-gen.ads +++ b/gcc/ada/gen_il-gen.ads @@ -48,14 +48,12 @@ -- If a field is syntactic, then the constructors in Nmake take a parameter to -- initialize that field. In addition, the tree-traversal routines in Atree -- (Traverse_Func and Traverse_Proc) traverse syntactic fields that are of --- type Node_Id (or subtypes of Node_Id) or List_Id. Finally, (with some --- exceptions documented in the body) the setter for a syntactic node or list --- field "Set_F (N, Val)" will set the Parent of Val to N, unless Val is Empty --- or Error[_List]. +-- type Node_Id (or subtypes of Node_Id) or List_Id. Finally, the setter for a +-- syntactic node or list field "Set_F (N, Val)" will set the Parent of Val to +-- N, unless Val is Empty or Error[_List]. -- --- Note that the same field can be syntactic in some node types but semantic --- in other node types. This is an added complexity that we might want to --- eliminate someday. We shouldn't add any new such cases. +-- No syntactic/semantic mixing: the same field cannot be syntactic in some +-- node types but semantic in other node types. -- -- A "program" written in the Gen_IL.Gen language consists of calls to the -- "Create_..." routines below, followed by a call to Compile, also below. In diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads index f6610b74e03..8a35fdc4208 100644 --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -6839,10 +6839,16 @@ package Sinfo is -- N_Exception_Declaration -- Sloc points to EXCEPTION -- Defining_Identifier - -- Expression + -- Expression (see below) -- More_Ids (set to False if no more identifiers in list) -- Prev_Ids (set to False if no previous identifiers in list) + -- Expression is not present in the syntax; it is set during expansion. + -- An exception_declaration is treated by the back end like an object of + -- type Standard.Exception_Type, and Expression is the initial value. + -- Expression is a syntactic field to match the Expression fields of + -- other node kinds. + ------------------------------------------ -- 11.2 Handled Sequence Of Statements -- ------------------------------------------