2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997, 1998
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
#include "config.h"
|
|
|
32 |
#include "c_types.h"
|
|
|
33 |
#include "ctype_ops.h"
|
|
|
34 |
#include "exp_ops.h"
|
|
|
35 |
#include "id_ops.h"
|
|
|
36 |
#include "hashid_ops.h"
|
|
|
37 |
#include "member_ops.h"
|
|
|
38 |
#include "nspace_ops.h"
|
|
|
39 |
#include "tok_ops.h"
|
|
|
40 |
#include "type_ops.h"
|
|
|
41 |
#include "error.h"
|
|
|
42 |
#include "catalog.h"
|
|
|
43 |
#include "access.h"
|
|
|
44 |
#include "basetype.h"
|
|
|
45 |
#include "class.h"
|
|
|
46 |
#include "constant.h"
|
|
|
47 |
#include "construct.h"
|
|
|
48 |
#include "convert.h"
|
|
|
49 |
#include "declare.h"
|
|
|
50 |
#include "derive.h"
|
|
|
51 |
#include "dump.h"
|
|
|
52 |
#include "exception.h"
|
|
|
53 |
#include "expression.h"
|
|
|
54 |
#include "file.h"
|
|
|
55 |
#include "function.h"
|
|
|
56 |
#include "hash.h"
|
|
|
57 |
#include "identifier.h"
|
|
|
58 |
#include "initialise.h"
|
|
|
59 |
#include "instance.h"
|
|
|
60 |
#include "namespace.h"
|
|
|
61 |
#include "option.h"
|
|
|
62 |
#include "parse.h"
|
|
|
63 |
#include "predict.h"
|
|
|
64 |
#include "redeclare.h"
|
|
|
65 |
#include "syntax.h"
|
|
|
66 |
#include "template.h"
|
|
|
67 |
#include "tok.h"
|
|
|
68 |
#include "token.h"
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
/*
|
|
|
72 |
USAGE SUPPRESSION FLAG
|
|
|
73 |
|
|
|
74 |
This flag may be set to true to indicate that the parser is in a sizeof
|
|
|
75 |
expression or similar so that any usages should not be included.
|
|
|
76 |
*/
|
|
|
77 |
|
|
|
78 |
int suppress_usage = 0 ;
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
/*
|
|
|
82 |
MARK AN IDENTIFIER AS BEING USED
|
|
|
83 |
|
|
|
84 |
This routine marks the identifier id as having been used and checks
|
|
|
85 |
any access controls.
|
|
|
86 |
*/
|
|
|
87 |
|
|
|
88 |
void use_id
|
|
|
89 |
PROTO_N ( ( id, suppress ) )
|
|
|
90 |
PROTO_T ( IDENTIFIER id X int suppress )
|
|
|
91 |
{
|
|
|
92 |
DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
93 |
DECL_SPEC acc = ( ds & dspec_access ) ;
|
|
|
94 |
if ( acc ) check_access ( id, acc ) ;
|
|
|
95 |
|
|
|
96 |
/* Check usage */
|
|
|
97 |
if ( ds & dspec_main ) {
|
|
|
98 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
99 |
switch ( TAG_hashid ( nm ) ) {
|
|
|
100 |
case hashid_name_tag : {
|
|
|
101 |
/* Can't take the address of 'main' */
|
|
|
102 |
report ( crt_loc, ERR_basic_start_main_addr ( id ) ) ;
|
|
|
103 |
break ;
|
|
|
104 |
}
|
|
|
105 |
case hashid_constr_tag : {
|
|
|
106 |
/* Can't take the address of a constructor */
|
|
|
107 |
report ( crt_loc, ERR_class_ctor_addr ( id ) ) ;
|
|
|
108 |
break ;
|
|
|
109 |
}
|
|
|
110 |
case hashid_destr_tag : {
|
|
|
111 |
/* Can't take the address of a destructor */
|
|
|
112 |
report ( crt_loc, ERR_class_dtor_addr ( id ) ) ;
|
|
|
113 |
break ;
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/* Mark use */
|
|
|
119 |
if ( !( ds & dspec_used ) ) {
|
|
|
120 |
if ( !suppress ) {
|
|
|
121 |
ds |= dspec_used ;
|
|
|
122 |
COPY_dspec ( id_storage ( id ), ds ) ;
|
|
|
123 |
}
|
|
|
124 |
if ( ds & ( dspec_inherit | dspec_alias | dspec_extern ) ) {
|
|
|
125 |
/* Check for inheritance */
|
|
|
126 |
IDENTIFIER uid = DEREF_id ( id_alias ( id ) ) ;
|
|
|
127 |
if ( !EQ_id ( uid, id ) ) {
|
|
|
128 |
ds = DEREF_dspec ( id_storage ( uid ) ) ;
|
|
|
129 |
if ( ds & dspec_used ) {
|
|
|
130 |
if ( do_usage ) dump_use ( id, &crt_loc, 1 ) ;
|
|
|
131 |
return ;
|
|
|
132 |
}
|
|
|
133 |
if ( !suppress ) {
|
|
|
134 |
ds |= dspec_used ;
|
|
|
135 |
COPY_dspec ( id_storage ( uid ), ds ) ;
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
if ( !( ds & dspec_defn ) && ( ds & dspec_instance ) ) {
|
|
|
140 |
/* Define template instance */
|
|
|
141 |
if ( !suppress ) define_template ( id, 0 ) ;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
if ( do_usage ) dump_use ( id, &crt_loc, 1 ) ;
|
|
|
145 |
return ;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
/*
|
|
|
150 |
MARK A FUNCTION IDENTIFIER AS BEING USED
|
|
|
151 |
|
|
|
152 |
This routine marks the function identifier id as having been called
|
|
|
153 |
and checks any access controls. In addition certain checks are applied
|
|
|
154 |
to the first call of an identifier. expl is true for explicit calls.
|
|
|
155 |
*/
|
|
|
156 |
|
|
|
157 |
void use_func_id
|
|
|
158 |
PROTO_N ( ( id, expl, suppress ) )
|
|
|
159 |
PROTO_T ( IDENTIFIER id X int expl X int suppress )
|
|
|
160 |
{
|
|
|
161 |
DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
162 |
DECL_SPEC acc = ( ds & dspec_access ) ;
|
|
|
163 |
if ( acc ) check_access ( id, acc ) ;
|
|
|
164 |
if ( !( ds & dspec_called ) ) {
|
|
|
165 |
/* Mark use */
|
|
|
166 |
if ( !suppress ) {
|
|
|
167 |
if ( !( ds & dspec_virtual ) ) ds |= dspec_used ;
|
|
|
168 |
ds |= dspec_called ;
|
|
|
169 |
COPY_dspec ( id_storage ( id ), ds ) ;
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/* Check for inheritance */
|
|
|
173 |
if ( ds & ( dspec_inherit | dspec_alias | dspec_extern ) ) {
|
|
|
174 |
IDENTIFIER uid = DEREF_id ( id_alias ( id ) ) ;
|
|
|
175 |
if ( !EQ_id ( uid, id ) ) {
|
|
|
176 |
ds = DEREF_dspec ( id_storage ( uid ) ) ;
|
|
|
177 |
if ( ds & dspec_called ) {
|
|
|
178 |
if ( do_usage ) dump_call ( id, &crt_loc, expl ) ;
|
|
|
179 |
return ;
|
|
|
180 |
}
|
|
|
181 |
if ( !suppress ) {
|
|
|
182 |
if ( !( ds & dspec_virtual ) ) ds |= dspec_used ;
|
|
|
183 |
ds |= dspec_called ;
|
|
|
184 |
COPY_dspec ( id_storage ( uid ), ds ) ;
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/* Check usage */
|
|
|
190 |
if ( ds & dspec_main ) {
|
|
|
191 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
192 |
if ( IS_hashid_name ( nm ) ) {
|
|
|
193 |
/* Can't call 'main' */
|
|
|
194 |
report ( crt_loc, ERR_basic_start_main_call ( id ) ) ;
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
if ( !( ds & dspec_defn ) && !suppress ) {
|
|
|
198 |
if ( ds & dspec_implicit ) {
|
|
|
199 |
/* Define implicitly declared function */
|
|
|
200 |
implicit_defn ( id, DEFAULT_USR ) ;
|
|
|
201 |
ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
202 |
} else if ( ds & dspec_instance ) {
|
|
|
203 |
/* Define template function */
|
|
|
204 |
if ( !( ds & dspec_virtual ) ) {
|
|
|
205 |
define_template ( id, 0 ) ;
|
|
|
206 |
ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
if ( ( ds & dspec_inline ) && !( ds & dspec_defn ) ) {
|
|
|
210 |
/* An inline function called before it is defined */
|
|
|
211 |
report ( crt_loc, ERR_dcl_fct_spec_inline_call ( id ) ) ;
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
if ( do_usage ) dump_call ( id, &crt_loc, expl ) ;
|
|
|
216 |
return ;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
/*
|
|
|
221 |
MARK A VIRTUAL FUNCTION AS BEING USED
|
|
|
222 |
|
|
|
223 |
Note that use_func_id does not mark virtual functions as having been
|
|
|
224 |
used because the actual function called can only be determined at
|
|
|
225 |
run-time. If subsequently it is found that the function called can
|
|
|
226 |
be determined statically then this routine is called to mark that
|
|
|
227 |
function as having been used. It is also used in certain similar
|
|
|
228 |
situations.
|
|
|
229 |
*/
|
|
|
230 |
|
|
|
231 |
void reuse_id
|
|
|
232 |
PROTO_N ( ( id, suppress ) )
|
|
|
233 |
PROTO_T ( IDENTIFIER id X int suppress )
|
|
|
234 |
{
|
|
|
235 |
DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
236 |
if ( !( ds & dspec_used ) && !suppress ) {
|
|
|
237 |
ds |= dspec_used ;
|
|
|
238 |
COPY_dspec ( id_storage ( id ), ds ) ;
|
|
|
239 |
if ( !( ds & dspec_defn ) ) {
|
|
|
240 |
if ( ds & dspec_implicit ) {
|
|
|
241 |
/* Define implicitly declared function */
|
|
|
242 |
implicit_defn ( id, DEFAULT_USR ) ;
|
|
|
243 |
} else if ( ds & dspec_instance ) {
|
|
|
244 |
/* Instantiate template functions */
|
|
|
245 |
define_template ( id, 0 ) ;
|
|
|
246 |
}
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
return ;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
/*
|
|
|
254 |
DEFINE AN IDENTIFIER ALIAS
|
|
|
255 |
|
|
|
256 |
This routine is called if the function or variable id is defined
|
|
|
257 |
(excluding tentative definitions). It passes the definition on to
|
|
|
258 |
any alias of id.
|
|
|
259 |
*/
|
|
|
260 |
|
|
|
261 |
void define_id
|
|
|
262 |
PROTO_N ( ( id ) )
|
|
|
263 |
PROTO_T ( IDENTIFIER id )
|
|
|
264 |
{
|
|
|
265 |
IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
|
|
|
266 |
if ( !EQ_id ( lid, id ) ) {
|
|
|
267 |
/* Check for previous definition */
|
|
|
268 |
LOCATION loc ;
|
|
|
269 |
DECL_SPEC ds ;
|
|
|
270 |
DEREF_loc ( id_loc ( id ), loc ) ;
|
|
|
271 |
ds = DEREF_dspec ( id_storage ( lid ) ) ;
|
|
|
272 |
if ( ds & dspec_defn ) {
|
|
|
273 |
EXP e = DEREF_exp ( id_variable_etc_init ( lid ) ) ;
|
|
|
274 |
if ( IS_NULL_exp ( e ) || !IS_exp_zero ( e ) ) {
|
|
|
275 |
/* Exclude previous tentative definitions */
|
|
|
276 |
PTR ( LOCATION ) ploc = id_loc ( lid ) ;
|
|
|
277 |
ERROR err = ERR_basic_odr_def ( lid, ploc ) ;
|
|
|
278 |
if ( ds & dspec_c ) {
|
|
|
279 |
/* Explain C linkage identifications */
|
|
|
280 |
HASHID nm = DEREF_hashid ( id_name ( lid ) ) ;
|
|
|
281 |
ERROR err2 = ERR_dcl_link_redecl ( nm, ploc ) ;
|
|
|
282 |
err = concat_error ( err, err2 ) ;
|
|
|
283 |
}
|
|
|
284 |
report ( loc, err ) ;
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/* Copy definition */
|
|
|
289 |
if ( IS_id_function_etc ( id ) ) {
|
|
|
290 |
EXP e = DEREF_exp ( id_function_etc_defn ( id ) ) ;
|
|
|
291 |
COPY_exp ( id_function_etc_defn ( lid ), e ) ;
|
|
|
292 |
} else if ( IS_id_variable_etc ( id ) ) {
|
|
|
293 |
TYPE t = DEREF_type ( id_variable_etc_type ( id ) ) ;
|
|
|
294 |
EXP e = DEREF_exp ( id_variable_etc_init ( id ) ) ;
|
|
|
295 |
EXP d = DEREF_exp ( id_variable_etc_term ( id ) ) ;
|
|
|
296 |
COPY_exp ( id_variable_etc_init ( lid ), e ) ;
|
|
|
297 |
COPY_exp ( id_variable_etc_term ( lid ), d ) ;
|
|
|
298 |
COPY_type ( id_variable_etc_type ( lid ), t ) ;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
/* Record definition */
|
|
|
302 |
ds |= dspec_defn ;
|
|
|
303 |
COPY_dspec ( id_storage ( lid ), ds ) ;
|
|
|
304 |
DEREF_loc ( id_loc ( lid ), loc ) ;
|
|
|
305 |
}
|
|
|
306 |
return ;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
/*
|
|
|
311 |
FIND THE END OF A LIST OF IDENTIFIER ALIASES
|
|
|
312 |
|
|
|
313 |
In most cases the alias of an identifier is its underlying meaning,
|
|
|
314 |
however for function parameters it is possible to have vast lists
|
|
|
315 |
of identifiers arising from redeclarations all linked by their alias
|
|
|
316 |
field. This routine scans down such a list until it finds an identifier
|
|
|
317 |
which is its own alias.
|
|
|
318 |
*/
|
|
|
319 |
|
|
|
320 |
IDENTIFIER chase_alias
|
|
|
321 |
PROTO_N ( ( id ) )
|
|
|
322 |
PROTO_T ( IDENTIFIER id )
|
|
|
323 |
{
|
|
|
324 |
while ( !IS_NULL_id ( id ) ) {
|
|
|
325 |
IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
|
|
|
326 |
if ( EQ_id ( lid, id ) ) break ;
|
|
|
327 |
id = lid ;
|
|
|
328 |
}
|
|
|
329 |
return ( id ) ;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
/*
|
|
|
334 |
CURRENT IDENTIFIER QUALIFIER
|
|
|
335 |
|
|
|
336 |
This variable is set to describe how the current identifier is
|
|
|
337 |
qualified.
|
|
|
338 |
*/
|
|
|
339 |
|
|
|
340 |
QUALIFIER crt_id_qualifier = qual_none ;
|
|
|
341 |
int crt_templ_qualifier = 0 ;
|
|
|
342 |
|
|
|
343 |
|
|
|
344 |
/*
|
|
|
345 |
CHECK AN IDENTIFIER NAME
|
|
|
346 |
|
|
|
347 |
This routine checks whether the identifier name id is suitable for use
|
|
|
348 |
in the context given by loc. The namespace qualifiers used in describing
|
|
|
349 |
id will be given by crt_id_qualifier. The routine returns true for
|
|
|
350 |
legal identifiers.
|
|
|
351 |
*/
|
|
|
352 |
|
|
|
353 |
ERROR check_id_name
|
|
|
354 |
PROTO_N ( ( id, loc ) )
|
|
|
355 |
PROTO_T ( IDENTIFIER id X int loc )
|
|
|
356 |
{
|
|
|
357 |
/* Check on namespace component */
|
|
|
358 |
ERROR err = NULL_err ;
|
|
|
359 |
QUALIFIER cq = crt_id_qualifier ;
|
|
|
360 |
switch ( cq ) {
|
|
|
361 |
case qual_none : {
|
|
|
362 |
/* No namespace specifier */
|
|
|
363 |
if ( in_template_decl && is_templ_alias ( id ) ) {
|
|
|
364 |
/* Check for hiding of template parameters */
|
|
|
365 |
err = ERR_temp_local_hide ( id ) ;
|
|
|
366 |
if ( !IS_NULL_err ( err ) ) return ( err ) ;
|
|
|
367 |
}
|
|
|
368 |
if ( crt_templ_qualifier ) goto qualifier_lab ;
|
|
|
369 |
break ;
|
|
|
370 |
}
|
|
|
371 |
case qual_nested :
|
|
|
372 |
qualifier_lab : {
|
|
|
373 |
/* Nested namespace specifier */
|
|
|
374 |
if ( loc == CONTEXT_PARAMETER || loc == CONTEXT_TEMPL_PARAM ) {
|
|
|
375 |
err = ERR_dcl_meaning_id ( cq, id ) ;
|
|
|
376 |
if ( !IS_NULL_err ( err ) ) return ( err ) ;
|
|
|
377 |
}
|
|
|
378 |
break ;
|
|
|
379 |
}
|
|
|
380 |
case qual_full :
|
|
|
381 |
case qual_top : {
|
|
|
382 |
/* Namespace specifier beginning with '::' */
|
|
|
383 |
err = ERR_dcl_meaning_full ( cq, id ) ;
|
|
|
384 |
if ( !IS_NULL_err ( err ) ) return ( err ) ;
|
|
|
385 |
goto qualifier_lab ;
|
|
|
386 |
}
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
/* Check on name component */
|
|
|
390 |
if ( loc != CONTEXT_FUNCTION && loc != CONTEXT_FUNC_MEMBER ) {
|
|
|
391 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
392 |
switch ( TAG_hashid ( nm ) ) {
|
|
|
393 |
case hashid_constr_tag : {
|
|
|
394 |
/* A constructor must be a member function */
|
|
|
395 |
err = ERR_class_mem_ctor ( id ) ;
|
|
|
396 |
break ;
|
|
|
397 |
}
|
|
|
398 |
case hashid_destr_tag : {
|
|
|
399 |
/* A destructor must be a member function */
|
|
|
400 |
err = ERR_class_dtor_func ( nm ) ;
|
|
|
401 |
break ;
|
|
|
402 |
}
|
|
|
403 |
case hashid_conv_tag :
|
|
|
404 |
case hashid_op_tag : {
|
|
|
405 |
/* These must be functions */
|
|
|
406 |
err = ERR_dcl_meaning_id ( cq, id ) ;
|
|
|
407 |
break ;
|
|
|
408 |
}
|
|
|
409 |
}
|
|
|
410 |
}
|
|
|
411 |
return ( err ) ;
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
/*
|
|
|
416 |
DECLARE AN IMPLICIT FUNCTION
|
|
|
417 |
|
|
|
418 |
This routine declares a function named id in the current scope with
|
|
|
419 |
declaration specifiers ds, return type ret (which may be the null type),
|
|
|
420 |
parameter types p (terminated by the null type), and function kind ell.
|
|
|
421 |
It is used to declare implicit functions.
|
|
|
422 |
*/
|
|
|
423 |
|
|
|
424 |
IDENTIFIER declare_func
|
|
|
425 |
PROTO_N ( ( ds, id, ret, p, ell, ex ) )
|
|
|
426 |
PROTO_T ( DECL_SPEC ds X IDENTIFIER id X TYPE ret X TYPE *p X
|
|
|
427 |
int ell X LIST ( TYPE ) ex )
|
|
|
428 |
{
|
|
|
429 |
/* Save certain information */
|
|
|
430 |
TYPE t ;
|
|
|
431 |
CV_SPEC cv ;
|
|
|
432 |
DECL_SPEC acc = crt_access ;
|
|
|
433 |
int td = have_type_declaration ;
|
|
|
434 |
QUALIFIER cq = crt_id_qualifier ;
|
|
|
435 |
int tq = crt_templ_qualifier ;
|
|
|
436 |
crt_access = dspec_public ;
|
|
|
437 |
crt_id_qualifier = qual_none ;
|
|
|
438 |
crt_templ_qualifier = 0 ;
|
|
|
439 |
have_type_declaration = TYPE_DECL_NONE ;
|
|
|
440 |
|
|
|
441 |
/* Declare parameters */
|
|
|
442 |
decl_loc = crt_loc ;
|
|
|
443 |
begin_param ( id ) ;
|
|
|
444 |
while ( !IS_NULL_type ( *p ) ) {
|
|
|
445 |
HASHID nm = lookup_anon () ;
|
|
|
446 |
IDENTIFIER pid = DEREF_id ( hashid_id ( nm ) ) ;
|
|
|
447 |
pid = make_param_decl ( dspec_none, *p, pid, CONTEXT_PARAMETER ) ;
|
|
|
448 |
init_param ( pid, NULL_exp ) ;
|
|
|
449 |
p++ ;
|
|
|
450 |
}
|
|
|
451 |
if ( IS_NULL_type ( ret ) ) ret = type_inferred ;
|
|
|
452 |
cv = func_linkage ( cv_none ) ;
|
|
|
453 |
t = make_func_type ( ret, ell, cv, ex ) ;
|
|
|
454 |
end_param () ;
|
|
|
455 |
|
|
|
456 |
/* Declare the function */
|
|
|
457 |
if ( in_class_defn ) {
|
|
|
458 |
#if LANGUAGE_CPP
|
|
|
459 |
if ( ds & dspec_friend ) {
|
|
|
460 |
id = make_friend_decl ( ds, t, id, 0, 1 ) ;
|
|
|
461 |
} else {
|
|
|
462 |
id = make_func_mem_decl ( ds, t, id, 0 ) ;
|
|
|
463 |
}
|
|
|
464 |
#else
|
|
|
465 |
id = make_member_decl ( ds, t, id, 0 ) ;
|
|
|
466 |
#endif
|
|
|
467 |
} else {
|
|
|
468 |
id = make_func_decl ( ds, t, id, 0 ) ;
|
|
|
469 |
}
|
|
|
470 |
if ( do_dump ) {
|
|
|
471 |
dump_implicit = 1 ;
|
|
|
472 |
dump_declare ( id, &decl_loc, 0 ) ;
|
|
|
473 |
}
|
|
|
474 |
have_type_declaration = td ;
|
|
|
475 |
crt_templ_qualifier = tq ;
|
|
|
476 |
crt_id_qualifier = cq ;
|
|
|
477 |
crt_access = acc ;
|
|
|
478 |
return ( id ) ;
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
/*
|
|
|
483 |
IMPLICITLY DECLARE AN IDENTIFIER
|
|
|
484 |
|
|
|
485 |
This routine implicitly declares an identifier id, either as a local
|
|
|
486 |
variable, if fn is false, or as a function. fn will be 2 in the cases
|
|
|
487 |
where C allows an implicit function declaration. The routine returns
|
|
|
488 |
the corresponding identifier expression.
|
|
|
489 |
*/
|
|
|
490 |
|
|
|
491 |
EXP implicit_id_exp
|
|
|
492 |
PROTO_N ( ( id, fn ) )
|
|
|
493 |
PROTO_T ( IDENTIFIER id X int fn )
|
|
|
494 |
{
|
|
|
495 |
EXP e ;
|
|
|
496 |
ERROR err ;
|
|
|
497 |
LOCATION loc ;
|
|
|
498 |
DECL_SPEC ds ;
|
|
|
499 |
IDENTIFIER pid ;
|
|
|
500 |
DECL_SPEC cl = crt_linkage ;
|
|
|
501 |
QUALIFIER cq = crt_id_qualifier ;
|
|
|
502 |
int tq = crt_templ_qualifier ;
|
|
|
503 |
NAMESPACE cns = crt_namespace ;
|
|
|
504 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
505 |
NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
|
|
|
506 |
|
|
|
507 |
/* Check for implicit function declarations */
|
|
|
508 |
if ( fn == 2 && option ( OPT_func_impl ) == OPTION_DISALLOW ) fn = 1 ;
|
|
|
509 |
|
|
|
510 |
/* Allow for template dependent declarations */
|
|
|
511 |
if ( in_template_decl && is_templ_nspace ( cns ) ) {
|
|
|
512 |
int opt = OPT_templ_undecl ;
|
|
|
513 |
OPTION sev = option ( opt ) ;
|
|
|
514 |
if ( sev != OPTION_ALLOW ) {
|
|
|
515 |
/* Implicit declarations for dependent identifiers */
|
|
|
516 |
if ( dependent_id ( id ) ) {
|
|
|
517 |
opt = OPT_none ;
|
|
|
518 |
sev = OPTION_ALLOW ;
|
|
|
519 |
}
|
|
|
520 |
}
|
|
|
521 |
if ( sev != OPTION_DISALLOW ) {
|
|
|
522 |
if ( sev != OPTION_ALLOW && fn != 2 ) {
|
|
|
523 |
if ( cq == qual_none ) {
|
|
|
524 |
err = ERR_lookup_unqual_undef ( nm ) ;
|
|
|
525 |
} else {
|
|
|
526 |
err = ERR_lookup_qual_undef ( nm, ns ) ;
|
|
|
527 |
}
|
|
|
528 |
err = set_severity ( err, opt, 0 ) ;
|
|
|
529 |
report ( crt_loc, err ) ;
|
|
|
530 |
}
|
|
|
531 |
MAKE_exp_undeclared ( type_templ_param, id, cq, e ) ;
|
|
|
532 |
return ( e ) ;
|
|
|
533 |
}
|
|
|
534 |
if ( cq == qual_none ) ns = NULL_nspace ;
|
|
|
535 |
}
|
|
|
536 |
|
|
|
537 |
/* Check for previous declaration */
|
|
|
538 |
if ( IS_NULL_nspace ( ns ) ) {
|
|
|
539 |
OPTION sev = option ( OPT_decl_unify ) ;
|
|
|
540 |
if ( sev != OPTION_OFF ) {
|
|
|
541 |
LIST ( IDENTIFIER ) p ;
|
|
|
542 |
NAMESPACE pns = nonblock_namespace ;
|
|
|
543 |
p = DEREF_list ( nspace_named_etc_extra ( pns ) ) ;
|
|
|
544 |
pid = unify_extern ( id, NULL_type, pns, p ) ;
|
|
|
545 |
if ( !IS_NULL_id ( pid ) ) {
|
|
|
546 |
if ( sev != OPTION_ON ) {
|
|
|
547 |
err = ERR_lookup_unqual_vis ( pid ) ;
|
|
|
548 |
err = set_severity ( err, OPT_decl_unify, 0 ) ;
|
|
|
549 |
report ( crt_loc, err ) ;
|
|
|
550 |
}
|
|
|
551 |
e = make_id_exp ( pid ) ;
|
|
|
552 |
return ( e ) ;
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
ns = cns ;
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
/* Rescan identifier */
|
|
|
559 |
pid = search_id ( ns, nm, 0, 0 ) ;
|
|
|
560 |
if ( !IS_NULL_id ( pid ) ) {
|
|
|
561 |
switch ( TAG_id ( pid ) ) {
|
|
|
562 |
case id_variable_tag :
|
|
|
563 |
case id_function_tag : {
|
|
|
564 |
e = make_id_exp ( pid ) ;
|
|
|
565 |
return ( e ) ;
|
|
|
566 |
}
|
|
|
567 |
}
|
|
|
568 |
}
|
|
|
569 |
|
|
|
570 |
/* Find namespace for declaration */
|
|
|
571 |
crt_linkage = dspec_c ;
|
|
|
572 |
crt_id_qualifier = qual_none ;
|
|
|
573 |
crt_templ_qualifier = 0 ;
|
|
|
574 |
push_namespace ( ns ) ;
|
|
|
575 |
bad_crt_loc++ ;
|
|
|
576 |
loc = crt_loc ;
|
|
|
577 |
if ( crt_state_depth == 0 ) {
|
|
|
578 |
/* Find identifier location */
|
|
|
579 |
IDENTIFIER uid = underlying_id ( id ) ;
|
|
|
580 |
DEREF_loc ( id_loc ( uid ), crt_loc ) ;
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
if ( fn ) {
|
|
|
584 |
/* Implicit functions declarations */
|
|
|
585 |
int ell ;
|
|
|
586 |
TYPE ret = type_sint ;
|
|
|
587 |
TYPE pars = NULL_type ;
|
|
|
588 |
#if LANGUAGE_CPP
|
|
|
589 |
/* Type is 'int ( ... )' in C++ */
|
|
|
590 |
ell = FUNC_ELLIPSIS ;
|
|
|
591 |
if ( fn == 1 ) ret = type_error ;
|
|
|
592 |
#else
|
|
|
593 |
/* Type is 'int ()' in C */
|
|
|
594 |
ell = FUNC_NO_PARAMS ;
|
|
|
595 |
#endif
|
|
|
596 |
ds = ( dspec_extern | dspec_ignore ) ;
|
|
|
597 |
id = declare_func ( ds, id, ret, &pars, ell, empty_type_set ) ;
|
|
|
598 |
|
|
|
599 |
} else {
|
|
|
600 |
/* Other implicit declarations */
|
|
|
601 |
decl_loc = crt_loc ;
|
|
|
602 |
id = make_object_decl ( dspec_none, type_error, id, 0 ) ;
|
|
|
603 |
IGNORE init_object ( id, NULL_exp ) ;
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
/* Report error */
|
|
|
607 |
crt_linkage = cl ;
|
|
|
608 |
crt_templ_qualifier = tq ;
|
|
|
609 |
crt_id_qualifier = cq ;
|
|
|
610 |
if ( fn == 2 ) {
|
|
|
611 |
pid = DEREF_id ( id_alias ( id ) ) ;
|
|
|
612 |
ds = DEREF_dspec ( id_storage ( pid ) ) ;
|
|
|
613 |
if ( ds & dspec_temp ) {
|
|
|
614 |
/* Implicit declaration already reported */
|
|
|
615 |
err = NULL_err ;
|
|
|
616 |
} else {
|
|
|
617 |
err = ERR_expr_call_undecl ( id ) ;
|
|
|
618 |
if ( !IS_NULL_err ( err ) ) {
|
|
|
619 |
ds |= dspec_temp ;
|
|
|
620 |
COPY_dspec ( id_storage ( pid ), ds ) ;
|
|
|
621 |
}
|
|
|
622 |
}
|
|
|
623 |
} else if ( cq == qual_none ) {
|
|
|
624 |
err = ERR_lookup_unqual_undef ( nm ) ;
|
|
|
625 |
} else {
|
|
|
626 |
err = ERR_lookup_qual_undef ( nm, ns ) ;
|
|
|
627 |
}
|
|
|
628 |
report ( crt_loc, err ) ;
|
|
|
629 |
|
|
|
630 |
/* Construct the result */
|
|
|
631 |
crt_loc = loc ;
|
|
|
632 |
bad_crt_loc-- ;
|
|
|
633 |
IGNORE pop_namespace () ;
|
|
|
634 |
e = make_id_exp ( id ) ;
|
|
|
635 |
return ( e ) ;
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
|
|
|
639 |
/*
|
|
|
640 |
LIST OF MEANINGS
|
|
|
641 |
|
|
|
642 |
This list is built up by list_ambiguous to give all the meanings of
|
|
|
643 |
its ambiguous identifier which match its type argument.
|
|
|
644 |
*/
|
|
|
645 |
|
|
|
646 |
static LIST ( IDENTIFIER ) ambig_meanings = NULL_list ( IDENTIFIER ) ;
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
/*
|
|
|
650 |
LIST MEANINGS OF AN AMBIGUOUS IDENTIFIER
|
|
|
651 |
|
|
|
652 |
This routine adds all meanings of the ambiguous identifier id to the
|
|
|
653 |
error list err.
|
|
|
654 |
*/
|
|
|
655 |
|
|
|
656 |
static unsigned list_ambiguous
|
|
|
657 |
PROTO_N ( ( id, n, err, type, rec ) )
|
|
|
658 |
PROTO_T ( IDENTIFIER id X unsigned n X ERROR *err X int type X int rec )
|
|
|
659 |
{
|
|
|
660 |
if ( !IS_NULL_id ( id ) ) {
|
|
|
661 |
switch ( TAG_id ( id ) ) {
|
|
|
662 |
case id_ambig_tag : {
|
|
|
663 |
/* Ambiguous identifiers */
|
|
|
664 |
LIST ( IDENTIFIER ) p = DEREF_list ( id_ambig_ids ( id ) ) ;
|
|
|
665 |
rec = DEREF_int ( id_ambig_over ( id ) ) ;
|
|
|
666 |
while ( !IS_NULL_list ( p ) ) {
|
|
|
667 |
id = DEREF_id ( HEAD_list ( p ) ) ;
|
|
|
668 |
n = list_ambiguous ( id, n, err, type, rec ) ;
|
|
|
669 |
p = TAIL_list ( p ) ;
|
|
|
670 |
}
|
|
|
671 |
break ;
|
|
|
672 |
}
|
|
|
673 |
case id_function_tag :
|
|
|
674 |
case id_mem_func_tag :
|
|
|
675 |
case id_stat_mem_func_tag : {
|
|
|
676 |
/* Functions */
|
|
|
677 |
if ( rec ) {
|
|
|
678 |
IDENTIFIER over ;
|
|
|
679 |
over = DEREF_id ( id_function_etc_over ( id ) ) ;
|
|
|
680 |
n = list_ambiguous ( over, n, err, type, rec ) ;
|
|
|
681 |
}
|
|
|
682 |
goto default_lab ;
|
|
|
683 |
}
|
|
|
684 |
case id_class_name_tag :
|
|
|
685 |
case id_class_alias_tag :
|
|
|
686 |
case id_enum_name_tag :
|
|
|
687 |
case id_enum_alias_tag :
|
|
|
688 |
case id_type_alias_tag : {
|
|
|
689 |
/* Types */
|
|
|
690 |
type = 0 ;
|
|
|
691 |
goto default_lab ;
|
|
|
692 |
}
|
|
|
693 |
default :
|
|
|
694 |
default_lab : {
|
|
|
695 |
/* Other identifiers */
|
|
|
696 |
PTR ( LOCATION ) loc = id_loc ( id ) ;
|
|
|
697 |
n++ ;
|
|
|
698 |
add_error ( err, ERR_fail_list_item ( n, id, loc ) ) ;
|
|
|
699 |
break ;
|
|
|
700 |
}
|
|
|
701 |
}
|
|
|
702 |
if ( type == 0 ) {
|
|
|
703 |
/* Add to list of meanings */
|
|
|
704 |
CONS_id ( id, ambig_meanings, ambig_meanings ) ;
|
|
|
705 |
}
|
|
|
706 |
}
|
|
|
707 |
return ( n ) ;
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
|
|
|
711 |
/*
|
|
|
712 |
REPORT AN AMBIGUOUS IDENTIFIER
|
|
|
713 |
|
|
|
714 |
This routine reports the identifier id as being ambiguous. Overloaded
|
|
|
715 |
functions count as a single identifier unless rec is true. It returns
|
|
|
716 |
one of the possible meanings. Only types are considered if type is
|
|
|
717 |
true. If there is exactly one possible meaning or force is true the
|
|
|
718 |
first meaning is returned. Otherwise the null identifier is returned.
|
|
|
719 |
*/
|
|
|
720 |
|
|
|
721 |
IDENTIFIER report_ambiguous
|
|
|
722 |
PROTO_N ( ( id, type, rec, force ) )
|
|
|
723 |
PROTO_T ( IDENTIFIER id X int type X int rec X int force )
|
|
|
724 |
{
|
|
|
725 |
ERROR err, err2 ;
|
|
|
726 |
LIST ( IDENTIFIER ) p ;
|
|
|
727 |
NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
|
|
|
728 |
|
|
|
729 |
/* List all meanings */
|
|
|
730 |
if ( !IS_NULL_nspace ( ns ) && IS_nspace_ctype ( ns ) ) {
|
|
|
731 |
err = ERR_lookup_ambig_mem ( id ) ;
|
|
|
732 |
} else {
|
|
|
733 |
err = ERR_lookup_ambig_id ( id ) ;
|
|
|
734 |
}
|
|
|
735 |
err2 = ERR_lookup_ambig_list () ;
|
|
|
736 |
if ( !IS_NULL_err ( err2 ) ) {
|
|
|
737 |
unsigned n = 0 ;
|
|
|
738 |
err = concat_error ( err, err2 ) ;
|
|
|
739 |
n = list_ambiguous ( id, n, &err, type, rec ) ;
|
|
|
740 |
err = concat_error ( err, ERR_fail_list_end ( n ) ) ;
|
|
|
741 |
}
|
|
|
742 |
report ( crt_loc, err ) ;
|
|
|
743 |
|
|
|
744 |
/* Check for resolved meaning */
|
|
|
745 |
id = NULL_id ;
|
|
|
746 |
p = ambig_meanings ;
|
|
|
747 |
if ( !IS_NULL_list ( p ) ) {
|
|
|
748 |
if ( IS_NULL_list ( TAIL_list ( p ) ) || force ) {
|
|
|
749 |
id = DEREF_id ( HEAD_list ( p ) ) ;
|
|
|
750 |
}
|
|
|
751 |
DESTROY_list ( p, SIZE_id ) ;
|
|
|
752 |
ambig_meanings = NULL_list ( IDENTIFIER ) ;
|
|
|
753 |
}
|
|
|
754 |
return ( id ) ;
|
|
|
755 |
}
|
|
|
756 |
|
|
|
757 |
|
|
|
758 |
/*
|
|
|
759 |
FIND THE DECLARATION SPECIFIER FOR AN AMBIGUOUS IDENTIFIER
|
|
|
760 |
|
|
|
761 |
This routine finds the declaration specifier for an ambiguous identifier
|
|
|
762 |
given by the list of cases pids. This consists of various properties
|
|
|
763 |
which all the cases share.
|
|
|
764 |
*/
|
|
|
765 |
|
|
|
766 |
DECL_SPEC find_ambig_dspec
|
|
|
767 |
PROTO_N ( ( pids ) )
|
|
|
768 |
PROTO_T ( LIST ( IDENTIFIER ) pids )
|
|
|
769 |
{
|
|
|
770 |
DECL_SPEC ds = ( dspec_implicit | dspec_template ) ;
|
|
|
771 |
while ( !IS_NULL_list ( pids ) ) {
|
|
|
772 |
IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
|
|
|
773 |
if ( !IS_NULL_id ( pid ) ) {
|
|
|
774 |
DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
|
|
|
775 |
ds &= pds ;
|
|
|
776 |
}
|
|
|
777 |
pids = TAIL_list ( pids ) ;
|
|
|
778 |
}
|
|
|
779 |
return ( ds ) ;
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
|
|
|
783 |
/*
|
|
|
784 |
CREATE AN IDENTIFIER EXPRESSION
|
|
|
785 |
|
|
|
786 |
This routine creates an expression corresponding to the identifier id.
|
|
|
787 |
Note that static member functions are identifier expressions if they
|
|
|
788 |
are not overloaded, but member expression otherwise. They are sorted
|
|
|
789 |
out properly during overload resolution (see resolve_cast).
|
|
|
790 |
*/
|
|
|
791 |
|
|
|
792 |
EXP make_id_exp
|
|
|
793 |
PROTO_N ( ( id ) )
|
|
|
794 |
PROTO_T ( IDENTIFIER id )
|
|
|
795 |
{
|
|
|
796 |
EXP e ;
|
|
|
797 |
unsigned tag = TAG_id ( id ) ;
|
|
|
798 |
QUALIFIER cq = crt_id_qualifier ;
|
|
|
799 |
switch ( tag ) {
|
|
|
800 |
|
|
|
801 |
case id_variable_tag :
|
|
|
802 |
case id_parameter_tag : {
|
|
|
803 |
/* Variables and parameters */
|
|
|
804 |
TYPE t ;
|
|
|
805 |
DECL_SPEC ds ;
|
|
|
806 |
use_id ( id, 0 ) ;
|
|
|
807 |
ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
808 |
if ( ds & dspec_auto ) {
|
|
|
809 |
/* Check use of automatic variable */
|
|
|
810 |
NAMESPACE ns = crt_namespace ;
|
|
|
811 |
switch ( TAG_nspace ( ns ) ) {
|
|
|
812 |
case nspace_block_tag :
|
|
|
813 |
case nspace_dummy_tag : {
|
|
|
814 |
if ( really_in_function_defn > 1 ) {
|
|
|
815 |
/* Used in nested function */
|
|
|
816 |
IDENTIFIER fid ;
|
|
|
817 |
ns = DEREF_nspace ( id_parent ( id ) ) ;
|
|
|
818 |
fid = DEREF_id ( nspace_name ( ns ) ) ;
|
|
|
819 |
if ( !EQ_id ( fid, crt_func_id ) ) {
|
|
|
820 |
ERROR err = ERR_class_local_auto ( id ) ;
|
|
|
821 |
report ( crt_loc, err ) ;
|
|
|
822 |
}
|
|
|
823 |
}
|
|
|
824 |
break ;
|
|
|
825 |
}
|
|
|
826 |
case nspace_param_tag :
|
|
|
827 |
case nspace_templ_tag : {
|
|
|
828 |
/* Used in default argument */
|
|
|
829 |
if ( in_default_arg ) {
|
|
|
830 |
ERROR err = ERR_dcl_fct_default_param ( id ) ;
|
|
|
831 |
report ( crt_loc, err ) ;
|
|
|
832 |
}
|
|
|
833 |
break ;
|
|
|
834 |
}
|
|
|
835 |
default : {
|
|
|
836 |
/* Used in local class */
|
|
|
837 |
ERROR err = ERR_class_local_auto ( id ) ;
|
|
|
838 |
report ( crt_loc, err ) ;
|
|
|
839 |
break ;
|
|
|
840 |
}
|
|
|
841 |
}
|
|
|
842 |
}
|
|
|
843 |
t = DEREF_type ( id_variable_etc_type ( id ) ) ;
|
|
|
844 |
if ( ( ds & dspec_extern ) && cv_extern ) {
|
|
|
845 |
CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
|
|
|
846 |
t = qualify_type ( t, ( cv | cv_extern ), 0 ) ;
|
|
|
847 |
used_extern_volatile = 1 ;
|
|
|
848 |
}
|
|
|
849 |
MAKE_exp_identifier ( t, id, cq, e ) ;
|
|
|
850 |
break ;
|
|
|
851 |
}
|
|
|
852 |
|
|
|
853 |
case id_stat_member_tag : {
|
|
|
854 |
/* Static data members */
|
|
|
855 |
TYPE t ;
|
|
|
856 |
DECL_SPEC ds ;
|
|
|
857 |
use_id ( id, suppress_usage ) ;
|
|
|
858 |
ds = DEREF_dspec ( id_storage ( id ) ) ;
|
|
|
859 |
if ( ds & dspec_inherit ) id = DEREF_id ( id_alias ( id ) ) ;
|
|
|
860 |
t = DEREF_type ( id_stat_member_type ( id ) ) ;
|
|
|
861 |
if ( ( ds & dspec_extern ) && cv_extern ) {
|
|
|
862 |
CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
|
|
|
863 |
t = qualify_type ( t, ( cv | cv_extern ), 0 ) ;
|
|
|
864 |
used_extern_volatile = 1 ;
|
|
|
865 |
}
|
|
|
866 |
MAKE_exp_identifier ( t, id, cq, e ) ;
|
|
|
867 |
break ;
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
case id_function_tag : {
|
|
|
871 |
/* Normal functions */
|
|
|
872 |
TYPE t = DEREF_type ( id_function_type ( id ) ) ;
|
|
|
873 |
MAKE_exp_identifier ( t, id, cq, e ) ;
|
|
|
874 |
break ;
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
case id_stat_mem_func_tag : {
|
|
|
878 |
/* Static member functions */
|
|
|
879 |
TYPE t = DEREF_type ( id_stat_mem_func_type ( id ) ) ;
|
|
|
880 |
IDENTIFIER over = DEREF_id ( id_stat_mem_func_over ( id ) ) ;
|
|
|
881 |
if ( IS_NULL_id ( over ) ) {
|
|
|
882 |
MAKE_exp_identifier ( t, id, cq, e ) ;
|
|
|
883 |
} else {
|
|
|
884 |
MAKE_exp_member ( t, id, cq, e ) ;
|
|
|
885 |
}
|
|
|
886 |
break ;
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
case id_mem_func_tag : {
|
|
|
890 |
/* Non-static member functions */
|
|
|
891 |
TYPE t = DEREF_type ( id_mem_func_type ( id ) ) ;
|
|
|
892 |
MAKE_exp_member ( t, id, cq, e ) ;
|
|
|
893 |
break ;
|
|
|
894 |
}
|
|
|
895 |
|
|
|
896 |
case id_member_tag : {
|
|
|
897 |
/* Non-static members */
|
|
|
898 |
TYPE t = DEREF_type ( id_member_type ( id ) ) ;
|
|
|
899 |
MAKE_exp_member ( t, id, cq, e ) ;
|
|
|
900 |
break ;
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
case id_enumerator_tag : {
|
|
|
904 |
/* Enumerators */
|
|
|
905 |
NAT n ;
|
|
|
906 |
TYPE t ;
|
|
|
907 |
use_id ( id, 0 ) ;
|
|
|
908 |
e = DEREF_exp ( id_enumerator_value ( id ) ) ;
|
|
|
909 |
DECONS_exp_int_lit ( t, n, tag, e ) ;
|
|
|
910 |
MAKE_exp_int_lit ( t, n, tag, e ) ;
|
|
|
911 |
break ;
|
|
|
912 |
}
|
|
|
913 |
|
|
|
914 |
case id_token_tag : {
|
|
|
915 |
/* Tokens */
|
|
|
916 |
TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
|
|
|
917 |
switch ( TAG_tok ( tok ) ) {
|
|
|
918 |
case tok_exp_tag :
|
|
|
919 |
case tok_nat_tag :
|
|
|
920 |
case tok_snat_tag :
|
|
|
921 |
case tok_stmt_tag : {
|
|
|
922 |
/* Expression tokens */
|
|
|
923 |
use_id ( id, 0 ) ;
|
|
|
924 |
id = DEREF_id ( id_token_alt ( id ) ) ;
|
|
|
925 |
e = apply_exp_token ( id, NULL_list ( TOKEN ), 0 ) ;
|
|
|
926 |
break ;
|
|
|
927 |
}
|
|
|
928 |
default : {
|
|
|
929 |
/* Other tokens */
|
|
|
930 |
goto default_lab ;
|
|
|
931 |
}
|
|
|
932 |
}
|
|
|
933 |
break ;
|
|
|
934 |
}
|
|
|
935 |
|
|
|
936 |
case id_class_name_tag :
|
|
|
937 |
case id_enum_name_tag :
|
|
|
938 |
case id_class_alias_tag :
|
|
|
939 |
case id_enum_alias_tag :
|
|
|
940 |
case id_type_alias_tag : {
|
|
|
941 |
/* Type names */
|
|
|
942 |
TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
|
|
|
943 |
report ( crt_loc, ERR_expr_prim_type ( id ) ) ;
|
|
|
944 |
MAKE_exp_value ( t, e ) ;
|
|
|
945 |
break ;
|
|
|
946 |
}
|
|
|
947 |
|
|
|
948 |
case id_ambig_tag : {
|
|
|
949 |
/* Ambiguous identifiers */
|
|
|
950 |
MAKE_exp_ambiguous ( type_error, id, cq, e ) ;
|
|
|
951 |
break ;
|
|
|
952 |
}
|
|
|
953 |
|
|
|
954 |
default :
|
|
|
955 |
default_lab : {
|
|
|
956 |
/* Undefined identifiers */
|
|
|
957 |
if ( cq == qual_none && in_template_decl ) {
|
|
|
958 |
/* Create a dummy identifier */
|
|
|
959 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
960 |
NAMESPACE ns = nonblock_namespace ;
|
|
|
961 |
MAKE_id_undef ( nm, dspec_none, ns, crt_loc, id ) ;
|
|
|
962 |
}
|
|
|
963 |
MAKE_exp_undeclared ( type_error, id, cq, e ) ;
|
|
|
964 |
break ;
|
|
|
965 |
}
|
|
|
966 |
}
|
|
|
967 |
return ( e ) ;
|
|
|
968 |
}
|
|
|
969 |
|
|
|
970 |
|
|
|
971 |
/*
|
|
|
972 |
FIND THE THIS PARAMETER OF A FUNCTION
|
|
|
973 |
|
|
|
974 |
This routine returns the 'this' parameter of the member function fn.
|
|
|
975 |
If use is true then the parameter is marked as used.
|
|
|
976 |
*/
|
|
|
977 |
|
|
|
978 |
IDENTIFIER this_param
|
|
|
979 |
PROTO_N ( ( fn, use ) )
|
|
|
980 |
PROTO_T ( IDENTIFIER fn X int use )
|
|
|
981 |
{
|
|
|
982 |
NAMESPACE ns ;
|
|
|
983 |
IDENTIFIER pid ;
|
|
|
984 |
HASHID nm = KEYWORD ( lex_this_Hname ) ;
|
|
|
985 |
TYPE t = DEREF_type ( id_mem_func_type ( fn ) ) ;
|
|
|
986 |
while ( IS_type_templ ( t ) ) {
|
|
|
987 |
t = DEREF_type ( type_templ_defn ( t ) ) ;
|
|
|
988 |
}
|
|
|
989 |
ns = DEREF_nspace ( type_func_pars ( t ) ) ;
|
|
|
990 |
pid = search_id ( ns, nm, 0, 0 ) ;
|
|
|
991 |
if ( !IS_NULL_id ( pid ) && use ) {
|
|
|
992 |
/* Mark parameter as used */
|
|
|
993 |
DECL_SPEC ds = DEREF_dspec ( id_storage ( pid ) ) ;
|
|
|
994 |
ds |= dspec_used ;
|
|
|
995 |
COPY_dspec ( id_storage ( pid ), ds ) ;
|
|
|
996 |
}
|
|
|
997 |
return ( pid ) ;
|
|
|
998 |
}
|
|
|
999 |
|
|
|
1000 |
|
|
|
1001 |
/*
|
|
|
1002 |
CREATE A THIS EXPRESSION
|
|
|
1003 |
|
|
|
1004 |
This routine deals with the 'this' expression. This is only in scope
|
|
|
1005 |
in the definition of a non-static member function. Note that the
|
|
|
1006 |
current value of 'this' is given by the address of the dummy parameter
|
|
|
1007 |
with name given by lex_this_Hname.
|
|
|
1008 |
*/
|
|
|
1009 |
|
|
|
1010 |
EXP make_this_exp
|
|
|
1011 |
PROTO_Z ()
|
|
|
1012 |
{
|
|
|
1013 |
EXP e ;
|
|
|
1014 |
TYPE t ;
|
|
|
1015 |
IDENTIFIER fn = crt_func_id ;
|
|
|
1016 |
if ( in_function_defn && IS_id_mem_func ( fn ) ) {
|
|
|
1017 |
/* The current value of 'this' is returned */
|
|
|
1018 |
IDENTIFIER pid = this_param ( fn, 1 ) ;
|
|
|
1019 |
if ( in_default_arg ) {
|
|
|
1020 |
/* Can't use 'this' in default argument */
|
|
|
1021 |
ERROR err = ERR_dcl_fct_default_param ( pid ) ;
|
|
|
1022 |
report ( crt_loc, err ) ;
|
|
|
1023 |
}
|
|
|
1024 |
e = DEREF_exp ( id_parameter_init ( pid ) ) ;
|
|
|
1025 |
t = DEREF_type ( exp_type ( e ) ) ;
|
|
|
1026 |
MAKE_exp_copy ( t, e, e ) ;
|
|
|
1027 |
} else {
|
|
|
1028 |
/* Must be inside a non-static member function */
|
|
|
1029 |
report ( crt_loc, ERR_expr_prim_this () ) ;
|
|
|
1030 |
e = make_error_exp ( 0 ) ;
|
|
|
1031 |
}
|
|
|
1032 |
return ( e ) ;
|
|
|
1033 |
}
|
|
|
1034 |
|
|
|
1035 |
|
|
|
1036 |
/*
|
|
|
1037 |
CREATE A THIS EXPRESSION
|
|
|
1038 |
|
|
|
1039 |
This routine creates an expression corresponding to the 'this' parameter
|
|
|
1040 |
of a member function. The parent class namespace is assigned to pns.
|
|
|
1041 |
The null expression is returned if we are outside of a member function.
|
|
|
1042 |
*/
|
|
|
1043 |
|
|
|
1044 |
EXP make_this_ref
|
|
|
1045 |
PROTO_N ( ( pns ) )
|
|
|
1046 |
PROTO_T ( NAMESPACE *pns )
|
|
|
1047 |
{
|
|
|
1048 |
IDENTIFIER fn = crt_func_id ;
|
|
|
1049 |
if ( in_function_defn && IS_id_mem_func ( fn ) ) {
|
|
|
1050 |
EXP e ;
|
|
|
1051 |
IDENTIFIER pid = this_param ( fn, 1 ) ;
|
|
|
1052 |
TYPE t = DEREF_type ( id_parameter_type ( pid ) ) ;
|
|
|
1053 |
MAKE_exp_identifier ( t, pid, qual_none, e ) ;
|
|
|
1054 |
*pns = DEREF_nspace ( id_parent ( fn ) ) ;
|
|
|
1055 |
return ( e ) ;
|
|
|
1056 |
}
|
|
|
1057 |
return ( NULL_exp ) ;
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
|
|
|
1061 |
/*
|
|
|
1062 |
DECLARE A THIS PARAMETER
|
|
|
1063 |
|
|
|
1064 |
This routine declares the dummy extra parameter for the non-static
|
|
|
1065 |
member function given by the identifier fn. The type of this parameter
|
|
|
1066 |
is the first element of the corresponding mtypes list (see
|
|
|
1067 |
member_func_type). An expression giving the address of the parameter
|
|
|
1068 |
is stored in its default argument position. This gives the value of
|
|
|
1069 |
the 'this' expression.
|
|
|
1070 |
*/
|
|
|
1071 |
|
|
|
1072 |
EXP make_this_decl
|
|
|
1073 |
PROTO_N ( ( fn ) )
|
|
|
1074 |
PROTO_T ( IDENTIFIER fn )
|
|
|
1075 |
{
|
|
|
1076 |
/* Look up identifier */
|
|
|
1077 |
EXP e ;
|
|
|
1078 |
TYPE t ;
|
|
|
1079 |
IDENTIFIER pid ;
|
|
|
1080 |
LIST ( TYPE ) mtypes ;
|
|
|
1081 |
NAMESPACE ns = crt_namespace ;
|
|
|
1082 |
HASHID nm = KEYWORD ( lex_this_Hname ) ;
|
|
|
1083 |
MEMBER mem = search_member ( ns, nm, 1 ) ;
|
|
|
1084 |
IDENTIFIER qid = DEREF_id ( member_id ( mem ) ) ;
|
|
|
1085 |
DECL_SPEC ds = ( dspec_auto | dspec_defn | dspec_implicit ) ;
|
|
|
1086 |
|
|
|
1087 |
/* Construct the type of the parameter */
|
|
|
1088 |
TYPE f = DEREF_type ( id_mem_func_type ( fn ) ) ;
|
|
|
1089 |
while ( IS_type_templ ( f ) ) {
|
|
|
1090 |
f = DEREF_type ( type_templ_defn ( f ) ) ;
|
|
|
1091 |
}
|
|
|
1092 |
mtypes = DEREF_list ( type_func_mtypes ( f ) ) ;
|
|
|
1093 |
t = DEREF_type ( HEAD_list ( mtypes ) ) ;
|
|
|
1094 |
|
|
|
1095 |
/* Declare parameter */
|
|
|
1096 |
MAKE_id_parameter ( nm, ds, ns, crt_loc, t, pid ) ;
|
|
|
1097 |
if ( !IS_NULL_id ( qid ) ) {
|
|
|
1098 |
qid = DEREF_id ( id_alias ( qid ) ) ;
|
|
|
1099 |
COPY_id ( id_alias ( pid ), qid ) ;
|
|
|
1100 |
}
|
|
|
1101 |
COPY_id ( hashid_cache ( nm ), pid ) ;
|
|
|
1102 |
COPY_id ( member_id ( mem ), pid ) ;
|
|
|
1103 |
|
|
|
1104 |
/* Construct the 'this' expression */
|
|
|
1105 |
t = DEREF_type ( type_ref_sub ( t ) ) ;
|
|
|
1106 |
t = rvalue_type ( t ) ;
|
|
|
1107 |
if ( option ( OPT_this_lvalue ) == OPTION_ALLOW ) {
|
|
|
1108 |
MAKE_type_ptr ( cv_lvalue, t, t ) ;
|
|
|
1109 |
MAKE_exp_identifier ( t, pid, qual_none, e ) ;
|
|
|
1110 |
} else {
|
|
|
1111 |
MAKE_type_ptr ( cv_none, t, t ) ;
|
|
|
1112 |
MAKE_exp_identifier ( t, pid, qual_none, e ) ;
|
|
|
1113 |
MAKE_exp_contents ( t, e, e ) ;
|
|
|
1114 |
}
|
|
|
1115 |
COPY_exp ( id_parameter_init ( pid ), e ) ;
|
|
|
1116 |
return ( e ) ;
|
|
|
1117 |
}
|
|
|
1118 |
|
|
|
1119 |
|
|
|
1120 |
/*
|
|
|
1121 |
CHECK FOR THIS EXPRESSIONS
|
|
|
1122 |
|
|
|
1123 |
This routine checks whether the expression e is a 'this' expression.
|
|
|
1124 |
*/
|
|
|
1125 |
|
|
|
1126 |
int is_this_exp
|
|
|
1127 |
PROTO_N ( ( e ) )
|
|
|
1128 |
PROTO_T ( EXP e )
|
|
|
1129 |
{
|
|
|
1130 |
if ( !IS_NULL_exp ( e ) ) {
|
|
|
1131 |
unsigned tag = TAG_exp ( e ) ;
|
|
|
1132 |
if ( tag == exp_indir_tag ) {
|
|
|
1133 |
e = DEREF_exp ( exp_indir_ptr ( e ) ) ;
|
|
|
1134 |
tag = TAG_exp ( e ) ;
|
|
|
1135 |
}
|
|
|
1136 |
if ( tag == exp_copy_tag ) {
|
|
|
1137 |
e = DEREF_exp ( exp_copy_arg ( e ) ) ;
|
|
|
1138 |
tag = TAG_exp ( e ) ;
|
|
|
1139 |
}
|
|
|
1140 |
if ( tag == exp_contents_tag ) {
|
|
|
1141 |
e = DEREF_exp ( exp_contents_ptr ( e ) ) ;
|
|
|
1142 |
tag = TAG_exp ( e ) ;
|
|
|
1143 |
}
|
|
|
1144 |
if ( tag == exp_copy_tag ) {
|
|
|
1145 |
e = DEREF_exp ( exp_copy_arg ( e ) ) ;
|
|
|
1146 |
tag = TAG_exp ( e ) ;
|
|
|
1147 |
}
|
|
|
1148 |
if ( tag == exp_identifier_tag ) {
|
|
|
1149 |
IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
|
|
|
1150 |
HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
|
|
|
1151 |
if ( EQ_KEYWORD ( nm, lex_this_Hname ) ) return ( 1 ) ;
|
|
|
1152 |
}
|
|
|
1153 |
}
|
|
|
1154 |
return ( 0 ) ;
|
|
|
1155 |
}
|
|
|
1156 |
|
|
|
1157 |
|
|
|
1158 |
/*
|
|
|
1159 |
FIND THE ELLIPSIS PARAMETER OF A FUNCTION
|
|
|
1160 |
|
|
|
1161 |
This routine returns the ellipsis parameter of the function fn.
|
|
|
1162 |
*/
|
|
|
1163 |
|
|
|
1164 |
IDENTIFIER ellipsis_param
|
|
|
1165 |
PROTO_N ( ( fn ) )
|
|
|
1166 |
PROTO_T ( IDENTIFIER fn )
|
|
|
1167 |
{
|
|
|
1168 |
int ell ;
|
|
|
1169 |
TYPE t = DEREF_type ( id_function_etc_type ( fn ) ) ;
|
|
|
1170 |
while ( IS_type_templ ( t ) ) {
|
|
|
1171 |
t = DEREF_type ( type_templ_defn ( t ) ) ;
|
|
|
1172 |
}
|
|
|
1173 |
ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
|
|
|
1174 |
if ( ell & FUNC_ELLIPSIS ) {
|
|
|
1175 |
HASHID nm = KEYWORD ( lex_ellipsis_Hexp ) ;
|
|
|
1176 |
NAMESPACE ns = DEREF_nspace ( type_func_pars ( t ) ) ;
|
|
|
1177 |
IDENTIFIER pid = search_id ( ns, nm, 0, 0 ) ;
|
|
|
1178 |
return ( pid ) ;
|
|
|
1179 |
}
|
|
|
1180 |
return ( NULL_id ) ;
|
|
|
1181 |
}
|
|
|
1182 |
|
|
|
1183 |
|
|
|
1184 |
/*
|
|
|
1185 |
FIND ELLIPSIS TYPE
|
|
|
1186 |
|
|
|
1187 |
This routine returns the type of the dummy ellipsis parameter. If
|
|
|
1188 |
force is true then an error is reported if this type has not been
|
|
|
1189 |
declared.
|
|
|
1190 |
*/
|
|
|
1191 |
|
|
|
1192 |
static TYPE find_ellipsis_type
|
|
|
1193 |
PROTO_N ( ( force ) )
|
|
|
1194 |
PROTO_T ( int force )
|
|
|
1195 |
{
|
|
|
1196 |
TYPE t = type_ellipsis ;
|
|
|
1197 |
if ( IS_NULL_type ( t ) ) {
|
|
|
1198 |
/* Look up token if not already defined */
|
|
|
1199 |
IDENTIFIER tid = get_special ( TOK_va_t, 1 ) ;
|
|
|
1200 |
if ( !IS_NULL_id ( tid ) && IS_id_token ( tid ) ) {
|
|
|
1201 |
tid = DEREF_id ( id_token_alt ( tid ) ) ;
|
|
|
1202 |
if ( IS_id_class_name_etc ( tid ) ) {
|
|
|
1203 |
t = DEREF_type ( id_class_name_etc_defn ( tid ) ) ;
|
|
|
1204 |
type_ellipsis = t ;
|
|
|
1205 |
}
|
|
|
1206 |
}
|
|
|
1207 |
if ( IS_NULL_type ( t ) ) {
|
|
|
1208 |
if ( force ) {
|
|
|
1209 |
/* Report if ellipsis type is undefined */
|
|
|
1210 |
HASHID nm = KEYWORD ( lex_ellipsis_Hexp ) ;
|
|
|
1211 |
report ( crt_loc, ERR_lib_builtin ( NULL_string, nm ) ) ;
|
|
|
1212 |
}
|
|
|
1213 |
t = type_error ;
|
|
|
1214 |
}
|
|
|
1215 |
}
|
|
|
1216 |
return ( t ) ;
|
|
|
1217 |
}
|
|
|
1218 |
|
|
|
1219 |
|
|
|
1220 |
/*
|
|
|
1221 |
DECLARE AN ELLIPSIS PARAMETER
|
|
|
1222 |
|
|
|
1223 |
This routine declares the dummy extra parameter representing the
|
|
|
1224 |
ellipsis component of the function id.
|
|
|
1225 |
*/
|
|
|
1226 |
|
|
|
1227 |
void make_ellipsis_decl
|
|
|
1228 |
PROTO_Z ()
|
|
|
1229 |
{
|
|
|
1230 |
IDENTIFIER pid ;
|
|
|
1231 |
NAMESPACE ns = crt_namespace ;
|
|
|
1232 |
TYPE t = find_ellipsis_type ( 0 ) ;
|
|
|
1233 |
HASHID nm = KEYWORD ( lex_ellipsis_Hexp ) ;
|
|
|
1234 |
MEMBER mem = search_member ( ns, nm, 1 ) ;
|
|
|
1235 |
IDENTIFIER qid = DEREF_id ( member_id ( mem ) ) ;
|
|
|
1236 |
DECL_SPEC ds = ( dspec_auto | dspec_defn | dspec_implicit ) ;
|
|
|
1237 |
MAKE_id_parameter ( nm, ds, ns, crt_loc, t, pid ) ;
|
|
|
1238 |
if ( !IS_NULL_id ( qid ) ) {
|
|
|
1239 |
qid = DEREF_id ( id_alias ( qid ) ) ;
|
|
|
1240 |
COPY_id ( id_alias ( pid ), qid ) ;
|
|
|
1241 |
}
|
|
|
1242 |
COPY_id ( hashid_cache ( nm ), pid ) ;
|
|
|
1243 |
COPY_id ( member_id ( mem ), pid ) ;
|
|
|
1244 |
return ;
|
|
|
1245 |
}
|
|
|
1246 |
|
|
|
1247 |
|
|
|
1248 |
/*
|
|
|
1249 |
CREATE AN ELLIPSIS EXPRESSION
|
|
|
1250 |
|
|
|
1251 |
This routine creates an expression corresponding to the ellipsis
|
|
|
1252 |
expression '...'. This can only be used in a function definition
|
|
|
1253 |
which has an ellipsis type, in which case it is an rvalue of type
|
|
|
1254 |
type_ellipsis.
|
|
|
1255 |
*/
|
|
|
1256 |
|
|
|
1257 |
EXP make_ellipsis_exp
|
|
|
1258 |
PROTO_Z ()
|
|
|
1259 |
{
|
|
|
1260 |
EXP e ;
|
|
|
1261 |
if ( in_function_defn ) {
|
|
|
1262 |
IDENTIFIER pid = ellipsis_param ( crt_func_id ) ;
|
|
|
1263 |
if ( !IS_NULL_id ( pid ) ) {
|
|
|
1264 |
/* Form result */
|
|
|
1265 |
TYPE t = find_ellipsis_type ( 1 ) ;
|
|
|
1266 |
report ( crt_loc, ERR_expr_call_ell_exp () ) ;
|
|
|
1267 |
MAKE_exp_identifier ( t, pid, qual_none, e ) ;
|
|
|
1268 |
return ( e ) ;
|
|
|
1269 |
}
|
|
|
1270 |
}
|
|
|
1271 |
report ( crt_loc, ERR_expr_call_ell_func () ) ;
|
|
|
1272 |
e = make_error_exp ( 0 ) ;
|
|
|
1273 |
return ( e ) ;
|
|
|
1274 |
}
|