diff mbox series

[Ada] Handle properly user_defined literals given by operators.

Message ID 20211004084824.GA1539708@adacore.com
State New
Headers show
Series [Ada] Handle properly user_defined literals given by operators. | expand

Commit Message

Pierre-Marie de Rodat Oct. 4, 2021, 8:48 a.m. UTC
This patch expands the implementation of aspects Integer_Literal,
Real_Literal and String_Literal, so that the value of the aspect, which
must be a function name, can be specified by an Operator_Symbol.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch6.adb (Analyze_Operator_Symbol): Recognize strings as
	operator names when they are the value of one of the Ada2022
	aspects for User_Defined_Literals.
	* sem_ch13.adb (Analyze_One_Aspect): Handle an aspect value
	given by an Operator_Name.
	(Validate_Literal_Aspect): Call Analyze_Operator_Symbol when
	needed.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -2991,7 +2991,15 @@  package body Sem_Ch13 is
             --  Copy expression for later processing by the procedures
             --  Check_Aspect_At_[Freeze_Point | End_Of_Declarations]
 
-            Set_Entity (Id, New_Copy_Tree (Expr));
+            --  The expression may be a subprogram name, and can
+            --  be an operator name that appears as a string, but
+            --  requires its own analysis procedure (see sem_ch6).
+
+            if Nkind (Expr) = N_Operator_Symbol then
+               Set_Entity (Id, Expr);
+            else
+               Set_Entity (Id, New_Copy_Tree (Expr));
+            end if;
 
             --  Set Delay_Required as appropriate to aspect
 
@@ -16668,7 +16676,15 @@  package body Sem_Ch13 is
       end if;
 
       if not Overloaded and then not Present (Entity (Func_Name)) then
-         Analyze (Func_Name);
+         --  The aspect is specified by a subprogram name, which
+         --  may be an operator name given originally by a string.
+
+         if Is_Operator_Name (Chars (Func_Name)) then
+            Analyze_Operator_Symbol (Func_Name);
+         else
+            Analyze (Func_Name);
+         end if;
+
          Overloaded := Is_Overloaded (Func_Name);
       end if;
 


diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -2126,8 +2126,15 @@  package body Sem_Ch6 is
                   and then Attribute_Name (Par) /= Name_Value)
         or else (Nkind (Maybe_Aspect_Spec) = N_Aspect_Specification
                   and then Get_Aspect_Id (Maybe_Aspect_Spec)
-                            --  include other aspects here ???
-                            in Aspect_Stable_Properties | Aspect_Aggregate)
+
+                            --  Include aspects that can be specified by a
+                            --  subprogram name, which can be an operator.
+
+                            in  Aspect_Stable_Properties
+                              | Aspect_Integer_Literal
+                              | Aspect_Real_Literal
+                              | Aspect_String_Literal
+                              | Aspect_Aggregate)
       then
          Find_Direct_Name (N);