5 void ucn_constraints(unsigned long u
) {
13 yyerror("UCN values below \\u00A0 are not allowed");
14 else if(u
>= 0xD800 && u
<= 0xDFFF)
15 yyerror("UCN values in [\\uD800, \\uDFFF] are not allowed");
20 enum type_category
get_type_category(const struct declaration_specifiers
*ds
,
21 const struct declarator_type
*dt
) {
30 if(get_type_category(ds
, dt
->next
) == tc_complete
31 && (dt
->u
.array
.size
|| (dt
->u
.array
.flags
& AF_STAR
)))
37 if((ds
->type_specifiers
& TS__BASIC
) == TS_VOID
)
39 /* XXX detect incomplete struct/union types */
44 /* C99 6.7.5.3 function declarators */
45 static void check_function_return_type(const struct declarator_type
*dt
) {
46 if(dt
) switch(dt
->type
) {
48 inputerror(&dt
->where
, "function returns an array");
52 inputerror(&dt
->where
, "function returns a function");
59 int is_void_args(const struct declarator_type
*dt
) {
60 const struct declaration
*args
;
61 const struct declarator
*d
;
62 const struct declaration_specifiers
*ds
;
64 if(dt
->u
.function
.variadic
) return 0;
65 args
= dt
->u
.function
.args
;
66 if(!args
|| args
->next
) return 0;
67 d
= args
->declarator_list
;
68 if(d
->name
|| d
->declarator_type
) return 0;
69 ds
= d
->declaration_specifiers
;
70 if(ds
->storage_class_specifiers
71 || ds
->type_qualifiers
72 || ds
->type_specifiers
!= TS_VOID
)
77 static int valid_bitfield_type(const struct declaration_specifiers
*ds
,
78 const struct declarator_type
*dt
) {
80 switch(ds
->type_specifiers
) {
82 case TS_SIGNED
|TS_INT
:
83 case TS_UNSIGNED
|TS_INT
:
93 void declaration_constraints(const struct declaration
*decl
,
94 enum declarator_context context
) {
95 const struct declarator
*d
;
97 /* C99 6.7.2 need at least one type specifier */
98 if(!decl
->declaration_specifiers
->type_specifiers
)
99 inputerror(&decl
->where
, "no type specifiers in declaration");
101 for(d
= decl
->declarator_list
; d
; d
= d
->next
)
102 declarator_constraints(d
->declaration_specifiers
,
106 void declarator_constraints(const struct declaration_specifiers
*ds
,
107 const struct declarator
*d
,
108 enum declarator_context context
,
110 const struct declarator_type
*dt
= d
->declarator_type
;
111 const struct location
*declloc
= dt ?
&dt
->where
: &d
->where
;
114 case dc_function_definition
:
115 if(ds
->storage_class_specifiers
& ~(SCS_EXTERN
|SCS_STATIC
))
116 inputerror(&d
->where
, "invalid storage class specifiers for a function");
117 if(!dt
|| (dt
->type
!= dt_function
118 && dt
->type
!= dt_old_function
)) {
120 inputerror(&d
->where
,
121 "function definition of '%s' requires a function declarator",
124 inputerror(&d
->where
,
125 "function definition requires a function declarator");
129 case dc_function_definition_parameter
:
131 inputerror(declloc
, "parameter %d has no name", argno
);
132 case dc_function_parameter
:
133 if(ds
->storage_class_specifiers
& (~SCS_REGISTER
)) {
135 inputerror(&d
->where
, "parameter '%s' has invalid storage class",
138 inputerror(&d
->where
, "parameter %d has invalid storage class",
141 switch(get_type_category(ds
, dt
)) {
143 if(context
== dc_function_definition_parameter
) {
144 /* arrays of completely-typed objects are allowed */
146 && dt
->type
== dt_array
147 && get_type_category(ds
, dt
->next
) == tc_complete
)) {
149 inputerror(declloc
, "parameter '%s' has incomplete type",
151 /* if no name, will already have reported an error */
157 inputerror(declloc
, "parameter '%s' has function type", d
->name
);
159 inputerror(declloc
, "parameter %d has function type", argno
);
166 case dc_struct_member
:
168 if(!valid_bitfield_type(ds
, dt
)) {
170 inputerror(&d
->where
, "member '%s' has invalid type for a bit field");
172 inputerror(&d
->where
, "member has invalid type for a bit field");
174 /* XXX field size must be integral */
176 switch(get_type_category(ds
, dt
)) {
178 inputerror(declloc
, "member '%s' has function type", d
->name
);
182 && dt
->type
== dt_array
184 && !dt
->u
.array
.flags
)
185 inputwarning(declloc
, warn_compat
,
186 "member '%s' is a GNU C flexible array", d
->name
);
188 inputerror(declloc
, "member '%s' has incomplete type", d
->name
);
197 switch(get_type_category(ds
, dt
)) {
199 inputerror(declloc
, "cannot convert to function type");
202 if(ds
->type_specifiers
!= TS_VOID
)
203 inputerror(declloc
, "cannot convert to incomplete type");
206 switch(ds
->type_specifiers
& TS__BASIC
) {
210 /* XXX and some typedefs */
211 inputerror(declloc
, "cannot convert to aggregate type");
212 } else switch(dt
->type
) {
214 inputerror(declloc
, "cannot convert to array type");
217 case dt_old_function
:
218 inputerror(declloc
, "cannot convert to function type");
221 /* pointers are OK */
230 case dc_compound_literal
:
231 switch(get_type_category(ds
, dt
)) {
233 inputerror(declloc
, "compound literals cannot have incomplete type");
236 inputerror(declloc
, "compound literals cannot have incomplete type");
244 switch(get_type_category(ds
, dt
)) {
246 inputerror(declloc
, "cannot take size of function type");
249 inputerror(declloc
, "cannot take size of incomplete type");
260 for(dt
= d
->declarator_type
; dt
; dt
= dt
->next
) {
265 /* C99 6.7.5.2 array declarators */
268 if((dt
->storage_class_specifiers
269 || dt
->type_qualifiers
)
270 && !(dt
== d
->declarator_type
271 && (context
== dc_function_parameter
272 || context
== dc_function_definition_parameter
)))
273 inputerror(&dt
->where
, "invalid array declarator");
274 switch(get_type_category(ds
, dt
->next
)) {
278 inputerror(&dt
->where
, "array element type has function type");
281 inputerror(&dt
->where
, "array element type has incomplete type");
284 /* XXX size must have integral type */
287 /* C99 6.7.5.3 function declarators */
289 case dt_old_function
:
290 check_function_return_type(dt
->next
);
291 if(dt
->u
.old_function
.args
) {
292 if(!(dt
== d
->declarator_type
&& context
== dc_function_definition
))
293 inputerror(&dt
->where
,
294 "non-empty identifier-list in function declarator");
296 /* check for duplicates */
297 struct dict
*dict
= dict_new();
298 struct identifier_list
*i
;
300 for(i
= dt
->u
.old_function
.args
; i
; i
= i
->next
) {
301 if(dict_get(dict
, i
->id
)) {
302 inputerror(&dt
->where
, "duplicate '%s' in function parameters",
306 dict_add(dict
, i
->id
, i
->id
);
313 check_function_return_type(dt
->next
);
314 if(!is_void_args(dt
)) {
315 /* recursively check arguments */
317 const struct declaration
*a
;
319 for(a
= dt
->u
.function
.args
; a
; a
= a
->next
)
320 declarator_constraints(a
->declaration_specifiers
,
322 context
== dc_function_definition
323 ? dc_function_definition_parameter
324 : dc_function_parameter
,