X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibsyntax%2Fast.rs;h=b677941291bc92fbd7d2d2a33492a1578833359b;hb=8290c950a8b4cdc70038736abcf29f41dede6e0c;hp=209ed014ea27caaa5c7d87a45da76675a41a5a2e;hpb=8516ba367d1f51318ce373fe9b60650c82ded1e9;p=rust.git diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 209ed014ea2..b677941291b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,30 +10,18 @@ // The Rust abstract syntax tree. -pub use self::Decl_::*; -pub use self::ExplicitSelf_::*; -pub use self::Expr_::*; -pub use self::FloatTy::*; pub use self::ForeignItem_::*; -pub use self::IntTy::*; pub use self::Item_::*; pub use self::KleeneOp::*; -pub use self::Lit_::*; -pub use self::LitIntType::*; pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; pub use self::Mutability::*; pub use self::Pat_::*; pub use self::PathListItem_::*; -pub use self::PrimTy::*; -pub use self::Sign::*; -pub use self::Stmt_::*; pub use self::StrStyle::*; pub use self::StructFieldKind::*; pub use self::TraitItem_::*; -pub use self::Ty_::*; pub use self::TyParamBound::*; -pub use self::UintTy::*; pub use self::UnsafeSource::*; pub use self::ViewPath_::*; pub use self::Visibility::*; @@ -746,7 +734,7 @@ pub fn to_string(op: UnOp) -> &'static str { } /// A statement -pub type Stmt = Spanned; +pub type Stmt = Spanned; impl fmt::Debug for Stmt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -759,36 +747,36 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] -pub enum Stmt_ { +pub enum StmtKind { /// Could be an item or a local (let) binding: - StmtDecl(P, NodeId), + Decl(P, NodeId), /// Expr without trailing semi-colon (must have unit type): - StmtExpr(P, NodeId), + Expr(P, NodeId), /// Expr with trailing semi-colon (may have any type): - StmtSemi(P, NodeId), + Semi(P, NodeId), - StmtMac(P, MacStmtStyle, ThinAttributes), + Mac(P, MacStmtStyle, ThinAttributes), } -impl Stmt_ { +impl StmtKind { pub fn id(&self) -> Option { match *self { - StmtDecl(_, id) => Some(id), - StmtExpr(_, id) => Some(id), - StmtSemi(_, id) => Some(id), - StmtMac(..) => None, + StmtKind::Decl(_, id) => Some(id), + StmtKind::Expr(_, id) => Some(id), + StmtKind::Semi(_, id) => Some(id), + StmtKind::Mac(..) => None, } } pub fn attrs(&self) -> &[Attribute] { match *self { - StmtDecl(ref d, _) => d.attrs(), - StmtExpr(ref e, _) | - StmtSemi(ref e, _) => e.attrs(), - StmtMac(_, _, Some(ref b)) => b, - StmtMac(_, _, None) => &[], + StmtKind::Decl(ref d, _) => d.attrs(), + StmtKind::Expr(ref e, _) | + StmtKind::Semi(ref e, _) => e.attrs(), + StmtKind::Mac(_, _, Some(ref b)) => b, + StmtKind::Mac(_, _, None) => &[], } } } @@ -829,21 +817,21 @@ pub fn attrs(&self) -> &[Attribute] { } } -pub type Decl = Spanned; +pub type Decl = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Decl_ { +pub enum DeclKind { /// A local (let) binding: - DeclLocal(P), + Local(P), /// An item binding: - DeclItem(P), + Item(P), } impl Decl { pub fn attrs(&self) -> &[Attribute] { match self.node { - DeclLocal(ref l) => l.attrs(), - DeclItem(ref i) => i.attrs(), + DeclKind::Local(ref l) => l.attrs(), + DeclKind::Item(ref i) => i.attrs(), } } } @@ -882,7 +870,7 @@ pub enum UnsafeSource { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,)] pub struct Expr { pub id: NodeId, - pub node: Expr_, + pub node: ExprKind, pub span: Span, pub attrs: ThinAttributes } @@ -903,18 +891,18 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Expr_ { +pub enum ExprKind { /// A `box x` expression. - ExprBox(P), + Box(P), /// First expr is the place; second expr is the value. - ExprInPlace(P, P), + InPlace(P, P), /// An array (`[a, b, c, d]`) - ExprVec(Vec>), + Vec(Vec>), /// A function call /// /// The first field resolves to the function itself, /// and the second field is the list of arguments - ExprCall(P, Vec>), + Call(P, Vec>), /// A method call (`x.foo::(a, b, c, d)`) /// /// The `SpannedIdent` is the identifier for the method name. @@ -926,109 +914,109 @@ pub enum Expr_ { /// and the remaining elements are the rest of the arguments. /// /// Thus, `x.foo::(a, b, c, d)` is represented as - /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. - ExprMethodCall(SpannedIdent, Vec>, Vec>), + /// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. + MethodCall(SpannedIdent, Vec>, Vec>), /// A tuple (`(a, b, c ,d)`) - ExprTup(Vec>), + Tup(Vec>), /// A binary operation (For example: `a + b`, `a * b`) - ExprBinary(BinOp, P, P), + Binary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) - ExprUnary(UnOp, P), + Unary(UnOp, P), /// A literal (For example: `1u8`, `"foo"`) - ExprLit(P), + Lit(P), /// A cast (`foo as f64`) - ExprCast(P, P), - ExprType(P, P), + Cast(P, P), + Type(P, P), /// An `if` block, with an optional else block /// /// `if expr { block } else { expr }` - ExprIf(P, P, Option>), + If(P, P, Option>), /// An `if let` expression with an optional else block /// /// `if let pat = expr { block } else { expr }` /// /// This is desugared to a `match` expression. - ExprIfLet(P, P, P, Option>), + IfLet(P, P, P, Option>), /// A while loop, with an optional label /// /// `'label: while expr { block }` - ExprWhile(P, P, Option), + While(P, P, Option), /// A while-let loop, with an optional label /// /// `'label: while let pat = expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - ExprWhileLet(P, P, P, Option), + WhileLet(P, P, P, Option), /// A for loop, with an optional label /// /// `'label: for pat in expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - ExprForLoop(P, P, P, Option), + ForLoop(P, P, P, Option), /// Conditionless loop (can be exited with break, continue, or return) /// /// `'label: loop { block }` - ExprLoop(P, Option), + Loop(P, Option), /// A `match` block. - ExprMatch(P, Vec), + Match(P, Vec), /// A closure (for example, `move |a, b, c| {a + b + c}`) - ExprClosure(CaptureBy, P, P), + Closure(CaptureBy, P, P), /// A block (`{ ... }`) - ExprBlock(P), + Block(P), /// An assignment (`a = foo()`) - ExprAssign(P, P), + Assign(P, P), /// An assignment with an operator /// /// For example, `a += 1`. - ExprAssignOp(BinOp, P, P), + AssignOp(BinOp, P, P), /// Access of a named struct field (`obj.foo`) - ExprField(P, SpannedIdent), + Field(P, SpannedIdent), /// Access of an unnamed field of a struct or tuple-struct /// /// For example, `foo.0`. - ExprTupField(P, Spanned), + TupField(P, Spanned), /// An indexing operation (`foo[2]`) - ExprIndex(P, P), + Index(P, P), /// A range (`1..2`, `1..`, or `..2`) - ExprRange(Option>, Option>), + Range(Option>, Option>), /// Variable reference, possibly containing `::` and/or type /// parameters, e.g. foo::bar::. /// /// Optionally "qualified", /// e.g. ` as SomeTrait>::SomeType`. - ExprPath(Option, Path), + Path(Option, Path), /// A referencing operation (`&a` or `&mut a`) - ExprAddrOf(Mutability, P), + AddrOf(Mutability, P), /// A `break`, with an optional label to break - ExprBreak(Option), + Break(Option), /// A `continue`, with an optional label - ExprAgain(Option), + Again(Option), /// A `return`, with an optional value to be returned - ExprRet(Option>), + Ret(Option>), /// Output of the `asm!()` macro - ExprInlineAsm(InlineAsm), + InlineAsm(InlineAsm), /// A macro invocation; pre-expansion - ExprMac(Mac), + Mac(Mac), /// A struct literal expression. /// /// For example, `Foo {x: 1, y: 2}`, or /// `Foo {x: 1, .. base}`, where `base` is the `Option`. - ExprStruct(Path, Vec, Option>), + Struct(Path, Vec, Option>), /// An array literal constructed from one repeated element. /// /// For example, `[1u8; 5]`. The first expression is the element /// to be repeated; the second is the number of times to repeat it. - ExprRepeat(P, P), + Repeat(P, P), /// No-op: used solely so we can pretty-print faithfully - ExprParen(P) + Paren(P), } /// The explicit Self type in a "qualified path". The actual @@ -1273,65 +1261,40 @@ pub enum StrStyle { } /// A literal -pub type Lit = Spanned; - -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum Sign { - Minus, - Plus -} - -impl Sign { - pub fn new(n: T) -> Sign { - n.sign() - } -} - -pub trait IntSign { - fn sign(&self) -> Sign; -} -macro_rules! doit { - ($($t:ident)*) => ($(impl IntSign for $t { - #[allow(unused_comparisons)] - fn sign(&self) -> Sign { - if *self < 0 {Minus} else {Plus} - } - })*) -} -doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } +pub type Lit = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum LitIntType { - SignedIntLit(IntTy, Sign), - UnsignedIntLit(UintTy), - UnsuffixedIntLit(Sign) + Signed(IntTy), + Unsigned(UintTy), + Unsuffixed, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Lit_ { +pub enum LitKind { /// A string literal (`"foo"`) - LitStr(InternedString, StrStyle), + Str(InternedString, StrStyle), /// A byte string (`b"foo"`) - LitByteStr(Rc>), + ByteStr(Rc>), /// A byte char (`b'f'`) - LitByte(u8), + Byte(u8), /// A character literal (`'a'`) - LitChar(char), + Char(char), /// An integer literal (`1u8`) - LitInt(u64, LitIntType), + Int(u64, LitIntType), /// A float literal (`1f64` or `1E10f64`) - LitFloat(InternedString, FloatTy), + Float(InternedString, FloatTy), /// A float literal without a suffix (`1.0 or 1.0E10`) - LitFloatUnsuffixed(InternedString), + FloatUnsuffixed(InternedString), /// A boolean literal - LitBool(bool), + Bool(bool), } -impl Lit_ { +impl LitKind { /// Returns true if this literal is a string and false otherwise. pub fn is_str(&self) -> bool { match *self { - LitStr(..) => true, + LitKind::Str(..) => true, _ => false, } } @@ -1397,11 +1360,11 @@ pub enum ImplItemKind { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum IntTy { - TyIs, - TyI8, - TyI16, - TyI32, - TyI64, + Is, + I8, + I16, + I32, + I64, } impl fmt::Debug for IntTy { @@ -1419,11 +1382,11 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { impl IntTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyIs => "isize", - TyI8 => "i8", - TyI16 => "i16", - TyI32 => "i32", - TyI64 => "i64" + IntTy::Is => "isize", + IntTy::I8 => "i8", + IntTy::I16 => "i16", + IntTy::I32 => "i32", + IntTy::I64 => "i64" } } @@ -1436,41 +1399,41 @@ pub fn val_to_string(&self, val: i64) -> String { pub fn ty_max(&self) -> u64 { match *self { - TyI8 => 0x80, - TyI16 => 0x8000, - TyIs | TyI32 => 0x80000000, // actually ni about TyIs - TyI64 => 0x8000000000000000 + IntTy::I8 => 0x80, + IntTy::I16 => 0x8000, + IntTy::Is | IntTy::I32 => 0x80000000, // FIXME: actually ni about Is + IntTy::I64 => 0x8000000000000000 } } pub fn bit_width(&self) -> Option { Some(match *self { - TyIs => return None, - TyI8 => 8, - TyI16 => 16, - TyI32 => 32, - TyI64 => 64, + IntTy::Is => return None, + IntTy::I8 => 8, + IntTy::I16 => 16, + IntTy::I32 => 32, + IntTy::I64 => 64, }) } } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum UintTy { - TyUs, - TyU8, - TyU16, - TyU32, - TyU64, + Us, + U8, + U16, + U32, + U64, } impl UintTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyUs => "usize", - TyU8 => "u8", - TyU16 => "u16", - TyU32 => "u32", - TyU64 => "u64" + UintTy::Us => "usize", + UintTy::U8 => "u8", + UintTy::U16 => "u16", + UintTy::U32 => "u32", + UintTy::U64 => "u64" } } @@ -1480,20 +1443,20 @@ pub fn val_to_string(&self, val: u64) -> String { pub fn ty_max(&self) -> u64 { match *self { - TyU8 => 0xff, - TyU16 => 0xffff, - TyUs | TyU32 => 0xffffffff, // actually ni about TyUs - TyU64 => 0xffffffffffffffff + UintTy::U8 => 0xff, + UintTy::U16 => 0xffff, + UintTy::Us | UintTy::U32 => 0xffffffff, // FIXME: actually ni about Us + UintTy::U64 => 0xffffffffffffffff } } pub fn bit_width(&self) -> Option { Some(match *self { - TyUs => return None, - TyU8 => 8, - TyU16 => 16, - TyU32 => 32, - TyU64 => 64, + UintTy::Us => return None, + UintTy::U8 => 8, + UintTy::U16 => 16, + UintTy::U32 => 32, + UintTy::U64 => 64, }) } } @@ -1512,8 +1475,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum FloatTy { - TyF32, - TyF64, + F32, + F64, } impl fmt::Debug for FloatTy { @@ -1531,15 +1494,15 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { impl FloatTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyF32 => "f32", - TyF64 => "f64", + FloatTy::F32 => "f32", + FloatTy::F64 => "f64", } } pub fn bit_width(&self) -> usize { match *self { - TyF32 => 32, - TyF64 => 64, + FloatTy::F32 => 32, + FloatTy::F64 => 64, } } } @@ -1556,7 +1519,7 @@ pub struct TypeBinding { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] pub struct Ty { pub id: NodeId, - pub node: Ty_, + pub node: TyKind, pub span: Span, } @@ -1566,17 +1529,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } -/// Not represented directly in the AST, referred to by name through a ty_path. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum PrimTy { - TyInt(IntTy), - TyUint(UintTy), - TyFloat(FloatTy), - TyStr, - TyBool, - TyChar -} - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct BareFnTy { pub unsafety: Unsafety, @@ -1587,36 +1539,36 @@ pub struct BareFnTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] /// The different kinds of types recognized by the compiler -pub enum Ty_ { - TyVec(P), +pub enum TyKind { + Vec(P), /// A fixed length array (`[T; n]`) - TyFixedLengthVec(P, P), + FixedLengthVec(P, P), /// A raw pointer (`*const T` or `*mut T`) - TyPtr(MutTy), + Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`) - TyRptr(Option, MutTy), + Rptr(Option, MutTy), /// A bare function (e.g. `fn(usize) -> bool`) - TyBareFn(P), + BareFn(P), /// A tuple (`(A, B, C, D,...)`) - TyTup(Vec> ), + Tup(Vec> ), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g. ` as SomeTrait>::SomeType`. /// /// Type parameters are stored in the Path itself - TyPath(Option, Path), + Path(Option, Path), /// Something like `A+B`. Note that `B` must always be a path. - TyObjectSum(P, TyParamBounds), + ObjectSum(P, TyParamBounds), /// A type like `for<'a> Foo<&'a Bar>` - TyPolyTraitRef(TyParamBounds), + PolyTraitRef(TyParamBounds), /// No-op; kept solely so that we can pretty-print faithfully - TyParen(P), + Paren(P), /// Unused for now - TyTypeof(P), - /// TyInfer means the type should be inferred instead of it having been + Typeof(P), + /// TyKind::Infer means the type should be inferred instead of it having been /// specified. This can appear anywhere in a type. - TyInfer, + Infer, // A macro in the type position. - TyMac(Mac) + Mac(Mac), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -1661,7 +1613,7 @@ pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg { // HACK(eddyb) fake type for the self argument. ty: P(Ty { id: DUMMY_NODE_ID, - node: TyInfer, + node: TyKind::Infer, span: DUMMY_SP, }), pat: P(Pat { @@ -1748,18 +1700,18 @@ pub fn span(&self) -> Span { /// Represents the kind of 'self' associated with a method #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ExplicitSelf_ { +pub enum SelfKind { /// No self - SelfStatic, + Static, /// `self` - SelfValue(Ident), + Value(Ident), /// `&'lt self`, `&'lt mut self` - SelfRegion(Option, Mutability, Ident), + Region(Option, Mutability, Ident), /// `self: TYPE` - SelfExplicit(P, Ident), + Explicit(P, Ident), } -pub type ExplicitSelf = Spanned; +pub type ExplicitSelf = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Mod {