@@ -45,6 +45,8 @@ pub struct BasicTypeDeclarationC {
45
45
pub type_qualifier : TypeQualifierC ,
46
46
/// The declaration's pointer level, i.e. `***`.
47
47
pub pointer_level : PointerLevelC ,
48
+ /// The declaration's array dimension, i.e. [][][].
49
+ pub array_dimension : ArrayDimensionC ,
48
50
/// The declaration's identifier, i.e. ident_N.
49
51
pub ident_id : String ,
50
52
}
@@ -55,6 +57,8 @@ pub struct BasicTypeDeclarationC {
55
57
pub struct StructDeclarationC {
56
58
/// The declaration's fields.
57
59
pub fields : DeclarationListC ,
60
+ /// The declaration's array dimension, i.e. [][][].
61
+ pub array_dimension : ArrayDimensionC ,
58
62
/// The declaration's identifier, i.e. struct_N.
59
63
pub ident_id : String ,
60
64
}
@@ -65,6 +69,8 @@ pub struct StructDeclarationC {
65
69
pub struct UnionDeclarationC {
66
70
/// The declaration's fields.
67
71
pub fields : DeclarationListC ,
72
+ /// The declaration's array dimension, i.e. [][][].
73
+ pub array_dimension : ArrayDimensionC ,
68
74
/// The declaration's identifier, i.e. union_N.
69
75
pub ident_id : String ,
70
76
}
@@ -147,7 +153,7 @@ pub struct DeclarationListC {
147
153
148
154
/// HeaderC is used in generation of C headers to represent a collection of
149
155
/// declarations.
150
- #[ derive( Debug , Clone ) ]
156
+ #[ derive( Clone ) ]
151
157
pub struct HeaderC {
152
158
/// The header's declarations.
153
159
pub def : DeclarationListC ,
@@ -256,7 +262,8 @@ impl Arbitrary for BaseTypeC {
256
262
"unsigned long long int" ,
257
263
"float" ,
258
264
"double" ,
259
- // "long double",
265
+ #[ cfg( feature = "long-doubles" ) ]
266
+ "long double" ,
260
267
"void*" ,
261
268
] ;
262
269
BaseTypeC {
@@ -315,10 +322,17 @@ impl Arbitrary for ArrayDimensionC {
315
322
// Keep these small, clang complains when they get too big.
316
323
let dimensions = g. gen_range ( 0 , 5 ) ;
317
324
let mut def = String :: new ( ) ;
318
- // Don't allow size 0 dimension until #684 and #1153 are closed.
319
- // 16 is an arbitrary "not too big" number for capping array size.
325
+
326
+ let lower_bound;
327
+ if cfg ! ( feature = "zero-sized-arrays" ) {
328
+ lower_bound = 0 ;
329
+ } else {
330
+ lower_bound = 1 ;
331
+ }
332
+
320
333
for _ in 1 ..dimensions {
321
- def += & format ! ( "[{}]" , g. gen_range( 1 , 16 ) ) ;
334
+ // 16 is an arbitrary "not too big" number for capping array size.
335
+ def += & format ! ( "[{}]" , g. gen_range( lower_bound, 16 ) ) ;
322
336
}
323
337
ArrayDimensionC { def }
324
338
}
@@ -347,6 +361,7 @@ impl Arbitrary for BasicTypeDeclarationC {
347
361
type_qualifier : Arbitrary :: arbitrary ( g) ,
348
362
type_name : Arbitrary :: arbitrary ( g) ,
349
363
pointer_level : Arbitrary :: arbitrary ( g) ,
364
+ array_dimension : Arbitrary :: arbitrary ( g) ,
350
365
ident_id : format ! ( "{}" , usize :: arbitrary( g) ) ,
351
366
}
352
367
}
@@ -357,11 +372,12 @@ impl fmt::Display for BasicTypeDeclarationC {
357
372
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
358
373
write ! (
359
374
f,
360
- "{} {} {} ident_{};" ,
375
+ "{} {} {} ident_{}{} ;" ,
361
376
self . type_qualifier,
362
377
self . type_name,
363
378
self . pointer_level,
364
- self . ident_id
379
+ self . ident_id,
380
+ self . array_dimension
365
381
)
366
382
}
367
383
}
@@ -398,14 +414,21 @@ impl Arbitrary for StructDeclarationC {
398
414
StructDeclarationC {
399
415
fields,
400
416
ident_id : format ! ( "{}" , usize :: arbitrary( g) ) ,
417
+ array_dimension : Arbitrary :: arbitrary ( g) ,
401
418
}
402
419
}
403
420
}
404
421
405
422
/// Enables to string and format for StructDeclarationC types.
406
423
impl fmt:: Display for StructDeclarationC {
407
424
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
408
- write ! ( f, "struct {{ {} }} struct_{};" , self . fields, self . ident_id)
425
+ write ! (
426
+ f,
427
+ "struct {{ {} }} struct_{}{};" ,
428
+ self . fields,
429
+ self . ident_id,
430
+ self . array_dimension
431
+ )
409
432
}
410
433
}
411
434
@@ -441,14 +464,21 @@ impl Arbitrary for UnionDeclarationC {
441
464
UnionDeclarationC {
442
465
fields,
443
466
ident_id : format ! ( "{}" , usize :: arbitrary( g) ) ,
467
+ array_dimension : Arbitrary :: arbitrary ( g) ,
444
468
}
445
469
}
446
470
}
447
471
448
472
/// Enables to string and format for UnionDeclarationC types.
449
473
impl fmt:: Display for UnionDeclarationC {
450
474
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
451
- write ! ( f, "union {{ {} }} union_{};" , self . fields, self . ident_id)
475
+ write ! (
476
+ f,
477
+ "union {{ {} }} union_{}{};" ,
478
+ self . fields,
479
+ self . ident_id,
480
+ self . array_dimension
481
+ )
452
482
}
453
483
}
454
484
@@ -597,3 +627,11 @@ impl fmt::Display for HeaderC {
597
627
write ! ( f, "{}" , display)
598
628
}
599
629
}
630
+
631
+ /// Use Display trait for Debug so that any failing property tests report
632
+ /// generated C code rather than the data structures that contain it.
633
+ impl fmt:: Debug for HeaderC {
634
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
635
+ write ! ( f, "{}" , self )
636
+ }
637
+ }
0 commit comments