Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Update to rust HEAD (2999003)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Jul 12, 2015
1 parent 9fdbfcd commit ab0ac6d
Show file tree
Hide file tree
Showing 26 changed files with 583 additions and 1,625 deletions.
2 changes: 2 additions & 0 deletions syntex_syntax/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum Os {
OsiOS,
OsDragonfly,
OsBitrig,
OsNetbsd,
OsOpenbsd,
}

Expand Down Expand Up @@ -138,6 +139,7 @@ impl fmt::Display for Os {
OsFreebsd => "freebsd".fmt(f),
OsDragonfly => "dragonfly".fmt(f),
OsBitrig => "bitrig".fmt(f),
OsNetbsd => "netbsd".fmt(f),
OsOpenbsd => "openbsd".fmt(f),
}
}
Expand Down
76 changes: 67 additions & 9 deletions syntex_syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ use owned_slice::OwnedSlice;
use parse::token::{InternedString, str_to_ident};
use parse::token;
use parse::lexer;
use print::pprust;
use ptr::P;

use std::cell::Cell;
use std::fmt;
use std::rc::Rc;
use serialize::{Encodable, Decodable, Encoder, Decoder};
Expand Down Expand Up @@ -200,14 +202,19 @@ impl Decodable for Ident {
/// Function name (not all functions have names)
pub type FnIdent = Option<Ident>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,
Debug, Copy)]
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
pub struct Lifetime {
pub id: NodeId,
pub span: Span,
pub name: Name
}

impl fmt::Debug for Lifetime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "lifetime({}: {})", self.id, pprust::lifetime_to_string(self))
}
}

/// A lifetime definition, eg `'a: 'b+'c+'d`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct LifetimeDef {
Expand All @@ -218,7 +225,7 @@ pub struct LifetimeDef {
/// A "Path" is essentially Rust's notion of a name; for instance:
/// std::cmp::PartialEq . It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Path {
pub span: Span,
/// A `::foo` path, is relative to the crate root rather than current
Expand All @@ -228,6 +235,18 @@ pub struct Path {
pub segments: Vec<PathSegment>,
}

impl fmt::Debug for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "path({})", pprust::path_to_string(self))
}
}

impl fmt::Display for Path {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", pprust::path_to_string(self))
}
}

/// A segment of a path: an identifier, an optional lifetime, and a set of
/// types.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down Expand Up @@ -358,12 +377,25 @@ pub type CrateNum = u32;
pub type NodeId = u32;

#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable,
RustcDecodable, Hash, Debug, Copy)]
RustcDecodable, Hash, Copy)]
pub struct DefId {
pub krate: CrateNum,
pub node: NodeId,
}

fn default_def_id_debug(_: DefId, _: &mut fmt::Formatter) -> fmt::Result { Ok(()) }

thread_local!(pub static DEF_ID_DEBUG: Cell<fn(DefId, &mut fmt::Formatter) -> fmt::Result> =
Cell::new(default_def_id_debug));

impl fmt::Debug for DefId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "DefId {{ krate: {}, node: {} }}",
self.krate, self.node));
DEF_ID_DEBUG.with(|def_id_debug| def_id_debug.get()(*self, f))
}
}

impl DefId {
/// Read the node id, asserting that this def-id is krate-local.
pub fn local_id(&self) -> NodeId {
Expand Down Expand Up @@ -539,13 +571,19 @@ pub struct Block {
pub span: Span,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Pat {
pub id: NodeId,
pub node: Pat_,
pub span: Span,
}

impl fmt::Debug for Pat {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "pat({}: {})", self.id, pprust::pat_to_string(self))
}
}

/// A single field in a struct pattern
///
/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
Expand Down Expand Up @@ -682,7 +720,16 @@ pub enum UnOp {
/// A statement
pub type Stmt = Spanned<Stmt_>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "stmt({}: {})",
ast_util::stmt_id(self),
pprust::stmt_to_string(self))
}
}


#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub enum Stmt_ {
/// Could be an item or a local (let) binding:
StmtDecl(P<Decl>, NodeId),
Expand All @@ -695,7 +742,6 @@ pub enum Stmt_ {

StmtMac(P<Mac>, MacStmtStyle),
}

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum MacStmtStyle {
/// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
Expand Down Expand Up @@ -772,13 +818,19 @@ pub enum UnsafeSource {
}

/// An expression
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,)]
pub struct Expr {
pub id: NodeId,
pub node: Expr_,
pub span: Span,
}

impl fmt::Debug for Expr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "expr({}: {})", self.id, pprust::expr_to_string(self))
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Expr_ {
/// First expr is the place; second expr is the value.
Expand Down Expand Up @@ -1357,13 +1409,19 @@ pub struct TypeBinding {


// NB PartialEq method appears below.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Ty {
pub id: NodeId,
pub node: Ty_,
pub span: Span,
}

impl fmt::Debug for Ty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "type({})", pprust::ty_to_string(self))
}
}

/// 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 {
Expand Down
Loading

0 comments on commit ab0ac6d

Please sign in to comment.