]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Get rid of Sy/Sm mixing (Expression)
authorBob Duff <duff@adacore.com>
Wed, 15 Oct 2025 10:43:32 +0000 (06:43 -0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:17 +0000 (15:15 +0100)
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.

gcc/ada/exp_ch11.adb
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/gen_il-gen.adb
gcc/ada/gen_il-gen.ads
gcc/ada/sinfo.ads

index ee6010a744454324a3337c7bdf32ae95152448f2..a6b17184cb16e83d9fd8aaee44f38e0a98ec63a6 100644 (file)
@@ -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);
index e123631bb013ab8ede0337fce1ac43342dd0abfd..e6e00ff986def76d060313e2e74b0e974b9549cb 100644 (file)
@@ -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)));
 
index 26d0193702ccd510c01c4a23410da5b5d71a420d..873c3cd76497016b8733f386bfaf45ac47dda6ba 100644 (file)
@@ -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;
index cb364ad65e28034f64aa5071f769bcdf8850eb23..149afe1dda94ab16cbcd0a2a859a0471ef24f102 100644 (file)
 --  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
index f6610b74e03ed76b56d1a78fc718550be400a694..8a35fdc420821d6b5bd562fc2a2fb2c28c16bfe9 100644 (file)
@@ -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 --
       ------------------------------------------