[Ada] Legality rules for Synchronization aspect on protected operations

Arnaud Charlet charlet@adacore.com
Wed Feb 19 11:17:00 GMT 2014


This patch detects additional errors when a Synchronization aspect on an
overriding protected operation does not match the given aspect on the
overridden operation of an ancestor interface.

Compiling b95000g.ads must yield:

b95000g.ads:29:13:
     type "Lock_Type" must implement abstract subprogram "Unlock" with a
     procedure
b95000g.ads:30:17:
     overriding operation "Unlock_2" must have synchronization
       "BY_PROTECTED_PROCEDURE"
b95000g.ads:32:17:
     type "Lock_Type" must implement abstract subprogram "Lock" with an entry
b95000g.ads:33:17:
     overriding operation "Lock_2" must have syncrhonization "OPTIONAL"
b95000g.ads:38:14:
     overriding operation "Try_Lock" must have syncrhonization "OPTIONAL"

---
-- B95000G.A
--
--*
--
-- OBJECTIVE:
--      Check that primitive procedures of synchronized interfaces with
--      a Synchronization aspect cannot be completed with different callable
--      entity, or can have conflicting 
--
-- CHANGE HISTORY:
--      16 Nov 13   GRB     Initial version
--!

package B95000G is
   type Spinlock is synchronized interface;

   procedure Unlock (L : in out Spinlock) is abstract
      with Synchronization => By_Protected_Procedure;
   procedure Lock (L : in out Spinlock) is abstract
      with Synchronization => By_Entry;
   procedure Try_Lock  (L : in out Spinlock; Success : out Boolean) is abstract
      with Synchronization => Optional;
   procedure Unlock_2 (L : in out Spinlock) is abstract
      with Synchronization => By_Protected_Procedure;
   procedure Lock_2 (L : in out Spinlock) is abstract
      with Synchronization => Optional;

   protected type Lock_Type is new Spinlock with
      entry Unlock;  -- ERROR: must be protected procedure
      procedure Unlock_2 
        with Synchronization => Optional; -- ERROR: should be By_Prot_Proc
      procedure Lock; -- ERROR: must be entry
      procedure Lock_2 with Synchronization => By_Entry; -- ERROR: is procedure
   private
      Unlocked : Boolean := True;
   end Lock_Type; 

   procedure Try_Lock
     (L       : in out Lock_Type;
      Success : out Boolean) 
   with Synchronization => By_Entry; -- ERROR: is procedure
end B95000G;

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

2014-02-19  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Check_Pragma_Implemented): Detect additional
	errors when a Synchronization aspect on an overriding protected
	operation does not match the given aspect on the overridden
	operation of an ancestor interface.

-------------- next part --------------
Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 207879)
+++ sem_ch3.adb	(working copy)
@@ -9377,7 +9377,26 @@
                Error_Msg_NE
                  ("type & must implement abstract subprogram & with a " &
                   "procedure", Subp_Alias, Contr_Typ);
+
+            elsif Present (Get_Rep_Pragma (Impl_Subp, Name_Implemented))
+              and then Implementation_Kind (Impl_Subp) /= Impl_Kind
+            then
+               Error_Msg_Name_1 := Impl_Kind;
+               Error_Msg_N
+                ("overriding operation& must have synchronization%",
+                   Subp_Alias);
             end if;
+
+         --  If primitive has Optional synchronization, overriding operation
+         --  must match if it has an explicit synchronization..
+
+         elsif Present (Get_Rep_Pragma (Impl_Subp, Name_Implemented))
+           and then Implementation_Kind (Impl_Subp) /= Impl_Kind
+         then
+               Error_Msg_Name_1 := Impl_Kind;
+               Error_Msg_N
+                ("overriding operation& must have syncrhonization%",
+                   Subp_Alias);
          end if;
       end Check_Pragma_Implemented;
 


More information about the Gcc-patches mailing list