1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Einfo
; use Einfo
;
28 with Einfo
.Entities
; use Einfo
.Entities
;
29 with Einfo
.Utils
; use Einfo
.Utils
;
30 with Errout
; use Errout
;
31 with Namet
; use Namet
;
32 with Sem_Aux
; use Sem_Aux
;
33 with Sinfo
; use Sinfo
;
34 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
35 with Snames
; use Snames
;
37 package body Sem_Smem
is
39 function Contains_Access_Type
(T
: Entity_Id
) return Boolean;
40 -- This function determines if type T is an access type, or contains
41 -- a component (array, record, protected type cases) that contains
42 -- an access type (recursively defined in the appropriate manner).
44 ----------------------
45 -- Check_Shared_Var --
46 ----------------------
48 procedure Check_Shared_Var
54 -- We cannot tolerate aliased variables, because they might be
55 -- modified via an aliased pointer, and we could not detect that
56 -- this was happening (to update the corresponding shared memory
57 -- file), so we must disallow all use of Aliased
59 if Aliased_Present
(N
) then
61 ("aliased variables " &
62 "not supported in Shared_Passive partitions",
65 -- We can't support access types at all, since they are local
66 -- pointers that cannot in any simple way be transmitted to other
69 elsif Is_Access_Type
(T
) then
71 ("access type variables " &
72 "not supported in Shared_Passive partitions",
75 -- We cannot tolerate types that contain access types, same reasons
77 elsif Contains_Access_Type
(T
) then
79 ("types containing access components " &
80 "not supported in Shared_Passive partitions",
83 -- Objects with default-initialized types will be rejected when
84 -- the initialization code is generated. However we must flag tasks
85 -- earlier on, to prevent expansion of stream attributes that is
88 elsif Has_Task
(T
) then
90 ("Shared_Passive partitions cannot contain tasks", Id
);
92 -- Currently we do not support unconstrained record types, since we
93 -- use 'Write to write out values. This could probably be special
94 -- cased and handled in the future if necessary.
96 elsif Is_Record_Type
(T
)
97 and then not Is_Constrained
(T
)
98 and then (Nkind
(N
) /= N_Object_Declaration
99 or else No
(Expression
(N
)))
102 ("unconstrained variant records " &
103 "not supported in Shared_Passive partitions",
106 end Check_Shared_Var
;
108 --------------------------
109 -- Contains_Access_Type --
110 --------------------------
112 function Contains_Access_Type
(T
: Entity_Id
) return Boolean is
116 if Is_Access_Type
(T
) then
119 elsif Is_Array_Type
(T
) then
120 return Contains_Access_Type
(Component_Type
(T
));
122 elsif Is_Record_Type
(T
) then
123 if Has_Discriminants
(T
) then
125 -- Check for access discriminants.
127 C
:= First_Discriminant
(T
);
128 while Present
(C
) loop
129 if Is_Access_Type
(Etype
(C
)) then
132 Next_Discriminant
(C
);
137 C
:= First_Component
(T
);
138 while Present
(C
) loop
140 -- For components, ignore internal components other than _Parent
142 if Comes_From_Source
(T
)
144 (Chars
(C
) = Name_uParent
146 not Is_Internal_Name
(Chars
(C
)))
147 and then Contains_Access_Type
(Etype
(C
))
157 elsif Is_Protected_Type
(T
) then
158 return Contains_Access_Type
(Corresponding_Record_Type
(T
));
163 end Contains_Access_Type
;