@@ -935,6 +935,37 @@ impure fn trans_exprs(@block_ctxt cx, &vec[@ast.expr] es)
935
935
ret tup( bcx, vs) ;
936
936
}
937
937
938
+ impure fn trans_cast ( @block_ctxt cx, & ast. expr e, & ast. ann ann) -> result {
939
+ auto e_res = trans_expr ( cx, e) ;
940
+ auto llsrctype = val_ty ( e_res. val ) ;
941
+ auto t = node_ann_type ( cx. fcx . ccx , ann) ;
942
+ auto lldsttype = type_of ( cx. fcx . ccx , t) ;
943
+ if ( !typeck. type_is_fp ( t) ) {
944
+ if ( llvm. LLVMGetIntTypeWidth ( lldsttype) >
945
+ llvm. LLVMGetIntTypeWidth ( llsrctype) ) {
946
+ if ( typeck. type_is_signed ( t) ) {
947
+ // Widening signed cast.
948
+ e_res. val =
949
+ e_res. bcx . build . SExtOrBitCast ( e_res. val ,
950
+ lldsttype) ;
951
+ } else {
952
+ // Widening unsigned cast.
953
+ e_res. val =
954
+ e_res. bcx . build . ZExtOrBitCast ( e_res. val ,
955
+ lldsttype) ;
956
+ }
957
+ } else {
958
+ // Narrowing cast.
959
+ e_res. val =
960
+ e_res. bcx . build . TruncOrBitCast ( e_res. val ,
961
+ lldsttype) ;
962
+ }
963
+ } else {
964
+ cx. fcx . ccx . sess . unimpl ( "fp cast" ) ;
965
+ }
966
+ ret e_res;
967
+ }
968
+
938
969
impure fn trans_expr ( @block_ctxt cx, & ast. expr e) -> result {
939
970
alt ( e. node ) {
940
971
case ( ast. expr_lit ( ?lit, _) ) {
@@ -1002,34 +1033,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
1002
1033
}
1003
1034
1004
1035
case ( ast. expr_cast ( ?e, _, ?ann) ) {
1005
- auto e_res = trans_expr ( cx, * e) ;
1006
- auto llsrctype = val_ty ( e_res. val ) ;
1007
- auto t = node_ann_type ( cx. fcx . ccx , ann) ;
1008
- auto lldsttype = type_of ( cx. fcx . ccx , t) ;
1009
- if ( !typeck. type_is_fp ( t) ) {
1010
- if ( llvm. LLVMGetIntTypeWidth ( lldsttype) >
1011
- llvm. LLVMGetIntTypeWidth ( llsrctype) ) {
1012
- if ( typeck. type_is_signed ( t) ) {
1013
- // Widening signed cast.
1014
- e_res. val =
1015
- e_res. bcx . build . SExtOrBitCast ( e_res. val ,
1016
- lldsttype) ;
1017
- } else {
1018
- // Widening unsigned cast.
1019
- e_res. val =
1020
- e_res. bcx . build . ZExtOrBitCast ( e_res. val ,
1021
- lldsttype) ;
1022
- }
1023
- } else {
1024
- // Narrowing cast.
1025
- e_res. val =
1026
- e_res. bcx . build . TruncOrBitCast ( e_res. val ,
1027
- lldsttype) ;
1028
- }
1029
- } else {
1030
- cx. fcx . ccx . sess . unimpl ( "fp cast" ) ;
1031
- }
1032
- ret e_res;
1036
+ ret trans_cast ( cx, * e, ann) ;
1033
1037
}
1034
1038
}
1035
1039
cx. fcx . ccx . sess . unimpl ( "expr variant in trans_expr" ) ;
0 commit comments