11use super :: { resolve_expr, PreferredType , ResolveExprCtx } ;
22use crate :: {
3- ast:: { self , UnaryOperator } ,
3+ ast:: { self , UnaryMathOperator } ,
44 resolve:: {
55 conform:: to_default:: conform_integer_literal_to_default_or_error,
6- destination:: resolve_expr_to_destination,
76 error:: { ResolveError , ResolveErrorKind } ,
87 Initialized ,
98 } ,
10- resolved:: { Expr , ExprKind , TypeKind , TypedExpr , UnaryOperation } ,
9+ resolved:: { Expr , ExprKind , TypeKind , TypedExpr , UnaryMathOperation } ,
1110 source_files:: Source ,
1211} ;
1312
14- pub fn resolve_unary_operation_expr (
13+ pub fn resolve_unary_math_operation_expr (
1514 ctx : & mut ResolveExprCtx < ' _ , ' _ > ,
16- unary_operation : & ast:: UnaryOperation ,
15+ operator : & UnaryMathOperator ,
16+ inner : & ast:: Expr ,
1717 preferred_type : Option < PreferredType > ,
1818 source : Source ,
1919) -> Result < TypedExpr , ResolveError > {
20- let resolved_expr = resolve_expr (
21- ctx,
22- & unary_operation. inner ,
23- preferred_type,
24- Initialized :: Require ,
25- ) ?;
26-
27- let operator = & unary_operation. operator ;
28-
29- if operator. is_address_of ( ) {
30- let result_type = resolved_expr. resolved_type . clone ( ) . pointer ( source) ;
31- let destination = resolve_expr_to_destination ( resolved_expr) ?;
32- let expr = Expr :: new ( ExprKind :: AddressOf ( Box :: new ( destination) ) , source) ;
33- return Ok ( TypedExpr :: new ( result_type, expr) ) ;
34- }
20+ let resolved_expr = resolve_expr ( ctx, inner, preferred_type, Initialized :: Require ) ?;
3521
3622 if operator. is_dereference ( ) {
3723 if resolved_expr. resolved_type . kind . is_ambiguous_type ( ) {
3824 return Err ( ResolveErrorKind :: CannotPerformUnaryOperationForType {
39- operator : unary_operation . operator . to_string ( ) ,
25+ operator : operator. to_string ( ) ,
4026 bad_type : resolved_expr. resolved_type . to_string ( ) ,
4127 }
4228 . at ( source) ) ;
@@ -46,15 +32,15 @@ pub fn resolve_unary_operation_expr(
4632 ( * * inner) . clone ( )
4733 } else {
4834 return Err ( ResolveErrorKind :: CannotPerformUnaryOperationForType {
49- operator : unary_operation . operator . to_string ( ) ,
35+ operator : operator. to_string ( ) ,
5036 bad_type : resolved_expr. resolved_type . to_string ( ) ,
5137 }
5238 . at ( source) ) ;
5339 } ;
5440
5541 let expr = Expr :: new (
56- ExprKind :: UnaryOperation ( Box :: new ( UnaryOperation {
57- operator : unary_operation . operator . clone ( ) ,
42+ ExprKind :: UnaryMathOperation ( Box :: new ( UnaryMathOperation {
43+ operator : operator. clone ( ) ,
5844 inner : resolved_expr,
5945 } ) ) ,
6046 source,
@@ -71,24 +57,26 @@ pub fn resolve_unary_operation_expr(
7157 }
7258 _ => {
7359 return Err ( ResolveErrorKind :: CannotPerformUnaryOperationForType {
74- operator : unary_operation . operator . to_string ( ) ,
60+ operator : operator. to_string ( ) ,
7561 bad_type : resolved_expr. resolved_type . to_string ( ) ,
7662 }
7763 . at ( source) ) ;
7864 }
7965 } ;
8066
81- let result_type = match unary_operation. operator {
82- UnaryOperator :: Not | UnaryOperator :: IsNonZero => TypeKind :: Boolean . at ( source) ,
83- UnaryOperator :: BitComplement | UnaryOperator :: Negate => resolved_expr. resolved_type . clone ( ) ,
84- UnaryOperator :: Dereference | UnaryOperator :: AddressOf => {
67+ let result_type = match operator {
68+ UnaryMathOperator :: Not | UnaryMathOperator :: IsNonZero => TypeKind :: Boolean . at ( source) ,
69+ UnaryMathOperator :: BitComplement | UnaryMathOperator :: Negate => {
70+ resolved_expr. resolved_type . clone ( )
71+ }
72+ UnaryMathOperator :: Dereference => {
8573 unreachable ! ( "should've already handled address-of/dereference operators" )
8674 }
8775 } ;
8876
8977 let expr = Expr :: new (
90- ExprKind :: UnaryOperation ( Box :: new ( UnaryOperation {
91- operator : unary_operation . operator . clone ( ) ,
78+ ExprKind :: UnaryMathOperation ( Box :: new ( UnaryMathOperation {
79+ operator : operator. clone ( ) ,
9280 inner : resolved_expr,
9381 } ) ) ,
9482 source,
0 commit comments