https://gcc.gnu.org/g:7e948513468e9beddb5e1978ef64851e9cd44055

commit r16-1334-g7e948513468e9beddb5e1978ef64851e9cd44055
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Mon Mar 10 12:02:45 2025 +0100

    ada: Remove duplicated code in parser for Chapter 4 (continued)
    
    P_Qualified_Simple_Name and P_Function_Name contain essentially the same
    code, except that P_Function_Name does not error out on an operator symbol
    that is followed by something else than a dot.
    
    This deletes P_Function_Name and changes P_Qualified_Simple_Name[_Resync]
    to not error out either in this case, with the only consequence that the
    error message given for:
    
      generic
        type T is private;
      function "&" (A, B : String) return String;
    
      procedure Proc is new "&" (Integer);
    
    is now identical to the one given for:
    
      generic
        type T is private;
      function "&" (A, B : String) return String;
    
      function Func is new "&" (Integer);
    
    namely:
    
    q.ads:7:12: error: operator symbol not allowed for generic subprogram
    
    gcc/ada/ChangeLog:
    
            * par-ch4.adb (P_Function_Name): Delete body.
            (P_Qualified_Simple_Name_Resync): Do not raise Error_Resync on an
            operator symbol followed by something else than a dot.
            * par-ch6.adb (P_Subprogram): Do not call P_Function_Name.
            * par.adb (P_Function_Name): Delete declaration.

Diff:
---
 gcc/ada/par-ch4.adb | 77 +++--------------------------------------------------
 gcc/ada/par-ch6.adb |  3 +--
 gcc/ada/par.adb     |  1 -
 3 files changed, 4 insertions(+), 77 deletions(-)

diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
index 1f1366817cc1..ebdc587f0e15 100644
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -935,69 +935,6 @@ package body Ch4 is
 
    --  Error recovery: cannot raise Error_Resync
 
-   function P_Function_Name return Node_Id is
-      Designator_Node : Node_Id;
-      Prefix_Node     : Node_Id;
-      Selector_Node   : Node_Id;
-      Dot_Sloc        : Source_Ptr := No_Location;
-
-   begin
-      --  Prefix_Node is set to the gathered prefix so far, Empty means that
-      --  no prefix has been scanned. This allows us to build up the result
-      --  in the required right recursive manner.
-
-      Prefix_Node := Empty;
-
-      --  Loop through prefixes
-
-      loop
-         Designator_Node := Token_Node;
-
-         if Token not in Token_Class_Desig then
-            return P_Identifier; -- let P_Identifier issue the error message
-
-         else -- Token in Token_Class_Desig
-            Scan; -- past designator
-            exit when Token /= Tok_Dot;
-         end if;
-
-         --  Here at a dot, with token just before it in Designator_Node
-
-         if No (Prefix_Node) then
-            Prefix_Node := Designator_Node;
-         else
-            Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
-            Set_Prefix (Selector_Node, Prefix_Node);
-            Set_Selector_Name (Selector_Node, Designator_Node);
-            Prefix_Node := Selector_Node;
-         end if;
-
-         Dot_Sloc := Token_Ptr;
-         Scan; -- past dot
-      end loop;
-
-      --  Fall out of the loop having just scanned a designator
-
-      if No (Prefix_Node) then
-         return Designator_Node;
-      else
-         Selector_Node := New_Node (N_Selected_Component, Dot_Sloc);
-         Set_Prefix (Selector_Node, Prefix_Node);
-         Set_Selector_Name (Selector_Node, Designator_Node);
-         return Selector_Node;
-      end if;
-
-   exception
-      when Error_Resync =>
-         return Error;
-   end P_Function_Name;
-
-   --  This function parses a restricted form of Names which are either
-   --  identifiers, or identifiers preceded by a sequence of prefixes
-   --  that are direct names.
-
-   --  Error recovery: cannot raise Error_Resync
-
    function P_Qualified_Simple_Name return Node_Id is
    begin
       return P_Qualified_Simple_Name_Resync;
@@ -1019,7 +956,7 @@ package body Ch4 is
       Dot_Sloc        : Source_Ptr := No_Location;
 
    begin
-      --  Prefix node is set to the gathered prefix so far, Empty means that
+      --  Prefix_Node is set to the gathered prefix so far, Empty means that
       --  no prefix has been scanned. This allows us to build up the result
       --  in the required right recursive manner.
 
@@ -1030,21 +967,13 @@ package body Ch4 is
       loop
          Designator_Node := Token_Node;
 
-         if Token = Tok_Identifier then
-            Scan; -- past identifier
-            exit when Token /= Tok_Dot;
-
-         elsif Token not in Token_Class_Desig then
+         if Token not in Token_Class_Desig then
             Discard_Junk_Node (P_Identifier); -- to issue the error message
             raise Error_Resync;
 
          else
             Scan; -- past designator
-
-            if Token /= Tok_Dot then
-               Error_Msg_SP ("identifier expected");
-               raise Error_Resync;
-            end if;
+            exit when Token /= Tok_Dot;
          end if;
 
          --  Here at a dot, with token just before it in Designator_Node
diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
index 55591fdc0335..0f7765ba300d 100644
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -362,12 +362,11 @@ package body Ch6 is
 
             if Func then
                Inst_Node := New_Node (N_Function_Instantiation, Fproc_Sloc);
-               Set_Name (Inst_Node, P_Function_Name);
             else
                Inst_Node := New_Node (N_Procedure_Instantiation, Fproc_Sloc);
-               Set_Name (Inst_Node, P_Qualified_Simple_Name);
             end if;
 
+            Set_Name (Inst_Node, P_Qualified_Simple_Name);
             Set_Defining_Unit_Name (Inst_Node, Name_Node);
             Set_Generic_Associations (Inst_Node, P_Generic_Actual_Part_Opt);
             P_Aspect_Specifications (Inst_Node, Semicolon => True);
diff --git a/gcc/ada/par.adb b/gcc/ada/par.adb
index 0003a332222e..e11ec7e7ff44 100644
--- a/gcc/ada/par.adb
+++ b/gcc/ada/par.adb
@@ -830,7 +830,6 @@ function Par (Configuration_Pragmas : Boolean) return 
List_Id is
       function P_Aggregate                            return Node_Id;
       function P_Expression                           return Node_Id;
       function P_Expression_Or_Range_Attribute        return Node_Id;
-      function P_Function_Name                        return Node_Id;
       function P_Name                                 return Node_Id;
       function P_Qualified_Simple_Name                return Node_Id;
       function P_Qualified_Simple_Name_Resync         return Node_Id;

Reply via email to