1entity e is 2end entity; 3 4architecture a of e is 5 6 type SharedCounter is protected 7 procedure increment (N: Integer := 1); 8 procedure decrement (N: Integer := 1); 9 impure function value return Integer; 10 end protected SharedCounter; 11 12 type bad1 is protected 13 procedure foo (x : not_here); -- Error 14 end protected; 15 16 type bad1 is protected body 17 end protected body; 18 19 type bad2 is protected body -- Error 20 end protected body; 21 22 type integer is protected body -- Error 23 end protected body; 24 25 type now is protected body -- Error 26 end protected body; 27 28 type SharedCounter is protected body 29 variable counter: Integer := 0; 30 31 procedure increment (N: Integer := 1) is 32 begin 33 counter := counter + N; 34 end procedure increment; 35 36 procedure decrement (N: Integer := 1) is 37 begin 38 counter := counter - N; 39 end procedure decrement; 40 41 impure function value return Integer is 42 begin 43 return counter; 44 end function value; 45 end protected body; 46 47 type SharedCounter is protected body -- Error 48 end protected body; 49 50 subtype s is SharedCounter; -- Error 51 52 shared variable x : integer; -- Error 53 54 shared variable y : SharedCounter; -- OK 55 56 shared variable y : SharedCounter := 1; -- Error 57 58 function make return SharedCounter is 59 variable result : SharedCounter; 60 begin 61 return result; 62 end function; 63 64 procedure proc(variable sh : in SharedCounter := make) is -- error 65 begin 66 end procedure; 67 68begin 69 70end architecture; 71 72architecture a2 of e is 73 74 type SharedCounter is protected 75 procedure increment (N: Integer := 1); 76 procedure decrement (N: Integer := 1); 77 impure function value return Integer; 78 procedure foo (x : in integer); 79 end protected SharedCounter; 80 81 type SharedCounter is protected body 82 variable counter: Integer := 0; 83 84 procedure increment (N: Integer := 1) is 85 begin 86 counter := counter + N; 87 end procedure increment; 88 89 procedure decrement (N: Integer := 1) is 90 begin 91 counter := counter - N; 92 end procedure decrement; 93 94 impure function value return Integer is 95 begin 96 return counter; 97 end function value; 98 99 procedure bar (x : in integer ) is 100 begin 101 null; 102 end procedure; 103 104 procedure foo (x : in integer ) is 105 begin 106 bar(x + 1); 107 end procedure; 108 end protected body; 109 110 shared variable x : SharedCounter; -- OK 111 112begin 113 114 process is 115 begin 116 x.increment(2); -- OK 117 x.increment; -- OK 118 x.counter := 5; -- Error 119 x.decrement(1, 2); -- Error 120 assert x.value = 5; -- OK 121 end process; 122 123 process is 124 function get_value (x : in sharedcounter ) return integer is -- Error 125 begin 126 return x.value; 127 end function; 128 begin 129 end process; 130 131 bad_assignment: process 132 variable y : SharedCounter; 133 variable z : SharedCounter; 134 begin 135 y := z; -- Error 136 wait; 137 end process; 138 139end architecture; 140 141package issue85 is 142 143 type protected_t is protected 144 procedure add(argument : inout protected_t); -- OK 145 end protected protected_t; 146 147end package; 148 149package pkg is 150 type protected_t is protected 151 end protected protected_t; 152end package; 153 154package body pkg is 155 -- Missing body for protected_t 156end package body; 157