]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Get rid of Sy/Sm mixing (Default_Expression)
authorBob Duff <duff@adacore.com>
Tue, 7 Oct 2025 14:35:03 +0000 (10:35 -0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:15 +0000 (15:15 +0100)
We should not mix "syntactic" and "semantic" for the same field
in different node kinds.

Change the name of Default_Expression (a syntactic field) on
N_Formal_Object_Declaration to be Expression. This avoids
the conflict with the name-named semantic field of
N_Parameter_Specification.

It is also more uniform with other syntactic categories that
use default_expression in the syntax rules.  See, for example,
COMPONENT_DECLARATION in sinfo.ads, which is presumably intended
to be uniform with OBJECT_DECLARATION.

Fix the comment on N_Formal_Object_Declaration to refer
to the new field name Expression.

gcc/ada/ChangeLog:

* gen_il-gen-gen_nodes.adb: Rename Default_Expression to be
Expression.
* gen_il-gen.adb (Check_For_Syntactic_Field_Mismatch): Do not
exempt Default_Expression from the rule.
* par-ch12.adb (P_Formal_Object_Declarations): Use renamed setter.
* sem_ch12.adb (Default): Use renamed getter.
(Analyze_Formal_Object_Declaration): Likewise.
* sprint.adb (Sprint_Node_Actual): Use renamed getter.
* sinfo.ads: Fix comments.

gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/gen_il-gen.adb
gcc/ada/par-ch12.adb
gcc/ada/sem_ch12.adb
gcc/ada/sinfo.ads
gcc/ada/sprint.adb

index 9fb962bf39c69cd44eb52e7134864138373434a4..59fe2d85250f9c46df177e520b9453a458fa0b44 100644 (file)
@@ -526,7 +526,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
         Sy (Null_Exclusion_Present, Flag, Default_False),
         Sy (Access_Definition, Node_Id, Default_Empty),
         Sy (Subtype_Mark, Node_Id, Default_Empty),
-        Sy (Default_Expression, Node_Id, Default_Empty),
+        Sy (Expression, Node_Id, Default_Empty),
         Sy (Aspect_Specifications, List_Id, Default_No_List),
         Sm (More_Ids, Flag),
         Sm (Prev_Ids, Flag)));
index 7cf99977dcbb5a3dfbc34be6ec35a3f3d63a9863..28622ff43d81e28adbb82a19faa664d7d70afe04 100644 (file)
@@ -1306,8 +1306,7 @@ package body Gen_IL.Gen is
                   --  for now. At least, we don't want to add any new cases of
                   --  syntactic/semantic mismatch.
 
-                  if F in Actions | Expression | Default_Expression
-                  then
+                  if F in Actions | Expression then
                      pragma Assert (Syntactic_Seen and Semantic_Seen);
 
                   else
index 7bd449d0b72fb08e72ec14281061efd9edb6f654..18cd9072452f744e3105e125ef7cc63b5cfac83a 100644 (file)
@@ -466,7 +466,7 @@ package body Ch12 is
          end if;
 
          No_Constraint;
-         Set_Default_Expression (Decl_Node, Init_Expr_Opt);
+         Set_Expression (Decl_Node, Init_Expr_Opt);
          P_Aspect_Specifications (Decl_Node, Semicolon => True);
 
          if Ident > 1 then
index 8d7378e35b9444449d48590be28071f49b1f837d..cee0b17df46b7d8b44d5c1de2aa50cf4f0a26e54 100644 (file)
@@ -1607,8 +1607,8 @@ package body Sem_Ch12 is
          return Result : Actual_Rec do
             case Nkind (Un_Formal) is
                when N_Formal_Object_Declaration =>
-                  if Present (Default_Expression (Un_Formal)) then
-                     Result := (Name_Exp, Default_Expression (Un_Formal));
+                  if Present (Expression (Un_Formal)) then
+                     Result := (Name_Exp, Expression (Un_Formal));
                   end if;
                when N_Formal_Type_Declaration =>
                   if Present (Default_Subtype_Mark (Un_Formal)) then
@@ -2557,7 +2557,7 @@ package body Sem_Ch12 is
                           (Defining_Identifier
                             (Assoc.Un_Formal), Sloc (N)),
                       Explicit_Generic_Actual_Parameter =>
-                        New_Copy_Tree (Default_Expression (Assoc.Un_Formal))));
+                        New_Copy_Tree (Expression (Assoc.Un_Formal))));
                end if;
             end if;
 
@@ -3361,7 +3361,7 @@ package body Sem_Ch12 is
    ---------------------------------------
 
    procedure Analyze_Formal_Object_Declaration (N : Node_Id) is
-      E  : constant Node_Id := Default_Expression (N);
+      E  : constant Node_Id := Expression (N);
       Id : constant Node_Id := Defining_Identifier (N);
 
       K                : Entity_Kind;
@@ -13239,7 +13239,7 @@ package body Sem_Ch12 is
                end if;
             end;
 
-         elsif Present (Default_Expression (Formal)) then
+         elsif Present (Expression (Formal)) then
 
             --  Use default to construct declaration
 
@@ -13257,7 +13257,7 @@ package body Sem_Ch12 is
                 Null_Exclusion_Present => Null_Exclusion_Present (Formal),
                 Object_Definition      => Def,
                 Expression             => New_Copy_Tree
-                                            (Default_Expression (Formal)));
+                                            (Expression (Formal)));
 
             Copy_Ghost_Aspect (Formal, To => Decl_Node);
             Set_Corresponding_Generic_Association
index 2c15b80d12ef55a8762f4e8207c9c83105fd3d58..a1a850adb4af63c8a1a672fbcd6670feceeabcd5 100644 (file)
@@ -5505,7 +5505,7 @@ package Sinfo is
       --  Out_Present
       --  Null_Exclusion_Present
       --  Parameter_Type subtype mark or access definition
-      --  Expression (set to Empty if no default expression present)
+      --  Expression (set to Empty if no default expression)
       --  More_Ids (set to False if no more identifiers in list)
       --  Prev_Ids (set to False if no previous identifiers in list)
       --  Default_Expression
@@ -7236,7 +7236,7 @@ package Sinfo is
       --  Null_Exclusion_Present (set to False if not present)
       --  Subtype_Mark (set to Empty if not present)
       --  Access_Definition (set to Empty if not present)
-      --  Default_Expression (set to Empty if no default expression)
+      --  Expression (set to Empty if no default expression)
       --  More_Ids (set to False if no more identifiers in list)
       --  Prev_Ids (set to False if no previous identifiers in list)
 
index f5caa3d1b78d4b3f4c59f7aa50e57924fc24210f..8c49864b87af9a18a76cb4bfd8df1b1602637b91 100644 (file)
@@ -1963,9 +1963,9 @@ package body Sprint is
                   Sprint_Node (Access_Definition (Node));
                end if;
 
-               if Present (Default_Expression (Node)) then
+               if Present (Expression (Node)) then
                   Write_Str (" := ");
-                  Sprint_Node (Default_Expression (Node));
+                  Sprint_Node (Expression (Node));
                end if;
 
                Write_Char (';');