@@ -5,7 +5,7 @@ use syn::Expr;
55use crate :: c_ast:: CUnOp ;
66use crate :: {
77 diagnostics:: TranslationResult ,
8- translator:: { signed_int_expr, ConvertedDecl , EnumMode , ExprContext , Translation } ,
8+ translator:: { signed_int_expr, ConvertedDecl , ExprContext , Translation } ,
99 with_stmts:: WithStmts ,
1010 CDeclKind , CEnumConstantId , CEnumId , CExprId , CExprKind , CLiteral , CQualTypeId , CTypeKind ,
1111 ConstIntExpr ,
@@ -24,21 +24,13 @@ impl<'c> Translation<'c> {
2424 . resolve_decl_name ( enum_id)
2525 . expect ( "Enums should already be renamed" ) ;
2626 let integral_type_rs = self . convert_type ( integral_type. ctype ) ?;
27- let item = match self . tcfg . enum_mode {
28- EnumMode :: NewType => {
29- let field = mk ( ) . pub_ ( ) . enum_field ( integral_type_rs) ;
30- mk ( ) . span ( span)
31- . call_attr ( "derive" , vec ! [ "Clone" , "Copy" ] )
32- . call_attr ( "repr" , vec ! [ "transparent" ] )
33- . pub_ ( )
34- . struct_item ( enum_name, vec ! [ field] , true )
35- }
36-
37- EnumMode :: Consts => mk ( )
38- . span ( span)
39- . pub_ ( )
40- . type_item ( enum_name, integral_type_rs) ,
41- } ;
27+ let field = mk ( ) . pub_ ( ) . enum_field ( integral_type_rs) ;
28+ let item = mk ( )
29+ . span ( span)
30+ . call_attr ( "derive" , vec ! [ "Clone" , "Copy" ] )
31+ . call_attr ( "repr" , vec ! [ "transparent" ] )
32+ . pub_ ( )
33+ . struct_item ( enum_name, vec ! [ field] , true ) ;
4234
4335 Ok ( ConvertedDecl :: Item ( item) )
4436 }
@@ -99,11 +91,8 @@ impl<'c> Translation<'c> {
9991 target_cty : CQualTypeId ,
10092 mut val : Box < Expr > ,
10193 ) -> TranslationResult < WithStmts < Box < Expr > > > {
102- match self . tcfg . enum_mode {
103- // First extract the enum's inner type...
104- EnumMode :: NewType => val = self . integer_from_enum ( val) ,
105- EnumMode :: Consts => { }
106- }
94+ // First extract the enum's inner type...
95+ val = self . integer_from_enum ( val) ;
10796
10897 // Cast from the enum's integral type to the expected integral type.
10998 let source_cty = self . enum_integral_type ( enum_id) ;
@@ -120,10 +109,7 @@ impl<'c> Translation<'c> {
120109
121110 /// Gets the inner integral value of an enum value.
122111 pub fn integer_from_enum ( & self , val : Box < Expr > ) -> Box < Expr > {
123- match self . tcfg . enum_mode {
124- EnumMode :: NewType => mk ( ) . anon_field_expr ( val, 0 ) ,
125- EnumMode :: Consts => val,
126- }
112+ mk ( ) . anon_field_expr ( val, 0 )
127113 }
128114
129115 /// Translates a cast where the target type is an `enum` type.
@@ -181,35 +167,15 @@ impl<'c> Translation<'c> {
181167 return Ok ( WithStmts :: new_val ( val) ) ;
182168 }
183169
184- match self . tcfg . enum_mode {
185- // Enum-to-enum casts need to be translated via the inner value as an intermediate.
186- EnumMode :: NewType => val = self . integer_from_enum ( val) ,
187- EnumMode :: Consts => { }
188- }
189-
170+ // Enum-to-enum casts need to be translated via the inner value as an intermediate.
171+ val = self . integer_from_enum ( val) ;
190172 source_cty = self . enum_integral_type ( source_enum_id) ;
191173 }
192174
193175 let enum_integral_type = self . enum_integral_type ( enum_id) ;
194176 let mut val = WithStmts :: new_val ( val) ;
195-
196- match self . tcfg . enum_mode {
197- EnumMode :: NewType => {
198- val =
199- self . convert_cast ( ctx, source_cty, enum_integral_type, val, None , None , None ) ?;
200- val = val. map ( |val| self . enum_constructor_expr ( enum_id, val) ) ;
201- }
202-
203- EnumMode :: Consts => {
204- let source_type_kind = & self . ast_context . resolve_type ( source_cty. ctype ) . kind ;
205- let enum_integral_type_kind =
206- & self . ast_context . resolve_type ( enum_integral_type. ctype ) . kind ;
207-
208- if source_type_kind != enum_integral_type_kind {
209- val = val. map ( |val| self . enum_constructor_expr ( enum_id, val) ) ;
210- }
211- }
212- }
177+ val = self . convert_cast ( ctx, source_cty, enum_integral_type, val, None , None , None ) ?;
178+ val = val. map ( |val| self . enum_constructor_expr ( enum_id, val) ) ;
213179
214180 Ok ( val)
215181 }
@@ -263,10 +229,7 @@ impl<'c> Translation<'c> {
263229 . unwrap ( ) ;
264230 self . add_import ( enum_id, & enum_name) ;
265231
266- match self . tcfg . enum_mode {
267- EnumMode :: NewType => mk ( ) . call_expr ( mk ( ) . ident_expr ( enum_name) , vec ! [ value] ) ,
268- EnumMode :: Consts => mk ( ) . cast_expr ( value, mk ( ) . ident_ty ( enum_name) ) ,
269- }
232+ mk ( ) . call_expr ( mk ( ) . ident_expr ( enum_name) , vec ! [ value] )
270233 }
271234
272235 fn is_variant_of_enum ( & self , enum_id : CEnumId , enum_constant_id : CEnumConstantId ) -> bool {
0 commit comments