Priority may be specified for protected and task types and objects using the standard aspect notation. This patch makes the analysis of the aspect argument earlier, so it is taken into account when the task or protected object is been created.
The following must compile quietly in Ada2012 mode and execute without producing any output. with Priority_Aspect; procedure Test_Priority_Aspect is begin null; end Test_Priority_Aspect; with System; package Priority_Aspect is Prio : constant System.Priority := System.Priority'First; task type Aspect_Type with Priority => Prio; T : Aspect_Type; task Aspect_Task with Priority => Prio; protected type Pr_Type with Priority => Prio is procedure Proc; end Pr_Type; P : Pr_Type; protected Pr_Obj with Priority => Prio is procedure Proc; end Pr_Obj; end Priority_Aspect; with Ada.Text_IO; use Ada.Text_IO; with Ada.Dynamic_Priorities; use Ada.Dynamic_Priorities; package body Priority_Aspect is protected body Pr_Type is procedure Proc is begin if Pr_Type'Priority /= Prio then Put_Line ("Unexpected priority when using aspect in protected type"); end if; end Proc; end Pr_Type; protected body Pr_Obj is procedure Proc is begin if Pr_Obj'Priority /= Prio then Put_Line ("Unexpected priority when using aspect in protected object"); end if; end Proc; end Pr_Obj; task body Aspect_Type is begin if Get_Priority /= Prio then Put_Line ("Unexpected priority when using aspect in task type"); end if; P.Proc; end Aspect_Type; task body Aspect_Task is begin if Get_Priority /= Prio then Put_Line ("Unexpected priority when using aspect in task object"); end if; Pr_Obj.Proc; end Aspect_Task; end Priority_Aspect; Command: gnatmake -q -gnat12 test_priority_aspect; test_priority_aspect Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-31 Jose Ruiz <r...@adacore.com> * sem_ch13.adb (Analyze_Aspect_Specifications): For the Priority and Interrupt_Priority aspects, force the analysis of the aspect expression (when building the equivalent pragma). Otherwise, its analysis is done too late, after the task or protected object has been created. * sem_ch9.adb (Analyze_Single_Protected_Declaration, Analyze_Single_Task_Declaration): Remove the code to move the aspects to the object declaration because they are needed in the type declaration.
Index: sem_ch9.adb =================================================================== --- sem_ch9.adb (revision 178358) +++ sem_ch9.adb (working copy) @@ -23,7 +23,6 @@ -- -- ------------------------------------------------------------------------------ -with Aspects; use Aspects; with Atree; use Atree; with Checks; use Checks; with Einfo; use Einfo; @@ -1726,7 +1725,6 @@ Defining_Identifier => O_Name, Object_Definition => Make_Identifier (Loc, Chars (T))); - Move_Aspects (N, O_Decl); Rewrite (N, T_Decl); Insert_After (N, O_Decl); Mark_Rewrite_Insertion (O_Decl); @@ -1796,7 +1794,6 @@ Defining_Identifier => O_Name, Object_Definition => Make_Identifier (Loc, Chars (T))); - Move_Aspects (N, O_Decl); Rewrite (N, T_Decl); Insert_After (N, O_Decl); Mark_Rewrite_Insertion (O_Decl); Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 178358) +++ sem_ch13.adb (working copy) @@ -1164,7 +1164,9 @@ Pragma_Identifier => Make_Identifier (Sloc (Id), Pname), Pragma_Argument_Associations => - New_List (Relocate_Node (Expr))); + New_List + (Make_Pragma_Argument_Association + (Sloc (Id), Expression => Relocate_Node (Expr)))); Set_From_Aspect_Specification (Aitem, True); @@ -1526,6 +1528,12 @@ end if; Prepend (Aitem, To => L); + + -- Analyze rewritten pragma. Otherwise, its + -- analysis is done too late, after the task or + -- protected object has been created. + + Analyze (Aitem); end; -- For all other cases, insert in sequence