diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-02-08 13:16:12 +0100 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-02-11 12:34:48 +0100 |
| commit | 05e25de4f0add7ae3cd0e8f66cd4558c5bfa42aa (patch) | |
| tree | 587130bb0d9d974e579d5a92a4893412351069fe /src/libsyntax | |
| parent | f875f4c4c24e8a14c04bbe4eedd230c4aa3c1431 (diff) | |
| download | rust-05e25de4f0add7ae3cd0e8f66cd4558c5bfa42aa.tar.gz rust-05e25de4f0add7ae3cd0e8f66cd4558c5bfa42aa.zip | |
[breaking-change] don't glob export ast::BinOp_
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 93 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 37 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax/util/parser.rs | 80 |
5 files changed, 128 insertions, 126 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2b3ca63c26f..be6d65a01b5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; pub use self::Decl_::*; @@ -627,97 +626,99 @@ pub enum Mutability { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum BinOp_ { +pub enum BinOpKind { /// The `+` operator (addition) - BiAdd, + Add, /// The `-` operator (subtraction) - BiSub, + Sub, /// The `*` operator (multiplication) - BiMul, + Mul, /// The `/` operator (division) - BiDiv, + Div, /// The `%` operator (modulus) - BiRem, + Rem, /// The `&&` operator (logical and) - BiAnd, + And, /// The `||` operator (logical or) - BiOr, + Or, /// The `^` operator (bitwise xor) - BiBitXor, + BitXor, /// The `&` operator (bitwise and) - BiBitAnd, + BitAnd, /// The `|` operator (bitwise or) - BiBitOr, + BitOr, /// The `<<` operator (shift left) - BiShl, + Shl, /// The `>>` operator (shift right) - BiShr, + Shr, /// The `==` operator (equality) - BiEq, + Eq, /// The `<` operator (less than) - BiLt, + Lt, /// The `<=` operator (less than or equal to) - BiLe, + Le, /// The `!=` operator (not equal to) - BiNe, + Ne, /// The `>=` operator (greater than or equal to) - BiGe, + Ge, /// The `>` operator (greater than) - BiGt, + Gt, } -impl BinOp_ { +impl BinOpKind { pub fn to_string(&self) -> &'static str { + use self::BinOpKind::*; match *self { - BiAdd => "+", - BiSub => "-", - BiMul => "*", - BiDiv => "/", - BiRem => "%", - BiAnd => "&&", - BiOr => "||", - BiBitXor => "^", - BiBitAnd => "&", - BiBitOr => "|", - BiShl => "<<", - BiShr => ">>", - BiEq => "==", - BiLt => "<", - BiLe => "<=", - BiNe => "!=", - BiGe => ">=", - BiGt => ">" + Add => "+", + Sub => "-", + Mul => "*", + Div => "/", + Rem => "%", + And => "&&", + Or => "||", + BitXor => "^", + BitAnd => "&", + BitOr => "|", + Shl => "<<", + Shr => ">>", + Eq => "==", + Lt => "<", + Le => "<=", + Ne => "!=", + Ge => ">=", + Gt => ">", } } pub fn lazy(&self) -> bool { match *self { - BiAnd | BiOr => true, + BinOpKind::And | BinOpKind::Or => true, _ => false } } pub fn is_shift(&self) -> bool { match *self { - BiShl | BiShr => true, + BinOpKind::Shl | BinOpKind::Shr => true, _ => false } } pub fn is_comparison(&self) -> bool { + use self::BinOpKind::*; match *self { - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => + Eq | Lt | Le | Ne | Gt | Ge => true, - BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem | - BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => + And | Or | Add | Sub | Mul | Div | Rem | + BitXor | BitAnd | BitOr | Shl | Shr => false, } } /// Returns `true` if the binary operator takes its arguments by value 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)] pub enum UnOp { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 2ce2e7f71f3..a5f6454cb38 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -116,7 +116,7 @@ pub trait AstBuilder { fn expr_ident(&self, span: Span, id: ast::Ident) -> 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>; 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>; @@ -605,7 +605,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { 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> { self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c174e35d93b..d6d0a35f2ce 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -13,13 +13,13 @@ pub use self::PathParsingMode::*; use abi; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Public, Unsafety, UnOp}; -use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode}; -use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block}; +use ast::{Public, Unsafety}; +use ast::{Mod, Arg, Arm, Attribute, BindingMode}; +use ast::Block; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; 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::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace}; @@ -38,14 +38,14 @@ use ast::{LitBool, LitChar, LitByte, LitByteStr}; use ast::{LitStr, LitInt, Local}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MutImmutable, MutMutable, Mac_}; -use ast::{MutTy, BiMul, Mutability}; +use ast::{MutTy, Mutability}; use ast::{NamedField, NoReturn}; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; 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::{BiSub, StrStyle}; +use ast::StrStyle; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; @@ -57,6 +57,7 @@ use ast::{UnnamedField, UnsafeBlock}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; use attr::{ThinAttributes, ThinAttributesExt, AttributesExt}; +use ast::{BinOpKind, UnOp}; use ast; use ast_util::{self, ident_to_path}; 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), AssocOp::AssignOp(k) => { let aop = match k { - token::Plus => BiAdd, - token::Minus => BiSub, - token::Star => BiMul, - token::Slash => BiDiv, - token::Percent => BiRem, - token::Caret => BiBitXor, - token::And => BiBitAnd, - token::Or => BiBitOr, - token::Shl => BiShl, - token::Shr => BiShr + token::Plus => BinOpKind::Add, + token::Minus => BinOpKind::Sub, + token::Star => BinOpKind::Mul, + token::Slash => BinOpKind::Div, + token::Percent => BinOpKind::Rem, + token::Caret => BinOpKind::BitXor, + token::And => BinOpKind::BitAnd, + token::Or => BinOpKind::BitOr, + token::Shl => BinOpKind::Shl, + token::Shr => BinOpKind::Shr, }; let (lhs_span, rhs_span) = (lhs_span, rhs.span); 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 mut err = self.diagnostic().struct_span_err(op_span, "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, "use `::<...>` instead of `<...>` if you meant to specify type arguments"); } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 220d0aff2e3..7d1b78b632f 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -15,7 +15,7 @@ pub use self::IdentStyle::*; pub use self::Lit::*; pub use self::Token::*; -use ast; +use ast::{self, BinOpKind}; use ext::mtwt; use ptr::P; use util::interner::{RcStr, StrInterner}; @@ -264,26 +264,26 @@ impl Token { } /// 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 { - BinOp(Star) => Some(ast::BiMul), - BinOp(Slash) => Some(ast::BiDiv), - BinOp(Percent) => Some(ast::BiRem), - BinOp(Plus) => Some(ast::BiAdd), - BinOp(Minus) => Some(ast::BiSub), - BinOp(Shl) => Some(ast::BiShl), - BinOp(Shr) => Some(ast::BiShr), - BinOp(And) => Some(ast::BiBitAnd), - BinOp(Caret) => Some(ast::BiBitXor), - BinOp(Or) => Some(ast::BiBitOr), - Lt => Some(ast::BiLt), - Le => Some(ast::BiLe), - Ge => Some(ast::BiGe), - Gt => Some(ast::BiGt), - EqEq => Some(ast::BiEq), - Ne => Some(ast::BiNe), - AndAnd => Some(ast::BiAnd), - OrOr => Some(ast::BiOr), + BinOp(Star) => Some(BinOpKind::Mul), + BinOp(Slash) => Some(BinOpKind::Div), + BinOp(Percent) => Some(BinOpKind::Rem), + BinOp(Plus) => Some(BinOpKind::Add), + BinOp(Minus) => Some(BinOpKind::Sub), + BinOp(Shl) => Some(BinOpKind::Shl), + BinOp(Shr) => Some(BinOpKind::Shr), + BinOp(And) => Some(BinOpKind::BitAnd), + BinOp(Caret) => Some(BinOpKind::BitXor), + BinOp(Or) => Some(BinOpKind::BitOr), + Lt => Some(BinOpKind::Lt), + Le => Some(BinOpKind::Le), + Ge => Some(BinOpKind::Ge), + Gt => Some(BinOpKind::Gt), + EqEq => Some(BinOpKind::Eq), + Ne => Some(BinOpKind::Ne), + AndAnd => Some(BinOpKind::And), + OrOr => Some(BinOpKind::Or), _ => None, } } diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index 87ef96d87ff..6fb81bb6a76 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. use parse::token::{Token, BinOpToken, keywords}; -use ast; +use ast::BinOpKind; /// Associative operator with precedence. /// @@ -108,28 +108,28 @@ impl AssocOp { } } - /// Create a new AssocOp from ast::BinOp_. - pub fn from_ast_binop(op: ast::BinOp_) -> Self { + /// Create a new AssocOp from ast::BinOpKind. + pub fn from_ast_binop(op: BinOpKind) -> Self { use self::AssocOp::*; match op { - ast::BiLt => Less, - ast::BiGt => Greater, - ast::BiLe => LessEqual, - ast::BiGe => GreaterEqual, - ast::BiEq => Equal, - ast::BiNe => NotEqual, - ast::BiMul => Multiply, - ast::BiDiv => Divide, - ast::BiRem => Modulus, - ast::BiAdd => Add, - ast::BiSub => Subtract, - ast::BiShl => ShiftLeft, - ast::BiShr => ShiftRight, - ast::BiBitAnd => BitAnd, - ast::BiBitXor => BitXor, - ast::BiBitOr => BitOr, - ast::BiAnd => LAnd, - ast::BiOr => LOr + BinOpKind::Lt => Less, + BinOpKind::Gt => Greater, + BinOpKind::Le => LessEqual, + BinOpKind::Ge => GreaterEqual, + BinOpKind::Eq => Equal, + BinOpKind::Ne => NotEqual, + BinOpKind::Mul => Multiply, + BinOpKind::Div => Divide, + BinOpKind::Rem => Modulus, + BinOpKind::Add => Add, + BinOpKind::Sub => Subtract, + BinOpKind::Shl => ShiftLeft, + BinOpKind::Shr => ShiftRight, + BinOpKind::BitAnd => BitAnd, + BinOpKind::BitXor => BitXor, + BinOpKind::BitOr => BitOr, + BinOpKind::And => LAnd, + 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::*; match *self { - Less => Some(ast::BiLt), - Greater => Some(ast::BiGt), - LessEqual => Some(ast::BiLe), - GreaterEqual => Some(ast::BiGe), - Equal => Some(ast::BiEq), - NotEqual => Some(ast::BiNe), - Multiply => Some(ast::BiMul), - Divide => Some(ast::BiDiv), - Modulus => Some(ast::BiRem), - Add => Some(ast::BiAdd), - Subtract => Some(ast::BiSub), - ShiftLeft => Some(ast::BiShl), - ShiftRight => Some(ast::BiShr), - BitAnd => Some(ast::BiBitAnd), - BitXor => Some(ast::BiBitXor), - BitOr => Some(ast::BiBitOr), - LAnd => Some(ast::BiAnd), - LOr => Some(ast::BiOr), + Less => Some(BinOpKind::Lt), + Greater => Some(BinOpKind::Gt), + LessEqual => Some(BinOpKind::Le), + GreaterEqual => Some(BinOpKind::Ge), + Equal => Some(BinOpKind::Eq), + NotEqual => Some(BinOpKind::Ne), + Multiply => Some(BinOpKind::Mul), + Divide => Some(BinOpKind::Div), + Modulus => Some(BinOpKind::Rem), + Add => Some(BinOpKind::Add), + Subtract => Some(BinOpKind::Sub), + ShiftLeft => Some(BinOpKind::Shl), + ShiftRight => Some(BinOpKind::Shr), + BitAnd => Some(BinOpKind::BitAnd), + BitXor => Some(BinOpKind::BitXor), + BitOr => Some(BinOpKind::BitOr), + LAnd => Some(BinOpKind::And), + LOr => Some(BinOpKind::Or), Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None } } |
