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 (64c21f9)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Dec 6, 2015
1 parent 92b2da0 commit 4e90ed6
Show file tree
Hide file tree
Showing 26 changed files with 1,277 additions and 513 deletions.
55 changes: 52 additions & 3 deletions syntex_syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub use self::ViewPath_::*;
pub use self::Visibility::*;
pub use self::PathParameters::*;

use attr::ThinAttributes;
use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
use abi::Abi;
use ast_util;
Expand Down Expand Up @@ -692,8 +693,21 @@ pub enum Stmt_ {
/// Expr with trailing semi-colon (may have any type):
StmtSemi(P<Expr>, NodeId),

StmtMac(P<Mac>, MacStmtStyle),
StmtMac(P<Mac>, MacStmtStyle, ThinAttributes),
}

impl Stmt_ {
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) => &[],
}
}
}

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum MacStmtStyle {
/// The macro statement had a trailing semicolon, e.g. `foo! { ... };`
Expand All @@ -718,6 +732,16 @@ pub struct Local {
pub init: Option<P<Expr>>,
pub id: NodeId,
pub span: Span,
pub attrs: ThinAttributes,
}

impl Local {
pub fn attrs(&self) -> &[Attribute] {
match self.attrs {
Some(ref b) => b,
None => &[],
}
}
}

pub type Decl = Spanned<Decl_>;
Expand All @@ -730,6 +754,15 @@ pub enum Decl_ {
DeclItem(P<Item>),
}

impl Decl {
pub fn attrs(&self) -> &[Attribute] {
match self.node {
DeclLocal(ref l) => l.attrs(),
DeclItem(ref i) => i.attrs(),
}
}
}

/// represents one arm of a 'match'
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Arm {
Expand Down Expand Up @@ -766,6 +799,16 @@ pub struct Expr {
pub id: NodeId,
pub node: Expr_,
pub span: Span,
pub attrs: ThinAttributes
}

impl Expr {
pub fn attrs(&self) -> &[Attribute] {
match self.attrs {
Some(ref b) => b,
None => &[],
}
}
}

impl fmt::Debug for Expr {
Expand Down Expand Up @@ -1258,7 +1301,7 @@ impl fmt::Debug for IntTy {

impl fmt::Display for IntTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ast_util::int_ty_to_string(*self, None))
write!(f, "{}", ast_util::int_ty_to_string(*self))
}
}

Expand Down Expand Up @@ -1303,7 +1346,7 @@ impl fmt::Debug for UintTy {

impl fmt::Display for UintTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ast_util::uint_ty_to_string(*self, None))
write!(f, "{}", ast_util::uint_ty_to_string(*self))
}
}

Expand Down Expand Up @@ -1792,6 +1835,12 @@ pub struct Item {
pub span: Span,
}

impl Item {
pub fn attrs(&self) -> &[Attribute] {
&self.attrs
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Item_ {
/// An`extern crate` item, with optional original crate name,
Expand Down
42 changes: 18 additions & 24 deletions syntex_syntax/src/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,23 @@ pub fn is_path(e: P<Expr>) -> bool {
match e.node { ExprPath(..) => true, _ => false }
}

/// Get a string representation of a signed int type, with its value.
/// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
pub fn int_ty_to_string(t: IntTy, val: Option<i64>) -> String {
let s = match t {
pub fn int_ty_to_string(t: IntTy) -> &'static str {
match t {
TyIs => "isize",
TyI8 => "i8",
TyI16 => "i16",
TyI32 => "i32",
TyI64 => "i64"
};

match val {
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
Some(n) => format!("{}{}", n as u64, s),
None => s.to_string()
}
}

pub fn int_val_to_string(t: IntTy, val: i64) -> String {
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
format!("{}{}", val as u64, int_ty_to_string(t))
}

pub fn int_ty_max(t: IntTy) -> u64 {
match t {
TyI8 => 0x80,
Expand All @@ -140,23 +137,20 @@ pub fn int_ty_max(t: IntTy) -> u64 {
}
}

/// Get a string representation of an unsigned int type, with its value.
/// We want to avoid "42u" in favor of "42us". "42uint" is right out.
pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
let s = match t {
pub fn uint_ty_to_string(t: UintTy) -> &'static str {
match t {
TyUs => "usize",
TyU8 => "u8",
TyU16 => "u16",
TyU32 => "u32",
TyU64 => "u64"
};

match val {
Some(n) => format!("{}{}", n, s),
None => s.to_string()
}
}

pub fn uint_val_to_string(t: UintTy, val: u64) -> String {
format!("{}{}", val, uint_ty_to_string(t))
}

pub fn uint_ty_max(t: UintTy) -> u64 {
match t {
TyU8 => 0xff,
Expand All @@ -166,10 +160,10 @@ pub fn uint_ty_max(t: UintTy) -> u64 {
}
}

pub fn float_ty_to_string(t: FloatTy) -> String {
pub fn float_ty_to_string(t: FloatTy) -> &'static str {
match t {
TyF32 => "f32".to_string(),
TyF64 => "f64".to_string(),
TyF32 => "f32",
TyF64 => "f64",
}
}

Expand Down
Loading

0 comments on commit 4e90ed6

Please sign in to comment.