@@ -5,7 +5,7 @@ use syn::Expr;
55use crate :: c_ast:: CUnOp ;
66use crate :: {
77 diagnostics:: TranslationResult ,
8- translator:: { signed_int_expr, ConvertedDecl , ExprContext , Translation } ,
8+ translator:: { signed_int_expr, ConvertedDecl , EnumMode , ExprContext , Translation } ,
99 with_stmts:: WithStmts ,
1010 CDeclKind , CEnumConstantId , CEnumId , CExprId , CExprKind , CLiteral , CQualTypeId , CTypeKind ,
1111 ConstIntExpr ,
@@ -23,10 +23,15 @@ impl<'c> Translation<'c> {
2323 . borrow ( )
2424 . resolve_decl_name ( enum_id)
2525 . expect ( "Enums should already be renamed" ) ;
26- let ty = self . convert_type ( integral_type. ctype ) ?;
27- Ok ( ConvertedDecl :: Item (
28- mk ( ) . span ( span) . pub_ ( ) . type_item ( enum_name, ty) ,
29- ) )
26+ let integral_type_rs = self . convert_type ( integral_type. ctype ) ?;
27+ let item = match self . tcfg . enum_mode {
28+ EnumMode :: Consts => mk ( )
29+ . span ( span)
30+ . pub_ ( )
31+ . type_item ( enum_name, integral_type_rs) ,
32+ } ;
33+
34+ Ok ( ConvertedDecl :: Item ( item) )
3035 }
3136
3237 pub fn convert_enum_constant (
@@ -163,11 +168,17 @@ impl<'c> Translation<'c> {
163168
164169 let enum_integral_type = self . enum_integral_type ( enum_id) ;
165170 let mut val = WithStmts :: new_val ( val) ;
166- let source_type_kind = & self . ast_context . resolve_type ( source_cty. ctype ) . kind ;
167- let enum_integral_type_kind = & self . ast_context . resolve_type ( enum_integral_type. ctype ) . kind ;
168171
169- if source_type_kind != enum_integral_type_kind {
170- val = val. map ( |val| self . enum_constructor_expr ( enum_id, val) ) ;
172+ match self . tcfg . enum_mode {
173+ EnumMode :: Consts => {
174+ let source_type_kind = & self . ast_context . resolve_type ( source_cty. ctype ) . kind ;
175+ let enum_integral_type_kind =
176+ & self . ast_context . resolve_type ( enum_integral_type. ctype ) . kind ;
177+
178+ if source_type_kind != enum_integral_type_kind {
179+ val = val. map ( |val| self . enum_constructor_expr ( enum_id, val) ) ;
180+ }
181+ }
171182 }
172183
173184 Ok ( val)
@@ -222,7 +233,9 @@ impl<'c> Translation<'c> {
222233 . unwrap ( ) ;
223234 self . add_import ( enum_id, & enum_name) ;
224235
225- mk ( ) . cast_expr ( value, mk ( ) . ident_ty ( enum_name) )
236+ match self . tcfg . enum_mode {
237+ EnumMode :: Consts => mk ( ) . cast_expr ( value, mk ( ) . ident_ty ( enum_name) ) ,
238+ }
226239 }
227240
228241 fn is_variant_of_enum ( & self , enum_id : CEnumId , enum_constant_id : CEnumConstantId ) -> bool {
0 commit comments