OSDN Git Service

* rtl.h (mem_attrs): Rename decl to expr; adjust all users.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_smem.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ S M E M                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.5 $
10 --                                                                          --
11 --          Copyright (C) 1998-2000, Free Software Foundation, Inc.         --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 with Atree;  use Atree;
30 with Einfo;  use Einfo;
31 with Errout; use Errout;
32 with Namet;  use Namet;
33 with Sinfo;  use Sinfo;
34 with Snames; use Snames;
35
36 package body Sem_Smem is
37
38    function Contains_Access_Type (T : Entity_Id) return Boolean;
39    --  This function determines if type T is an access type, or contains
40    --  a component (array, record, protected type cases) that contains
41    --  an access type (recursively defined in the appropriate manner).
42
43    ----------------------
44    -- Check_Shared_Var --
45    ----------------------
46
47    procedure Check_Shared_Var
48      (Id : Entity_Id;
49       T  : Entity_Id;
50       N  : Node_Id)
51    is
52    begin
53       --  We cannot tolerate aliased variables, because they might be
54       --  modified via an aliased pointer, and we could not detect that
55       --  this was happening (to update the corresponding shared memory
56       --  file), so we must disallow all use of Aliased
57
58       if Aliased_Present (N) then
59          Error_Msg_N
60            ("aliased variables " &
61             "not supported in Shared_Passive partitions",
62             N);
63
64       --  We can't support access types at all, since they are local
65       --  pointers that cannot in any simple way be transmitted to other
66       --  partitions.
67
68       elsif Is_Access_Type (T) then
69          Error_Msg_N
70            ("access type variables " &
71             "not supported in Shared_Passive partitions",
72             Id);
73
74       --  We cannot tolerate types that contain access types, same reasons
75
76       elsif Contains_Access_Type (T) then
77          Error_Msg_N
78            ("types containing access components " &
79             "not supported in Shared_Passive partitions",
80             Id);
81
82       --  Currently we do not support unconstrained record types, since we
83       --  use 'Write to write out values. This could probably be special
84       --  cased and handled in the future if necessary.
85
86       elsif Is_Record_Type (T)
87         and then not Is_Constrained (T)
88       then
89          Error_Msg_N
90            ("unconstrained variant records " &
91             "not supported in Shared_Passive partitions",
92             Id);
93       end if;
94    end Check_Shared_Var;
95
96    --------------------------
97    -- Contains_Access_Type --
98    --------------------------
99
100    function Contains_Access_Type (T : Entity_Id) return Boolean is
101       C : Entity_Id;
102
103    begin
104       if Is_Access_Type (T) then
105          return True;
106
107       elsif Is_Array_Type (T) then
108          return Contains_Access_Type (Component_Type (T));
109
110       elsif Is_Record_Type (T) then
111          if Has_Discriminants (T) then
112             C := First_Discriminant (T);
113             while Present (C) loop
114                if Comes_From_Source (C) then
115                   return True;
116                else
117                   C := Next_Discriminant (C);
118                end if;
119             end loop;
120          end if;
121
122          C := First_Component (T);
123          while Present (C) loop
124
125             --  For components, ignore internal components other than _Parent
126
127             if Comes_From_Source (T)
128               and then
129                 (Chars (C) = Name_uParent
130                   or else
131                  not Is_Internal_Name (Chars (C)))
132               and then Contains_Access_Type (Etype (C))
133             then
134                return True;
135             else
136                C := Next_Component (C);
137             end if;
138          end loop;
139
140          return False;
141
142       elsif Is_Protected_Type (T) then
143          return Contains_Access_Type (Corresponding_Record_Type (T));
144
145       else
146          return False;
147       end if;
148    end Contains_Access_Type;
149
150 end Sem_Smem;