* config/arm/elf.h (ASM_OUTPUT_ALIGNED_COMMON): Remove definition.
[official-gcc.git] / gcc / ada / sem_mech.adb
blobfb58aebc232ebf49a3923da81c3a7ea80490d7a7
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ M E C H --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1996-2002 Free Software Foundation, Inc. --
10 -- --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Einfo; use Einfo;
29 with Errout; use Errout;
30 with Targparm; use Targparm;
31 with Nlists; use Nlists;
32 with Sem; use Sem;
33 with Sem_Util; use Sem_Util;
34 with Sinfo; use Sinfo;
35 with Snames; use Snames;
36 with Stand; use Stand;
38 package body Sem_Mech is
40 -------------------------
41 -- Set_Mechanism_Value --
42 -------------------------
44 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
45 Class : Node_Id;
46 Param : Node_Id;
48 procedure Bad_Class;
49 -- Signal bad descriptor class name
51 procedure Bad_Mechanism;
52 -- Signal bad mechanism name
54 procedure Bad_Class is
55 begin
56 Error_Msg_N ("unrecognized descriptor class name", Class);
57 end Bad_Class;
59 procedure Bad_Mechanism is
60 begin
61 Error_Msg_N ("unrecognized mechanism name", Mech_Name);
62 end Bad_Mechanism;
64 -- Start of processing for Set_Mechanism_Value
66 begin
67 if Mechanism (Ent) /= Default_Mechanism then
68 Error_Msg_NE
69 ("mechanism for & has already been set", Mech_Name, Ent);
70 end if;
72 -- MECHANISM_NAME ::= value | reference | descriptor
74 if Nkind (Mech_Name) = N_Identifier then
75 if Chars (Mech_Name) = Name_Value then
76 Set_Mechanism_With_Checks (Ent, By_Copy, Mech_Name);
77 return;
79 elsif Chars (Mech_Name) = Name_Reference then
80 Set_Mechanism_With_Checks (Ent, By_Reference, Mech_Name);
81 return;
83 elsif Chars (Mech_Name) = Name_Descriptor then
84 Check_VMS (Mech_Name);
85 Set_Mechanism_With_Checks (Ent, By_Descriptor, Mech_Name);
86 return;
88 elsif Chars (Mech_Name) = Name_Copy then
89 Error_Msg_N
90 ("bad mechanism name, Value assumed", Mech_Name);
91 Set_Mechanism (Ent, By_Copy);
93 else
94 Bad_Mechanism;
95 return;
96 end if;
98 -- MECHANISM_NAME ::= descriptor (CLASS_NAME)
99 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
101 -- Note: this form is parsed as an indexed component
103 elsif Nkind (Mech_Name) = N_Indexed_Component then
104 Class := First (Expressions (Mech_Name));
106 if Nkind (Prefix (Mech_Name)) /= N_Identifier
107 or else Chars (Prefix (Mech_Name)) /= Name_Descriptor
108 or else Present (Next (Class))
109 then
110 Bad_Mechanism;
111 return;
112 end if;
114 -- MECHANISM_NAME ::= descriptor (Class => CLASS_NAME)
115 -- CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
117 -- Note: this form is parsed as a function call
119 elsif Nkind (Mech_Name) = N_Function_Call then
121 Param := First (Parameter_Associations (Mech_Name));
123 if Nkind (Name (Mech_Name)) /= N_Identifier
124 or else Chars (Name (Mech_Name)) /= Name_Descriptor
125 or else Present (Next (Param))
126 or else No (Selector_Name (Param))
127 or else Chars (Selector_Name (Param)) /= Name_Class
128 then
129 Bad_Mechanism;
130 return;
131 else
132 Class := Explicit_Actual_Parameter (Param);
133 end if;
135 else
136 Bad_Mechanism;
137 return;
138 end if;
140 -- Fall through here with Class set to descriptor class name
142 Check_VMS (Mech_Name);
144 if Nkind (Class) /= N_Identifier then
145 Bad_Class;
146 return;
148 elsif Chars (Class) = Name_UBS then
149 Set_Mechanism_With_Checks (Ent, By_Descriptor_UBS, Mech_Name);
151 elsif Chars (Class) = Name_UBSB then
152 Set_Mechanism_With_Checks (Ent, By_Descriptor_UBSB, Mech_Name);
154 elsif Chars (Class) = Name_UBA then
155 Set_Mechanism_With_Checks (Ent, By_Descriptor_UBA, Mech_Name);
157 elsif Chars (Class) = Name_S then
158 Set_Mechanism_With_Checks (Ent, By_Descriptor_S, Mech_Name);
160 elsif Chars (Class) = Name_SB then
161 Set_Mechanism_With_Checks (Ent, By_Descriptor_SB, Mech_Name);
163 elsif Chars (Class) = Name_A then
164 Set_Mechanism_With_Checks (Ent, By_Descriptor_A, Mech_Name);
166 elsif Chars (Class) = Name_NCA then
167 Set_Mechanism_With_Checks (Ent, By_Descriptor_NCA, Mech_Name);
169 else
170 Bad_Class;
171 return;
172 end if;
174 end Set_Mechanism_Value;
176 -------------------------------
177 -- Set_Mechanism_With_Checks --
178 -------------------------------
180 procedure Set_Mechanism_With_Checks
181 (Ent : Entity_Id;
182 Mech : Mechanism_Type;
183 Enod : Node_Id)
185 begin
186 -- Right now we only do some checks for functions returning arguments
187 -- by desctiptor. Probably mode checks need to be added here ???
189 if Mech in Descriptor_Codes and then not Is_Formal (Ent) then
190 if Is_Record_Type (Etype (Ent)) then
191 Error_Msg_N ("?records cannot be returned by Descriptor", Enod);
192 return;
193 end if;
194 end if;
196 -- If we fall through, all checks have passed
198 Set_Mechanism (Ent, Mech);
199 end Set_Mechanism_With_Checks;
201 --------------------
202 -- Set_Mechanisms --
203 --------------------
205 procedure Set_Mechanisms (E : Entity_Id) is
206 Formal : Entity_Id;
207 Typ : Entity_Id;
209 begin
210 -- Skip this processing if inside a generic template. Not only is
211 -- it uneccessary (since neither extra formals nor mechanisms are
212 -- relevant for the template itself), but at least at the moment,
213 -- procedures get frozen early inside a template so attempting to
214 -- look at the formal types does not work too well if they are
215 -- private types that have not been frozen yet.
217 if Inside_A_Generic then
218 return;
219 end if;
221 -- Loop through formals
223 Formal := First_Formal (E);
224 while Present (Formal) loop
226 if Mechanism (Formal) = Default_Mechanism then
227 Typ := Underlying_Type (Etype (Formal));
229 -- If there is no underlying type, then skip this processing and
230 -- leave the convention set to Default_Mechanism. It seems odd
231 -- that there should ever be such cases but there are (see
232 -- comments for filed regression tests 1418-001 and 1912-009) ???
234 if No (Typ) then
235 goto Skip_Formal;
236 end if;
238 case Convention (E) is
240 ---------
241 -- Ada --
242 ---------
244 -- Note: all RM defined conventions are treated the same
245 -- from the point of view of parameter passing mechanims
247 when Convention_Ada |
248 Convention_Intrinsic |
249 Convention_Entry |
250 Convention_Protected |
251 Convention_Stubbed =>
253 -- By reference types are passed by reference (RM 6.2(4))
255 if Is_By_Reference_Type (Typ) then
256 Set_Mechanism (Formal, By_Reference);
258 -- By copy types are passed by copy (RM 6.2(3))
260 elsif Is_By_Copy_Type (Typ) then
261 Set_Mechanism (Formal, By_Copy);
263 -- All other types we leave the Default_Mechanism set, so
264 -- that the backend can choose the appropriate method.
266 else
267 null;
268 end if;
270 -------
271 -- C --
272 -------
274 -- Note: Assembler, C++, Java, Stdcall also use C conventions
276 when Convention_Assembler |
277 Convention_C |
278 Convention_CPP |
279 Convention_Java |
280 Convention_Stdcall =>
282 -- The following values are passed by copy
284 -- IN Scalar parameters (RM B.3(66))
285 -- IN parameters of access types (RM B.3(67))
286 -- Access parameters (RM B.3(68))
287 -- Access to subprogram types (RM B.3(71))
289 -- Note: in the case of access parameters, it is the
290 -- pointer that is passed by value. In GNAT access
291 -- parameters are treated as IN parameters of an
292 -- anonymous access type, so this falls out free.
294 -- The bottom line is that all IN elementary types
295 -- are passed by copy in GNAT.
297 if Is_Elementary_Type (Typ) then
298 if Ekind (Formal) = E_In_Parameter then
299 Set_Mechanism (Formal, By_Copy);
301 -- OUT and IN OUT parameters of elementary types are
302 -- passed by reference (RM B.3(68)). Note that we are
303 -- not following the advice to pass the address of a
304 -- copy to preserve by copy semantics.
306 else
307 Set_Mechanism (Formal, By_Reference);
308 end if;
310 -- Records are normally passed by reference (RM B.3(69)).
311 -- However, this can be overridden by the use of the
312 -- C_Pass_By_Copy pragma or C_Pass_By_Copy convention.
314 elsif Is_Record_Type (Typ) then
316 -- If the record is not convention C, then we always
317 -- pass by reference, C_Pass_By_Copy does not apply.
319 if Convention (Typ) /= Convention_C then
320 Set_Mechanism (Formal, By_Reference);
322 -- If convention C_Pass_By_Copy was specified for
323 -- the record type, then we pass by copy.
325 elsif C_Pass_By_Copy (Typ) then
326 Set_Mechanism (Formal, By_Copy);
328 -- Otherwise, for a C convention record, we set the
329 -- convention in accordance with a possible use of
330 -- the C_Pass_By_Copy pragma. Note that the value of
331 -- Default_C_Record_Mechanism in the absence of such
332 -- a pragma is By_Reference.
334 else
335 Set_Mechanism (Formal, Default_C_Record_Mechanism);
336 end if;
338 -- Array types are passed by reference (B.3 (71))
340 elsif Is_Array_Type (Typ) then
341 Set_Mechanism (Formal, By_Reference);
343 -- For all other types, use Default_Mechanism mechanism
345 else
346 null;
347 end if;
349 -----------
350 -- COBOL --
351 -----------
353 when Convention_COBOL =>
355 -- Access parameters (which in GNAT look like IN parameters
356 -- of an access type) are passed by copy (RM B.4(96)) as
357 -- are all other IN parameters of scalar type (RM B.4(97)).
359 -- For now we pass these parameters by reference as well.
360 -- The RM specifies the intent BY_CONTENT, but gigi does
361 -- not currently transform By_Copy properly. If we pass by
362 -- reference, it will be imperative to introduce copies ???
364 if Is_Elementary_Type (Typ)
365 and then Ekind (Formal) = E_In_Parameter
366 then
367 Set_Mechanism (Formal, By_Reference);
369 -- All other parameters (i.e. all non-scalar types, and
370 -- all OUT or IN OUT parameters) are passed by reference.
371 -- Note that at the moment we are not bothering to make
372 -- copies of scalar types as recommended in the RM.
374 else
375 Set_Mechanism (Formal, By_Reference);
376 end if;
378 -------------
379 -- Fortran --
380 -------------
382 when Convention_Fortran =>
384 -- In OpenVMS, pass a character of array of character
385 -- value using Descriptor(S).
387 if OpenVMS_On_Target
388 and then (Root_Type (Typ) = Standard_Character
389 or else
390 (Is_Array_Type (Typ)
391 and then
392 Root_Type (Component_Type (Typ)) =
393 Standard_Character))
394 then
395 Set_Mechanism (Formal, By_Descriptor_S);
397 -- Access types are passed by default (presumably this
398 -- will mean they are passed by copy)
400 elsif Is_Access_Type (Typ) then
401 null;
403 -- For now, we pass all other parameters by reference.
404 -- It is not clear that this is right in the long run,
405 -- but it seems to correspond to what gnu f77 wants.
407 else
408 Set_Mechanism (Formal, By_Reference);
409 end if;
411 end case;
412 end if;
414 <<Skip_Formal>> -- remove this when problem above is fixed ???
416 Next_Formal (Formal);
417 end loop;
419 -- Now deal with return type, we always leave the default mechanism
420 -- set except for the case of returning a By_Reference type for an
421 -- Ada convention, where we force return by reference
423 if Ekind (E) = E_Function
424 and then Mechanism (E) = Default_Mechanism
425 and then not Has_Foreign_Convention (E)
426 and then Is_By_Reference_Type (Etype (E))
427 then
428 Set_Mechanism (E, By_Reference);
429 end if;
431 end Set_Mechanisms;
433 end Sem_Mech;