OSDN Git Service

PR c/5420:
[pf3gnuchains/gcc-fork.git] / gcc / ch / xtypeck.c
1 /* Copyright (C) 1992, 1993, 1994, 1998 Free Software Foundation, Inc.
2
3 This file is part of GNU CC.
4
5 GNU CC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 GNU CC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU CC; see the file COPYING.  If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.  */
19
20
21 #if 0
22 tree
23 build_component_ref (datum, field_name)
24   tree datum, field_name;
25 {
26   return build_chill_component_ref (datum, field_name);
27 }
28
29 /* Mark EXP saying that we need to be able to take the
30    address of it; it should not be allocated in a register.
31    Value is 1 if successful.  */
32
33 int
34 mark_addressable (exp)
35      tree exp;
36 {
37   register tree x = exp;
38   while (1)
39     switch (TREE_CODE (x))
40       {
41       case ADDR_EXPR:
42       case COMPONENT_REF:
43       case ARRAY_REF:
44       case REALPART_EXPR:
45       case IMAGPART_EXPR:
46         x = TREE_OPERAND (x, 0);
47         break;
48
49       case CONSTRUCTOR:
50         TREE_ADDRESSABLE (x) = 1;
51         return 1;
52
53       case VAR_DECL:
54       case CONST_DECL:
55       case PARM_DECL:
56       case RESULT_DECL:
57         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
58             && DECL_NONLOCAL (x))
59           {
60             if (TREE_PUBLIC (x))
61               {
62                 error ("global register variable `%s' used in nested function",
63                        IDENTIFIER_POINTER (DECL_NAME (x)));
64                 return 0;
65               }
66             pedwarn ("register variable `%s' used in nested function",
67                      IDENTIFIER_POINTER (DECL_NAME (x)));
68           }
69         else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
70           {
71             if (TREE_PUBLIC (x))
72               {
73                 error ("address of global register variable `%s' requested",
74                        IDENTIFIER_POINTER (DECL_NAME (x)));
75                 return 0;
76               }
77
78             /* If we are making this addressable due to its having
79                volatile components, give a different error message.  Also
80                handle the case of an unnamed parameter by not trying
81                to give the name.  */
82
83             else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x)))
84               {
85                 error ("cannot put object with volatile field into register");
86                 return 0;
87               }
88
89             pedwarn ("address of register variable `%s' requested",
90                      IDENTIFIER_POINTER (DECL_NAME (x)));
91           }
92         put_var_into_stack (x);
93
94         /* drops in */
95       case FUNCTION_DECL:
96         TREE_ADDRESSABLE (x) = 1;
97 #if 0  /* poplevel deals with this now.  */
98         if (DECL_CONTEXT (x) == 0)
99           TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
100 #endif
101
102       default:
103         return 1;
104     }
105 }
106
107 /* Return an unsigned type the same as TYPE in other respects.  */
108
109 tree
110 unsigned_type (type)
111      tree type;
112 {
113   tree type1 = TYPE_MAIN_VARIANT (type);
114   if (type1 == signed_char_type_node || type1 == char_type_node)
115     return unsigned_char_type_node;
116   if (type1 == integer_type_node)
117     return unsigned_type_node;
118   if (type1 == short_integer_type_node)
119     return short_unsigned_type_node;
120   if (type1 == long_integer_type_node)
121     return long_unsigned_type_node;
122   if (type1 == long_long_integer_type_node)
123     return long_long_unsigned_type_node;
124   return type;
125 }
126
127 /* Return a signed type the same as TYPE in other respects.  */
128
129 tree
130 signed_type (type)
131      tree type;
132 {
133   tree type1 = TYPE_MAIN_VARIANT (type);
134   if (type1 == unsigned_char_type_node || type1 == char_type_node)
135     return signed_char_type_node;
136   if (type1 == unsigned_type_node)
137     return integer_type_node;
138   if (type1 == short_unsigned_type_node)
139     return short_integer_type_node;
140   if (type1 == long_unsigned_type_node)
141     return long_integer_type_node;
142   if (type1 == long_long_unsigned_type_node)
143     return long_long_integer_type_node;
144   return type;
145 }
146
147 /* Return a type the same as TYPE except unsigned or
148    signed according to UNSIGNEDP.  */
149
150 tree
151 signed_or_unsigned_type (unsignedp, type)
152      int unsignedp;
153      tree type;
154 {
155   if (! INTEGRAL_TYPE_P (type))
156     return type;
157   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
158     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
159   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
160     return unsignedp ? unsigned_type_node : integer_type_node;
161   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
162     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
163   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
164     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
165   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
166     return (unsignedp ? long_long_unsigned_type_node
167             : long_long_integer_type_node);
168   return type;
169 }
170
171 extern tree intHI_type_node;
172 extern tree intSI_type_node;
173 extern tree intDI_type_node;
174
175 extern tree unsigned_intHI_type_node;
176 extern tree unsigned_intSI_type_node;
177 extern tree unsigned_intDI_type_node;
178
179 /* Return an integer type with BITS bits of precision,
180    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
181
182 tree
183 type_for_size (bits, unsignedp)
184      unsigned bits;
185      int unsignedp;
186 {
187   if (bits == TYPE_PRECISION (signed_char_type_node))
188     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
189
190   if (bits == TYPE_PRECISION (short_integer_type_node))
191     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
192
193   if (bits == TYPE_PRECISION (integer_type_node))
194     return unsignedp ? unsigned_type_node : integer_type_node;
195
196   if (bits == TYPE_PRECISION (long_integer_type_node))
197     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
198
199   if (bits == TYPE_PRECISION (long_long_integer_type_node))
200     return (unsignedp ? long_long_unsigned_type_node
201             : long_long_integer_type_node);
202
203   if (bits <= TYPE_PRECISION (intHI_type_node))
204     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
205
206   if (bits <= TYPE_PRECISION (intSI_type_node))
207     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
208
209   if (bits <= TYPE_PRECISION (intDI_type_node))
210     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
211
212   return 0;
213 }
214
215 /* Return a data type that has machine mode MODE.
216    If the mode is an integer,
217    then UNSIGNEDP selects between signed and unsigned types.  */
218
219 tree
220 type_for_mode (mode, unsignedp)
221      enum machine_mode mode;
222      int unsignedp;
223 {
224   if (mode == TYPE_MODE (signed_char_type_node))
225     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
226
227   if (mode == TYPE_MODE (short_integer_type_node))
228     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
229
230   if (mode == TYPE_MODE (integer_type_node))
231     return unsignedp ? unsigned_type_node : integer_type_node;
232
233   if (mode == TYPE_MODE (long_integer_type_node))
234     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
235
236   if (mode == TYPE_MODE (long_long_integer_type_node))
237     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
238
239   if (mode == TYPE_MODE (intHI_type_node))
240     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
241
242   if (mode == TYPE_MODE (intSI_type_node))
243     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
244
245   if (mode == TYPE_MODE (intDI_type_node))
246     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
247
248   if (mode == TYPE_MODE (float_type_node))
249     return float_type_node;
250
251   if (mode == TYPE_MODE (double_type_node))
252     return double_type_node;
253
254   if (mode == TYPE_MODE (long_double_type_node))
255     return long_double_type_node;
256
257   if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
258     return build_pointer_type (char_type_node);
259
260   if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
261     return build_pointer_type (integer_type_node);
262
263   return 0;
264 }
265
266 tree
267 truthvalue_conversion (expr)
268      tree expr;
269 {
270   return chill_truthvalue_conversion (expr);
271 }
272 #endif