@@ -173,20 +173,6 @@ impl<'c> Translation<'c> {
173
173
CTypeKind :: ConstantArray ( ty, n) => {
174
174
// Convert all of the provided initializer values
175
175
176
- // Need to check to see if the next item is a string literal,
177
- // if it is need to treat it as a declaration, rather than
178
- // an init list. https://github.com/GaloisInc/C2Rust/issues/40
179
- let mut is_string = false ;
180
-
181
- if ids. len ( ) == 1 {
182
- let v = ids. first ( ) . unwrap ( ) ;
183
- if let CExprKind :: Literal ( _, CLiteral :: String { .. } ) =
184
- self . ast_context . index ( * v) . kind
185
- {
186
- is_string = true ;
187
- }
188
- }
189
-
190
176
let to_array_element = |id : & CExprId | -> TranslationResult < _ > {
191
177
self . convert_expr ( ctx. used ( ) , * id) ?. result_map ( |x| {
192
178
// Array literals require all of their elements to be
@@ -208,38 +194,42 @@ impl<'c> Translation<'c> {
208
194
} )
209
195
} ;
210
196
211
- if is_string {
212
- let v = ids. first ( ) . unwrap ( ) ;
213
- self . convert_expr ( ctx. used ( ) , * v)
214
- } else {
215
- match ids {
216
- [ ] => {
217
- // this was likely a C array of the form `int x[16] = {}`,
218
- // we'll emit that as [0; 16].
219
- let len = mk ( ) . lit_expr ( mk ( ) . int_unsuffixed_lit ( n as u128 ) ) ;
220
- Ok ( self
221
- . implicit_default_expr ( ty, ctx. is_static ) ?
222
- . map ( |default_value| mk ( ) . repeat_expr ( default_value, len) ) )
223
- }
224
- [ single] => {
197
+ match ids {
198
+ [ ] => {
199
+ // this was likely a C array of the form `int x[16] = {}`,
200
+ // we'll emit that as [0; 16].
201
+ let len = mk ( ) . lit_expr ( mk ( ) . int_unsuffixed_lit ( n as u128 ) ) ;
202
+ Ok ( self
203
+ . implicit_default_expr ( ty, ctx. is_static ) ?
204
+ . map ( |default_value| mk ( ) . repeat_expr ( default_value, len) ) )
205
+ }
206
+ [ single] => {
207
+ // Need to check to see if the next item is a string literal,
208
+ // if it is need to treat it as a declaration, rather than
209
+ // an init list. https://github.com/GaloisInc/C2Rust/issues/40
210
+ if let CExprKind :: Literal ( _, CLiteral :: String { .. } ) =
211
+ self . ast_context . index ( * single) . kind
212
+ {
213
+ self . convert_expr ( ctx. used ( ) , * single)
214
+ } else {
225
215
// this was likely a C array of the form `int x[16] = { default }`,
226
216
// we'll emit that as [default; 16].
227
217
let len = mk ( ) . lit_expr ( mk ( ) . int_unsuffixed_lit ( n as u128 ) ) ;
228
218
Ok ( to_array_element ( single) ?
229
219
. map ( |default_value| mk ( ) . repeat_expr ( default_value, len) ) )
230
220
}
231
- [ .. ] => {
232
- Ok ( ids
233
- . iter ( )
234
- . map ( to_array_element )
235
- . chain (
236
- // Pad out the array literal with default values to the desired size
237
- iter :: repeat ( self . implicit_default_expr ( ty , ctx . is_static ) )
238
- . take ( n - ids . len ( ) ) ,
239
- )
240
- . collect :: < TranslationResult < WithStmts < _ > > > ( ) ?
241
- . map ( |vals| mk ( ) . array_expr ( vals ) ) )
242
- }
221
+ }
222
+ [ .. ] => {
223
+ Ok ( ids
224
+ . iter ( )
225
+ . map ( to_array_element )
226
+ . chain (
227
+ // Pad out the array literal with default values to the desired size
228
+ iter :: repeat ( self . implicit_default_expr ( ty , ctx . is_static ) )
229
+ . take ( n - ids . len ( ) ) ,
230
+ )
231
+ . collect :: < TranslationResult < WithStmts < _ > > > ( ) ?
232
+ . map ( |vals| mk ( ) . array_expr ( vals ) ) )
243
233
}
244
234
}
245
235
}
0 commit comments