@@ -2,13 +2,11 @@ use c2rust_ast_builder::mk;
22use proc_macro2:: Span ;
33use syn:: Expr ;
44
5- use crate :: c_ast:: CUnOp ;
65use crate :: {
76 diagnostics:: TranslationResult ,
87 translator:: { signed_int_expr, ConvertedDecl , EnumMode , ExprContext , Translation } ,
98 with_stmts:: WithStmts ,
10- CDeclKind , CEnumConstantId , CEnumId , CExprId , CExprKind , CLiteral , CQualTypeId , CTypeId ,
11- CTypeKind , ConstIntExpr ,
9+ CDeclKind , CEnumConstantId , CEnumId , CQualTypeId , CTypeId , CTypeKind , ConstIntExpr ,
1210} ;
1311
1412impl < ' c > Translation < ' c > {
@@ -141,29 +139,8 @@ impl<'c> Translation<'c> {
141139 ctx : ExprContext ,
142140 mut source_cty : CQualTypeId ,
143141 enum_id : CEnumId ,
144- expr : Option < CExprId > ,
145142 mut val : Box < Expr > ,
146143 ) -> TranslationResult < WithStmts < Box < Expr > > > {
147- if let Some ( expr) = expr {
148- match self . ast_context [ expr] . kind {
149- CExprKind :: Literal ( _, CLiteral :: Integer ( i, _) ) => {
150- val = self . enum_for_i64 ( enum_id, i as i64 ) ;
151- return Ok ( WithStmts :: new_val ( val) ) ;
152- }
153-
154- CExprKind :: Unary ( _, CUnOp :: Negate , subexpr_id, _) => {
155- if let & CExprKind :: Literal ( _, CLiteral :: Integer ( i, _) ) =
156- & self . ast_context [ subexpr_id] . kind
157- {
158- val = self . enum_for_i64 ( enum_id, -( i as i64 ) ) ;
159- return Ok ( WithStmts :: new_val ( val) ) ;
160- }
161- }
162-
163- _ => { }
164- }
165- }
166-
167144 // We could be casting from enum to enum...
168145 if let CTypeKind :: Enum ( source_enum_id) =
169146 self . ast_context . resolve_type ( source_cty. ctype ) . kind
@@ -208,7 +185,7 @@ impl<'c> Translation<'c> {
208185
209186 /// Given an integer value this attempts to either generate the corresponding enum
210187 /// variant directly, otherwise it converts a number to the enum type.
211- fn enum_for_i64 ( & self , enum_id : CEnumId , value : i64 ) -> Box < Expr > {
188+ pub fn enum_for_i64 ( & self , enum_id : CEnumId , value : i64 ) -> Box < Expr > {
212189 if let Some ( enum_constant_id) = self . enum_variant_for_i64 ( enum_id, value) {
213190 return self . enum_constant_expr ( enum_constant_id) ;
214191 }
0 commit comments