[breaking-change] don't glob export ast::BinOp_
This commit is contained in:
parent
f875f4c4c2
commit
05e25de4f0
12 changed files with 164 additions and 164 deletions
|
@ -885,24 +885,24 @@ pub fn lower_unop(_lctx: &LoweringContext, u: UnOp) -> hir::UnOp {
|
||||||
pub fn lower_binop(_lctx: &LoweringContext, b: BinOp) -> hir::BinOp {
|
pub fn lower_binop(_lctx: &LoweringContext, b: BinOp) -> hir::BinOp {
|
||||||
Spanned {
|
Spanned {
|
||||||
node: match b.node {
|
node: match b.node {
|
||||||
BiAdd => hir::BiAdd,
|
BinOpKind::Add => hir::BiAdd,
|
||||||
BiSub => hir::BiSub,
|
BinOpKind::Sub => hir::BiSub,
|
||||||
BiMul => hir::BiMul,
|
BinOpKind::Mul => hir::BiMul,
|
||||||
BiDiv => hir::BiDiv,
|
BinOpKind::Div => hir::BiDiv,
|
||||||
BiRem => hir::BiRem,
|
BinOpKind::Rem => hir::BiRem,
|
||||||
BiAnd => hir::BiAnd,
|
BinOpKind::And => hir::BiAnd,
|
||||||
BiOr => hir::BiOr,
|
BinOpKind::Or => hir::BiOr,
|
||||||
BiBitXor => hir::BiBitXor,
|
BinOpKind::BitXor => hir::BiBitXor,
|
||||||
BiBitAnd => hir::BiBitAnd,
|
BinOpKind::BitAnd => hir::BiBitAnd,
|
||||||
BiBitOr => hir::BiBitOr,
|
BinOpKind::BitOr => hir::BiBitOr,
|
||||||
BiShl => hir::BiShl,
|
BinOpKind::Shl => hir::BiShl,
|
||||||
BiShr => hir::BiShr,
|
BinOpKind::Shr => hir::BiShr,
|
||||||
BiEq => hir::BiEq,
|
BinOpKind::Eq => hir::BiEq,
|
||||||
BiLt => hir::BiLt,
|
BinOpKind::Lt => hir::BiLt,
|
||||||
BiLe => hir::BiLe,
|
BinOpKind::Le => hir::BiLe,
|
||||||
BiNe => hir::BiNe,
|
BinOpKind::Ne => hir::BiNe,
|
||||||
BiGe => hir::BiGe,
|
BinOpKind::Ge => hir::BiGe,
|
||||||
BiGt => hir::BiGt,
|
BinOpKind::Gt => hir::BiGt,
|
||||||
},
|
},
|
||||||
span: b.span,
|
span: b.span,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
// The Rust abstract syntax tree.
|
// The Rust abstract syntax tree.
|
||||||
|
|
||||||
pub use self::BinOp_::*;
|
|
||||||
pub use self::BlockCheckMode::*;
|
pub use self::BlockCheckMode::*;
|
||||||
pub use self::CaptureClause::*;
|
pub use self::CaptureClause::*;
|
||||||
pub use self::Decl_::*;
|
pub use self::Decl_::*;
|
||||||
|
@ -627,97 +626,99 @@ pub enum Mutability {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
pub enum BinOp_ {
|
pub enum BinOpKind {
|
||||||
/// The `+` operator (addition)
|
/// The `+` operator (addition)
|
||||||
BiAdd,
|
Add,
|
||||||
/// The `-` operator (subtraction)
|
/// The `-` operator (subtraction)
|
||||||
BiSub,
|
Sub,
|
||||||
/// The `*` operator (multiplication)
|
/// The `*` operator (multiplication)
|
||||||
BiMul,
|
Mul,
|
||||||
/// The `/` operator (division)
|
/// The `/` operator (division)
|
||||||
BiDiv,
|
Div,
|
||||||
/// The `%` operator (modulus)
|
/// The `%` operator (modulus)
|
||||||
BiRem,
|
Rem,
|
||||||
/// The `&&` operator (logical and)
|
/// The `&&` operator (logical and)
|
||||||
BiAnd,
|
And,
|
||||||
/// The `||` operator (logical or)
|
/// The `||` operator (logical or)
|
||||||
BiOr,
|
Or,
|
||||||
/// The `^` operator (bitwise xor)
|
/// The `^` operator (bitwise xor)
|
||||||
BiBitXor,
|
BitXor,
|
||||||
/// The `&` operator (bitwise and)
|
/// The `&` operator (bitwise and)
|
||||||
BiBitAnd,
|
BitAnd,
|
||||||
/// The `|` operator (bitwise or)
|
/// The `|` operator (bitwise or)
|
||||||
BiBitOr,
|
BitOr,
|
||||||
/// The `<<` operator (shift left)
|
/// The `<<` operator (shift left)
|
||||||
BiShl,
|
Shl,
|
||||||
/// The `>>` operator (shift right)
|
/// The `>>` operator (shift right)
|
||||||
BiShr,
|
Shr,
|
||||||
/// The `==` operator (equality)
|
/// The `==` operator (equality)
|
||||||
BiEq,
|
Eq,
|
||||||
/// The `<` operator (less than)
|
/// The `<` operator (less than)
|
||||||
BiLt,
|
Lt,
|
||||||
/// The `<=` operator (less than or equal to)
|
/// The `<=` operator (less than or equal to)
|
||||||
BiLe,
|
Le,
|
||||||
/// The `!=` operator (not equal to)
|
/// The `!=` operator (not equal to)
|
||||||
BiNe,
|
Ne,
|
||||||
/// The `>=` operator (greater than or equal to)
|
/// The `>=` operator (greater than or equal to)
|
||||||
BiGe,
|
Ge,
|
||||||
/// The `>` operator (greater than)
|
/// The `>` operator (greater than)
|
||||||
BiGt,
|
Gt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinOp_ {
|
impl BinOpKind {
|
||||||
pub fn to_string(&self) -> &'static str {
|
pub fn to_string(&self) -> &'static str {
|
||||||
|
use self::BinOpKind::*;
|
||||||
match *self {
|
match *self {
|
||||||
BiAdd => "+",
|
Add => "+",
|
||||||
BiSub => "-",
|
Sub => "-",
|
||||||
BiMul => "*",
|
Mul => "*",
|
||||||
BiDiv => "/",
|
Div => "/",
|
||||||
BiRem => "%",
|
Rem => "%",
|
||||||
BiAnd => "&&",
|
And => "&&",
|
||||||
BiOr => "||",
|
Or => "||",
|
||||||
BiBitXor => "^",
|
BitXor => "^",
|
||||||
BiBitAnd => "&",
|
BitAnd => "&",
|
||||||
BiBitOr => "|",
|
BitOr => "|",
|
||||||
BiShl => "<<",
|
Shl => "<<",
|
||||||
BiShr => ">>",
|
Shr => ">>",
|
||||||
BiEq => "==",
|
Eq => "==",
|
||||||
BiLt => "<",
|
Lt => "<",
|
||||||
BiLe => "<=",
|
Le => "<=",
|
||||||
BiNe => "!=",
|
Ne => "!=",
|
||||||
BiGe => ">=",
|
Ge => ">=",
|
||||||
BiGt => ">"
|
Gt => ">",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn lazy(&self) -> bool {
|
pub fn lazy(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
BiAnd | BiOr => true,
|
BinOpKind::And | BinOpKind::Or => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_shift(&self) -> bool {
|
pub fn is_shift(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
BiShl | BiShr => true,
|
BinOpKind::Shl | BinOpKind::Shr => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_comparison(&self) -> bool {
|
pub fn is_comparison(&self) -> bool {
|
||||||
|
use self::BinOpKind::*;
|
||||||
match *self {
|
match *self {
|
||||||
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe =>
|
Eq | Lt | Le | Ne | Gt | Ge =>
|
||||||
true,
|
true,
|
||||||
BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
|
And | Or | Add | Sub | Mul | Div | Rem |
|
||||||
BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr =>
|
BitXor | BitAnd | BitOr | Shl | Shr =>
|
||||||
false,
|
false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Returns `true` if the binary operator takes its arguments by value
|
/// Returns `true` if the binary operator takes its arguments by value
|
||||||
pub fn is_by_value(&self) -> bool {
|
pub fn is_by_value(&self) -> bool {
|
||||||
!BinOp_::is_comparison(self)
|
!self.is_comparison()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BinOp = Spanned<BinOp_>;
|
pub type BinOp = Spanned<BinOpKind>;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
pub enum UnOp {
|
pub enum UnOp {
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub trait AstBuilder {
|
||||||
fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
|
fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>;
|
||||||
|
|
||||||
fn expr_self(&self, span: Span) -> P<ast::Expr>;
|
fn expr_self(&self, span: Span) -> P<ast::Expr>;
|
||||||
fn expr_binary(&self, sp: Span, op: ast::BinOp_,
|
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
||||||
lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>;
|
lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>;
|
||||||
fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
|
fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>;
|
||||||
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>;
|
fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>;
|
||||||
|
@ -605,7 +605,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||||
self.expr_ident(span, special_idents::self_)
|
self.expr_ident(span, special_idents::self_)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr_binary(&self, sp: Span, op: ast::BinOp_,
|
fn expr_binary(&self, sp: Span, op: ast::BinOpKind,
|
||||||
lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> {
|
lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> {
|
||||||
self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs))
|
self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,13 @@ pub use self::PathParsingMode::*;
|
||||||
use abi;
|
use abi;
|
||||||
use ast::BareFnTy;
|
use ast::BareFnTy;
|
||||||
use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
|
use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
|
||||||
use ast::{Public, Unsafety, UnOp};
|
use ast::{Public, Unsafety};
|
||||||
use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode};
|
use ast::{Mod, Arg, Arm, Attribute, BindingMode};
|
||||||
use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block};
|
use ast::Block;
|
||||||
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause};
|
use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause};
|
||||||
use ast::{Constness, ConstTraitItem, Crate, CrateConfig};
|
use ast::{Constness, ConstTraitItem, Crate, CrateConfig};
|
||||||
use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn};
|
use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn};
|
||||||
use ast::{BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf};
|
use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf};
|
||||||
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
|
use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain};
|
||||||
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
|
use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox};
|
||||||
use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace};
|
use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace};
|
||||||
|
@ -38,14 +38,14 @@ use ast::{LitBool, LitChar, LitByte, LitByteStr};
|
||||||
use ast::{LitStr, LitInt, Local};
|
use ast::{LitStr, LitInt, Local};
|
||||||
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
|
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
|
||||||
use ast::{MutImmutable, MutMutable, Mac_};
|
use ast::{MutImmutable, MutMutable, Mac_};
|
||||||
use ast::{MutTy, BiMul, Mutability};
|
use ast::{MutTy, Mutability};
|
||||||
use ast::{NamedField, NoReturn};
|
use ast::{NamedField, NoReturn};
|
||||||
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange};
|
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange};
|
||||||
use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild};
|
use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild};
|
||||||
use ast::{PolyTraitRef, QSelf};
|
use ast::{PolyTraitRef, QSelf};
|
||||||
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
|
use ast::{Return, Stmt, StmtDecl};
|
||||||
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField};
|
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField};
|
||||||
use ast::{BiSub, StrStyle};
|
use ast::StrStyle;
|
||||||
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
|
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
|
||||||
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
|
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
|
||||||
use ast::{Ty, Ty_, TypeBinding, TyMac};
|
use ast::{Ty, Ty_, TypeBinding, TyMac};
|
||||||
|
@ -57,6 +57,7 @@ use ast::{UnnamedField, UnsafeBlock};
|
||||||
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
|
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||||
use ast::{Visibility, WhereClause};
|
use ast::{Visibility, WhereClause};
|
||||||
use attr::{ThinAttributes, ThinAttributesExt, AttributesExt};
|
use attr::{ThinAttributes, ThinAttributesExt, AttributesExt};
|
||||||
|
use ast::{BinOpKind, UnOp};
|
||||||
use ast;
|
use ast;
|
||||||
use ast_util::{self, ident_to_path};
|
use ast_util::{self, ident_to_path};
|
||||||
use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap};
|
use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap};
|
||||||
|
@ -2925,16 +2926,16 @@ impl<'a> Parser<'a> {
|
||||||
self.mk_expr(lhs_span.lo, rhs.span.hi, ExprInPlace(lhs, rhs), None),
|
self.mk_expr(lhs_span.lo, rhs.span.hi, ExprInPlace(lhs, rhs), None),
|
||||||
AssocOp::AssignOp(k) => {
|
AssocOp::AssignOp(k) => {
|
||||||
let aop = match k {
|
let aop = match k {
|
||||||
token::Plus => BiAdd,
|
token::Plus => BinOpKind::Add,
|
||||||
token::Minus => BiSub,
|
token::Minus => BinOpKind::Sub,
|
||||||
token::Star => BiMul,
|
token::Star => BinOpKind::Mul,
|
||||||
token::Slash => BiDiv,
|
token::Slash => BinOpKind::Div,
|
||||||
token::Percent => BiRem,
|
token::Percent => BinOpKind::Rem,
|
||||||
token::Caret => BiBitXor,
|
token::Caret => BinOpKind::BitXor,
|
||||||
token::And => BiBitAnd,
|
token::And => BinOpKind::BitAnd,
|
||||||
token::Or => BiBitOr,
|
token::Or => BinOpKind::BitOr,
|
||||||
token::Shl => BiShl,
|
token::Shl => BinOpKind::Shl,
|
||||||
token::Shr => BiShr
|
token::Shr => BinOpKind::Shr,
|
||||||
};
|
};
|
||||||
let (lhs_span, rhs_span) = (lhs_span, rhs.span);
|
let (lhs_span, rhs_span) = (lhs_span, rhs.span);
|
||||||
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
|
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
|
||||||
|
@ -2961,7 +2962,7 @@ impl<'a> Parser<'a> {
|
||||||
let op_span = mk_sp(op.span.lo, self.span.hi);
|
let op_span = mk_sp(op.span.lo, self.span.hi);
|
||||||
let mut err = self.diagnostic().struct_span_err(op_span,
|
let mut err = self.diagnostic().struct_span_err(op_span,
|
||||||
"chained comparison operators require parentheses");
|
"chained comparison operators require parentheses");
|
||||||
if op.node == BiLt && *outer_op == AssocOp::Greater {
|
if op.node == BinOpKind::Lt && *outer_op == AssocOp::Greater {
|
||||||
err.fileline_help(op_span,
|
err.fileline_help(op_span,
|
||||||
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
|
"use `::<...>` instead of `<...>` if you meant to specify type arguments");
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub use self::IdentStyle::*;
|
||||||
pub use self::Lit::*;
|
pub use self::Lit::*;
|
||||||
pub use self::Token::*;
|
pub use self::Token::*;
|
||||||
|
|
||||||
use ast;
|
use ast::{self, BinOpKind};
|
||||||
use ext::mtwt;
|
use ext::mtwt;
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
use util::interner::{RcStr, StrInterner};
|
use util::interner::{RcStr, StrInterner};
|
||||||
|
@ -264,26 +264,26 @@ impl Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maps a token to its corresponding binary operator.
|
/// Maps a token to its corresponding binary operator.
|
||||||
pub fn to_binop(&self) -> Option<ast::BinOp_> {
|
pub fn to_binop(&self) -> Option<BinOpKind> {
|
||||||
match *self {
|
match *self {
|
||||||
BinOp(Star) => Some(ast::BiMul),
|
BinOp(Star) => Some(BinOpKind::Mul),
|
||||||
BinOp(Slash) => Some(ast::BiDiv),
|
BinOp(Slash) => Some(BinOpKind::Div),
|
||||||
BinOp(Percent) => Some(ast::BiRem),
|
BinOp(Percent) => Some(BinOpKind::Rem),
|
||||||
BinOp(Plus) => Some(ast::BiAdd),
|
BinOp(Plus) => Some(BinOpKind::Add),
|
||||||
BinOp(Minus) => Some(ast::BiSub),
|
BinOp(Minus) => Some(BinOpKind::Sub),
|
||||||
BinOp(Shl) => Some(ast::BiShl),
|
BinOp(Shl) => Some(BinOpKind::Shl),
|
||||||
BinOp(Shr) => Some(ast::BiShr),
|
BinOp(Shr) => Some(BinOpKind::Shr),
|
||||||
BinOp(And) => Some(ast::BiBitAnd),
|
BinOp(And) => Some(BinOpKind::BitAnd),
|
||||||
BinOp(Caret) => Some(ast::BiBitXor),
|
BinOp(Caret) => Some(BinOpKind::BitXor),
|
||||||
BinOp(Or) => Some(ast::BiBitOr),
|
BinOp(Or) => Some(BinOpKind::BitOr),
|
||||||
Lt => Some(ast::BiLt),
|
Lt => Some(BinOpKind::Lt),
|
||||||
Le => Some(ast::BiLe),
|
Le => Some(BinOpKind::Le),
|
||||||
Ge => Some(ast::BiGe),
|
Ge => Some(BinOpKind::Ge),
|
||||||
Gt => Some(ast::BiGt),
|
Gt => Some(BinOpKind::Gt),
|
||||||
EqEq => Some(ast::BiEq),
|
EqEq => Some(BinOpKind::Eq),
|
||||||
Ne => Some(ast::BiNe),
|
Ne => Some(BinOpKind::Ne),
|
||||||
AndAnd => Some(ast::BiAnd),
|
AndAnd => Some(BinOpKind::And),
|
||||||
OrOr => Some(ast::BiOr),
|
OrOr => Some(BinOpKind::Or),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
use parse::token::{Token, BinOpToken, keywords};
|
use parse::token::{Token, BinOpToken, keywords};
|
||||||
use ast;
|
use ast::BinOpKind;
|
||||||
|
|
||||||
/// Associative operator with precedence.
|
/// Associative operator with precedence.
|
||||||
///
|
///
|
||||||
|
@ -108,28 +108,28 @@ impl AssocOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new AssocOp from ast::BinOp_.
|
/// Create a new AssocOp from ast::BinOpKind.
|
||||||
pub fn from_ast_binop(op: ast::BinOp_) -> Self {
|
pub fn from_ast_binop(op: BinOpKind) -> Self {
|
||||||
use self::AssocOp::*;
|
use self::AssocOp::*;
|
||||||
match op {
|
match op {
|
||||||
ast::BiLt => Less,
|
BinOpKind::Lt => Less,
|
||||||
ast::BiGt => Greater,
|
BinOpKind::Gt => Greater,
|
||||||
ast::BiLe => LessEqual,
|
BinOpKind::Le => LessEqual,
|
||||||
ast::BiGe => GreaterEqual,
|
BinOpKind::Ge => GreaterEqual,
|
||||||
ast::BiEq => Equal,
|
BinOpKind::Eq => Equal,
|
||||||
ast::BiNe => NotEqual,
|
BinOpKind::Ne => NotEqual,
|
||||||
ast::BiMul => Multiply,
|
BinOpKind::Mul => Multiply,
|
||||||
ast::BiDiv => Divide,
|
BinOpKind::Div => Divide,
|
||||||
ast::BiRem => Modulus,
|
BinOpKind::Rem => Modulus,
|
||||||
ast::BiAdd => Add,
|
BinOpKind::Add => Add,
|
||||||
ast::BiSub => Subtract,
|
BinOpKind::Sub => Subtract,
|
||||||
ast::BiShl => ShiftLeft,
|
BinOpKind::Shl => ShiftLeft,
|
||||||
ast::BiShr => ShiftRight,
|
BinOpKind::Shr => ShiftRight,
|
||||||
ast::BiBitAnd => BitAnd,
|
BinOpKind::BitAnd => BitAnd,
|
||||||
ast::BiBitXor => BitXor,
|
BinOpKind::BitXor => BitXor,
|
||||||
ast::BiBitOr => BitOr,
|
BinOpKind::BitOr => BitOr,
|
||||||
ast::BiAnd => LAnd,
|
BinOpKind::And => LAnd,
|
||||||
ast::BiOr => LOr
|
BinOpKind::Or => LOr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,27 +185,27 @@ impl AssocOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ast_binop(&self) -> Option<ast::BinOp_> {
|
pub fn to_ast_binop(&self) -> Option<BinOpKind> {
|
||||||
use self::AssocOp::*;
|
use self::AssocOp::*;
|
||||||
match *self {
|
match *self {
|
||||||
Less => Some(ast::BiLt),
|
Less => Some(BinOpKind::Lt),
|
||||||
Greater => Some(ast::BiGt),
|
Greater => Some(BinOpKind::Gt),
|
||||||
LessEqual => Some(ast::BiLe),
|
LessEqual => Some(BinOpKind::Le),
|
||||||
GreaterEqual => Some(ast::BiGe),
|
GreaterEqual => Some(BinOpKind::Ge),
|
||||||
Equal => Some(ast::BiEq),
|
Equal => Some(BinOpKind::Eq),
|
||||||
NotEqual => Some(ast::BiNe),
|
NotEqual => Some(BinOpKind::Ne),
|
||||||
Multiply => Some(ast::BiMul),
|
Multiply => Some(BinOpKind::Mul),
|
||||||
Divide => Some(ast::BiDiv),
|
Divide => Some(BinOpKind::Div),
|
||||||
Modulus => Some(ast::BiRem),
|
Modulus => Some(BinOpKind::Rem),
|
||||||
Add => Some(ast::BiAdd),
|
Add => Some(BinOpKind::Add),
|
||||||
Subtract => Some(ast::BiSub),
|
Subtract => Some(BinOpKind::Sub),
|
||||||
ShiftLeft => Some(ast::BiShl),
|
ShiftLeft => Some(BinOpKind::Shl),
|
||||||
ShiftRight => Some(ast::BiShr),
|
ShiftRight => Some(BinOpKind::Shr),
|
||||||
BitAnd => Some(ast::BiBitAnd),
|
BitAnd => Some(BinOpKind::BitAnd),
|
||||||
BitXor => Some(ast::BiBitXor),
|
BitXor => Some(BinOpKind::BitXor),
|
||||||
BitOr => Some(ast::BiBitOr),
|
BitOr => Some(BinOpKind::BitOr),
|
||||||
LAnd => Some(ast::BiAnd),
|
LAnd => Some(BinOpKind::And),
|
||||||
LOr => Some(ast::BiOr),
|
LOr => Some(BinOpKind::Or),
|
||||||
Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None
|
Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
use deriving::generic::*;
|
use deriving::generic::*;
|
||||||
use deriving::generic::ty::*;
|
use deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast::{MetaItem, Expr, BinOpKind, self};
|
||||||
use syntax::ast::{MetaItem, Expr};
|
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::{ExtCtxt, Annotatable};
|
use syntax::ext::base::{ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
|
@ -116,7 +115,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
|
|
||||||
let assign = cx.stmt_let(span, false, test_id, new);
|
let assign = cx.stmt_let(span, false, test_id, new);
|
||||||
|
|
||||||
let cond = cx.expr_binary(span, ast::BiEq,
|
let cond = cx.expr_binary(span, BinOpKind::Eq,
|
||||||
cx.expr_ident(span, test_id),
|
cx.expr_ident(span, test_id),
|
||||||
cx.expr_path(equals_path.clone()));
|
cx.expr_path(equals_path.clone()));
|
||||||
let if_ = cx.expr_if(span,
|
let if_ = cx.expr_if(span,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
use deriving::generic::*;
|
use deriving::generic::*;
|
||||||
use deriving::generic::ty::*;
|
use deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast::{MetaItem, Expr, self};
|
use syntax::ast::{MetaItem, Expr, BinOpKind};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::{ExtCtxt, Annotatable};
|
use syntax::ext::base::{ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
|
@ -35,9 +35,9 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone());
|
let eq = cx.expr_binary(span, BinOpKind::Eq, self_f, other_f.clone());
|
||||||
|
|
||||||
cx.expr_binary(span, ast::BiAnd, subexpr, eq)
|
cx.expr_binary(span, BinOpKind::And, subexpr, eq)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, true),
|
cx.expr_bool(span, true),
|
||||||
Box::new(|cx, span, _, _| cx.expr_bool(span, false)),
|
Box::new(|cx, span, _, _| cx.expr_bool(span, false)),
|
||||||
|
@ -52,9 +52,9 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
|
||||||
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`")
|
||||||
};
|
};
|
||||||
|
|
||||||
let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone());
|
let eq = cx.expr_binary(span, BinOpKind::Ne, self_f, other_f.clone());
|
||||||
|
|
||||||
cx.expr_binary(span, ast::BiOr, subexpr, eq)
|
cx.expr_binary(span, BinOpKind::Or, subexpr, eq)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, false),
|
cx.expr_bool(span, false),
|
||||||
Box::new(|cx, span, _, _| cx.expr_bool(span, true)),
|
Box::new(|cx, span, _, _| cx.expr_bool(span, true)),
|
||||||
|
|
|
@ -13,8 +13,7 @@ pub use self::OrderingOp::*;
|
||||||
use deriving::generic::*;
|
use deriving::generic::*;
|
||||||
use deriving::generic::ty::*;
|
use deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast::{MetaItem, Expr, BinOpKind, self};
|
||||||
use syntax::ast::{MetaItem, Expr};
|
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::{ExtCtxt, Annotatable};
|
use syntax::ext::base::{ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
|
@ -161,7 +160,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
|
|
||||||
let assign = cx.stmt_let(span, false, test_id, new);
|
let assign = cx.stmt_let(span, false, test_id, new);
|
||||||
|
|
||||||
let cond = cx.expr_binary(span, ast::BiEq,
|
let cond = cx.expr_binary(span, BinOpKind::Eq,
|
||||||
cx.expr_ident(span, test_id),
|
cx.expr_ident(span, test_id),
|
||||||
equals_expr.clone());
|
equals_expr.clone());
|
||||||
let if_ = cx.expr_if(span,
|
let if_ = cx.expr_if(span,
|
||||||
|
@ -183,7 +182,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
/// Strict inequality.
|
/// Strict inequality.
|
||||||
fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
||||||
span: Span, substr: &Substructure) -> P<Expr> {
|
span: Span, substr: &Substructure) -> P<Expr> {
|
||||||
let op = if less {ast::BiLt} else {ast::BiGt};
|
let op = if less { BinOpKind::Lt } else { BinOpKind::Gt };
|
||||||
cs_fold(
|
cs_fold(
|
||||||
false, // need foldr,
|
false, // need foldr,
|
||||||
|cx, span, subexpr, self_f, other_fs| {
|
|cx, span, subexpr, self_f, other_fs| {
|
||||||
|
@ -214,8 +213,8 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
||||||
let not_cmp = cx.expr_unary(span, ast::UnOp::Not,
|
let not_cmp = cx.expr_unary(span, ast::UnOp::Not,
|
||||||
cx.expr_binary(span, op, other_f.clone(), self_f));
|
cx.expr_binary(span, op, other_f.clone(), self_f));
|
||||||
|
|
||||||
let and = cx.expr_binary(span, ast::BiAnd, not_cmp, subexpr);
|
let and = cx.expr_binary(span, BinOpKind::And, not_cmp, subexpr);
|
||||||
cx.expr_binary(span, ast::BiOr, cmp, and)
|
cx.expr_binary(span, BinOpKind::Or, cmp, and)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, equal),
|
cx.expr_bool(span, equal),
|
||||||
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
|
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
|
|
|
@ -194,8 +194,7 @@ use std::vec;
|
||||||
|
|
||||||
use syntax::abi::Abi;
|
use syntax::abi::Abi;
|
||||||
use syntax::abi;
|
use syntax::abi;
|
||||||
use syntax::ast;
|
use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData, BinOpKind, self};
|
||||||
use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData};
|
|
||||||
use syntax::ast_util;
|
use syntax::ast_util;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
|
@ -1279,8 +1278,9 @@ impl<'a> MethodDef<'a> {
|
||||||
Some(first) => {
|
Some(first) => {
|
||||||
let first_expr = cx.expr_ident(sp, first);
|
let first_expr = cx.expr_ident(sp, first);
|
||||||
let id = cx.expr_ident(sp, ident);
|
let id = cx.expr_ident(sp, ident);
|
||||||
let test = cx.expr_binary(sp, ast::BiEq, first_expr, id);
|
let test = cx.expr_binary(sp, BinOpKind::Eq, first_expr, id);
|
||||||
discriminant_test = cx.expr_binary(sp, ast::BiAnd, discriminant_test, test)
|
discriminant_test = cx.expr_binary(sp, BinOpKind::And,
|
||||||
|
discriminant_test, test)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
first_ident = Some(ident);
|
first_ident = Some(ident);
|
||||||
|
|
|
@ -62,7 +62,7 @@ fn expand(cx: &mut ExtCtxt,
|
||||||
let zero = cx.expr_isize(span, 0);
|
let zero = cx.expr_isize(span, 0);
|
||||||
cs_fold(false,
|
cs_fold(false,
|
||||||
|cx, span, subexpr, field, _| {
|
|cx, span, subexpr, field, _| {
|
||||||
cx.expr_binary(span, ast::BiAdd, subexpr,
|
cx.expr_binary(span, ast::BinOpKind::Add, subexpr,
|
||||||
cx.expr_method_call(span, field,
|
cx.expr_method_call(span, field,
|
||||||
token::str_to_ident("total_sum"), vec![]))
|
token::str_to_ident("total_sum"), vec![]))
|
||||||
},
|
},
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span,
|
||||||
if item.attrs.iter().find(|a| a.check_name("ignore")).is_some() {
|
if item.attrs.iter().find(|a| a.check_name("ignore")).is_some() {
|
||||||
acc
|
acc
|
||||||
} else {
|
} else {
|
||||||
cx.expr_binary(item.span, ast::BiAdd, acc,
|
cx.expr_binary(item.span, ast::BinOpKind::Add, acc,
|
||||||
cx.expr_method_call(item.span,
|
cx.expr_method_call(item.span,
|
||||||
item.self_.clone(),
|
item.self_.clone(),
|
||||||
substr.method_ident,
|
substr.method_ident,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue