@@ -114,6 +114,9 @@ pub enum Literal {
114114 ty : Type ,
115115 value : Box < Literal > ,
116116 } ,
117+ Array {
118+ items : Vec < Literal > ,
119+ } ,
117120}
118121
119122impl Literal {
@@ -182,13 +185,19 @@ impl Literal {
182185 }
183186 }
184187 }
188+ Literal :: Array { ref mut items } => {
189+ for item in items {
190+ item. replace_self_with ( self_ty) ;
191+ }
192+ }
185193 Literal :: Expr ( ..) => { }
186194 }
187195 }
188196
189197 fn is_valid ( & self , bindings : & Bindings ) -> bool {
190198 match * self {
191199 Literal :: Expr ( ..) => true ,
200+ Literal :: Array { ref items } => items. iter ( ) . all ( |i| i. is_valid ( bindings) ) ,
192201 Literal :: Path {
193202 ref associated_to,
194203 ref name,
@@ -228,6 +237,14 @@ impl Literal {
228237 ref right,
229238 ..
230239 } => left. visit ( visitor) && right. visit ( visitor) ,
240+ Literal :: Array { ref items } => {
241+ for item in items {
242+ if !item. visit ( visitor) {
243+ return false ;
244+ }
245+ }
246+ true
247+ }
231248 Literal :: FieldAccess { ref base, .. } => base. visit ( visitor) ,
232249 Literal :: Struct { ref fields, .. } => {
233250 for ( _name, field) in fields. iter ( ) {
@@ -305,6 +322,11 @@ impl Literal {
305322 left. rename_for_config ( config) ;
306323 right. rename_for_config ( config) ;
307324 }
325+ Literal :: Array { ref mut items } => {
326+ for item in items {
327+ item. rename_for_config ( config) ;
328+ }
329+ }
308330 Literal :: Expr ( _) => { }
309331 Literal :: Cast {
310332 ref mut ty,
@@ -506,6 +528,14 @@ impl Literal {
506528 }
507529 }
508530
531+ syn:: Expr :: Array ( syn:: ExprArray { ref elems, .. } ) => {
532+ let mut items = vec ! [ ] ;
533+ for elem in elems {
534+ items. push ( Self :: load ( elem) ?) ;
535+ }
536+ Ok ( Literal :: Array { items } )
537+ }
538+
509539 _ => Err ( format ! ( "Unsupported expression. {:?}" , * expr) ) ,
510540 }
511541 }
@@ -665,8 +695,14 @@ impl Constant {
665695 } else {
666696 out. write ( "static const " ) ;
667697 }
668- language_backend. write_type ( out, & self . ty ) ;
669- write ! ( out, " {};" , self . export_name( ) ) ;
698+ crate :: bindgen:: cdecl:: write_field (
699+ language_backend,
700+ out,
701+ & self . ty ,
702+ self . export_name ( ) ,
703+ config,
704+ ) ;
705+ write ! ( out, ";" ) ;
670706 condition. write_after ( config, out) ;
671707 }
672708
@@ -759,9 +795,8 @@ impl Constant {
759795 } else {
760796 out. write ( "const " ) ;
761797 }
762-
763- language_backend. write_type ( out, & self . ty ) ;
764- write ! ( out, " {name} = " ) ;
798+ crate :: bindgen:: cdecl:: write_field ( language_backend, out, & self . ty , & name, config) ;
799+ write ! ( out, " = " ) ;
765800 language_backend. write_literal ( out, value) ;
766801 write ! ( out, ";" ) ;
767802 }
@@ -771,10 +806,10 @@ impl Constant {
771806 }
772807 Language :: Cython => {
773808 out. write ( "const " ) ;
774- language_backend. write_type ( out, & self . ty ) ;
775809 // For extern Cython declarations the initializer is ignored,
776810 // but still useful as documentation, so we write it as a comment.
777- write ! ( out, " {name} # = " ) ;
811+ crate :: bindgen:: cdecl:: write_field ( language_backend, out, & self . ty , & name, config) ;
812+ write ! ( out, " # = " ) ;
778813 language_backend. write_literal ( out, value) ;
779814 }
780815 }
0 commit comments