@@ -34,13 +34,14 @@ use util::nodemap::{NodeMap, FxHashSet};
34
34
use syntax_pos:: { Span , DUMMY_SP } ;
35
35
use syntax:: codemap:: { self , Spanned } ;
36
36
use syntax:: abi:: Abi ;
37
- use syntax:: ast:: { Ident , Name , NodeId , DUMMY_NODE_ID , AsmDialect } ;
37
+ use syntax:: ast:: { self , Ident , Name , NodeId , DUMMY_NODE_ID , AsmDialect } ;
38
38
use syntax:: ast:: { Attribute , Lit , StrStyle , FloatTy , IntTy , UintTy , MetaItem } ;
39
39
use syntax:: ext:: hygiene:: SyntaxContext ;
40
40
use syntax:: ptr:: P ;
41
41
use syntax:: symbol:: { Symbol , keywords} ;
42
42
use syntax:: tokenstream:: TokenStream ;
43
43
use syntax:: util:: ThinVec ;
44
+ use syntax:: util:: parser:: ExprPrecedence ;
44
45
use ty:: AdtKind ;
45
46
46
47
use rustc_data_structures:: indexed_vec;
@@ -958,6 +959,31 @@ impl BinOp_ {
958
959
}
959
960
}
960
961
962
+ impl Into < ast:: BinOpKind > for BinOp_ {
963
+ fn into ( self ) -> ast:: BinOpKind {
964
+ match self {
965
+ BiAdd => ast:: BinOpKind :: Add ,
966
+ BiSub => ast:: BinOpKind :: Sub ,
967
+ BiMul => ast:: BinOpKind :: Mul ,
968
+ BiDiv => ast:: BinOpKind :: Div ,
969
+ BiRem => ast:: BinOpKind :: Rem ,
970
+ BiAnd => ast:: BinOpKind :: And ,
971
+ BiOr => ast:: BinOpKind :: Or ,
972
+ BiBitXor => ast:: BinOpKind :: BitXor ,
973
+ BiBitAnd => ast:: BinOpKind :: BitAnd ,
974
+ BiBitOr => ast:: BinOpKind :: BitOr ,
975
+ BiShl => ast:: BinOpKind :: Shl ,
976
+ BiShr => ast:: BinOpKind :: Shr ,
977
+ BiEq => ast:: BinOpKind :: Eq ,
978
+ BiLt => ast:: BinOpKind :: Lt ,
979
+ BiLe => ast:: BinOpKind :: Le ,
980
+ BiNe => ast:: BinOpKind :: Ne ,
981
+ BiGe => ast:: BinOpKind :: Ge ,
982
+ BiGt => ast:: BinOpKind :: Gt ,
983
+ }
984
+ }
985
+ }
986
+
961
987
pub type BinOp = Spanned < BinOp_ > ;
962
988
963
989
#[ derive( Clone , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug , Copy ) ]
@@ -1166,6 +1192,42 @@ pub struct Expr {
1166
1192
pub hir_id : HirId ,
1167
1193
}
1168
1194
1195
+ impl Expr {
1196
+ pub fn precedence ( & self ) -> ExprPrecedence {
1197
+ match self . node {
1198
+ ExprBox ( _) => ExprPrecedence :: Box ,
1199
+ ExprArray ( _) => ExprPrecedence :: Array ,
1200
+ ExprCall ( ..) => ExprPrecedence :: Call ,
1201
+ ExprMethodCall ( ..) => ExprPrecedence :: MethodCall ,
1202
+ ExprTup ( _) => ExprPrecedence :: Tup ,
1203
+ ExprBinary ( op, ..) => ExprPrecedence :: Binary ( op. node . into ( ) ) ,
1204
+ ExprUnary ( ..) => ExprPrecedence :: Unary ,
1205
+ ExprLit ( _) => ExprPrecedence :: Lit ,
1206
+ ExprType ( ..) | ExprCast ( ..) => ExprPrecedence :: Cast ,
1207
+ ExprIf ( ..) => ExprPrecedence :: If ,
1208
+ ExprWhile ( ..) => ExprPrecedence :: While ,
1209
+ ExprLoop ( ..) => ExprPrecedence :: Loop ,
1210
+ ExprMatch ( ..) => ExprPrecedence :: Match ,
1211
+ ExprClosure ( ..) => ExprPrecedence :: Closure ,
1212
+ ExprBlock ( ..) => ExprPrecedence :: Block ,
1213
+ ExprAssign ( ..) => ExprPrecedence :: Assign ,
1214
+ ExprAssignOp ( ..) => ExprPrecedence :: AssignOp ,
1215
+ ExprField ( ..) => ExprPrecedence :: Field ,
1216
+ ExprTupField ( ..) => ExprPrecedence :: TupField ,
1217
+ ExprIndex ( ..) => ExprPrecedence :: Index ,
1218
+ ExprPath ( ..) => ExprPrecedence :: Path ,
1219
+ ExprAddrOf ( ..) => ExprPrecedence :: AddrOf ,
1220
+ ExprBreak ( ..) => ExprPrecedence :: Break ,
1221
+ ExprAgain ( ..) => ExprPrecedence :: Continue ,
1222
+ ExprRet ( ..) => ExprPrecedence :: Ret ,
1223
+ ExprInlineAsm ( ..) => ExprPrecedence :: InlineAsm ,
1224
+ ExprStruct ( ..) => ExprPrecedence :: Struct ,
1225
+ ExprRepeat ( ..) => ExprPrecedence :: Repeat ,
1226
+ ExprYield ( ..) => ExprPrecedence :: Yield ,
1227
+ }
1228
+ }
1229
+ }
1230
+
1169
1231
impl fmt:: Debug for Expr {
1170
1232
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1171
1233
write ! ( f, "expr({}: {})" , self . id,
0 commit comments