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

Commit

Permalink
Merge branch 'rust'
Browse files Browse the repository at this point in the history
# Conflicts:
#	syntex_syntax/src/ext/format.rs
#	syntex_syntax/src/lib.rs
  • Loading branch information
erickt committed Jul 12, 2015
2 parents 7b17b66 + ab0ac6d commit b4945b9
Show file tree
Hide file tree
Showing 26 changed files with 579 additions and 344 deletions.
2 changes: 1 addition & 1 deletion hello_world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hello_world"
version = "0.5.0"
version = "0.8.0"
authors = [ "[email protected]" ]
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion hello_world/hello_world_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hello_world_macros"
version = "0.5.0"
version = "0.8.0"
authors = [ "[email protected]" ]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion syntex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syntex"
version = "0.7.0"
version = "0.8.0"
authors = [ "[email protected]" ]
license = "MIT/Apache-2.0"
description = "A library that enables compile time syntax extension expansion"
Expand Down
2 changes: 1 addition & 1 deletion syntex_syntax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syntex_syntax"
version = "0.7.0"
version = "0.8.0"
authors = [ "[email protected]" ]
license = "MIT/Apache-2.0"
description = "Export of libsyntax for code generation"
Expand Down
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
4 changes: 2 additions & 2 deletions syntex_syntax/src/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub struct IdVisitor<'a, O:'a> {

impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> {
fn visit_generics_helper(&mut self, generics: &Generics) {
for type_parameter in &*generics.ty_params {
for type_parameter in generics.ty_params.iter() {
self.operation.visit_id(type_parameter.id)
}
for lifetime in &generics.lifetimes {
Expand Down Expand Up @@ -615,7 +615,7 @@ pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
// are two arrays of segments equal when compared unhygienically?
pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> bool {
a.len() == b.len() &&
a.iter().zip(b.iter()).all(|(s, t)| {
a.iter().zip(b).all(|(s, t)| {
s.identifier.name == t.identifier.name &&
// FIXME #7743: ident -> name problems in lifetime comparison?
// can types contain idents?
Expand Down
79 changes: 52 additions & 27 deletions syntex_syntax/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

// Functions dealing with attributes and meta items

// BitSet
#![allow(deprecated)]

pub use self::StabilityLevel::*;
pub use self::ReprAttr::*;
pub use self::IntType::*;
Expand Down Expand Up @@ -374,6 +377,8 @@ pub struct Stability {
// The reason for the current stability level. If deprecated, the
// reason for deprecation.
pub reason: Option<InternedString>,
// The relevant rust-lang issue
pub issue: Option<u32>
}

/// The available stability levels.
Expand All @@ -396,7 +401,7 @@ fn find_stability_generic<'a,
-> (Option<Stability>, Vec<&'a AM>) {

let mut stab: Option<Stability> = None;
let mut deprecated: Option<(InternedString, Option<InternedString>)> = None;
let mut deprecated: Option<(Option<InternedString>, Option<InternedString>)> = None;
let mut used_attrs: Vec<&'a AM> = vec![];

'outer: for attr in attrs {
Expand All @@ -408,41 +413,54 @@ fn find_stability_generic<'a,

used_attrs.push(attr);

let (feature, since, reason) = match attr.meta_item_list() {
let (feature, since, reason, issue) = match attr.meta_item_list() {
Some(metas) => {
let mut feature = None;
let mut since = None;
let mut reason = None;
for meta in metas.iter() {
if meta.name() == "feature" {
match meta.value_str() {
Some(v) => feature = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
let mut issue = None;
for meta in metas {
match &*meta.name() {
"feature" => {
match meta.value_str() {
Some(v) => feature = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
}
}
}
}
if &meta.name()[..] == "since" {
match meta.value_str() {
Some(v) => since = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
"since" => {
match meta.value_str() {
Some(v) => since = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
}
}
}
}
if &meta.name()[..] == "reason" {
match meta.value_str() {
Some(v) => reason = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
"reason" => {
match meta.value_str() {
Some(v) => reason = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
}
}
}
"issue" => {
match meta.value_str().and_then(|s| s.parse().ok()) {
Some(v) => issue = Some(v),
None => {
diagnostic.span_err(meta.span, "incorrect meta item");
continue 'outer;
}
}
}
_ => {}
}
}
(feature, since, reason)
(feature, since, reason, issue)
}
None => {
diagnostic.span_err(attr.span(), "incorrect stability attribute type");
Expand Down Expand Up @@ -476,14 +494,15 @@ fn find_stability_generic<'a,
feature: feature.unwrap_or(intern_and_get_ident("bogus")),
since: since,
deprecated_since: None,
reason: reason
reason: reason,
issue: issue,
});
} else { // "deprecated"
if deprecated.is_some() {
diagnostic.span_err(item_sp, "multiple deprecated attributes");
}

deprecated = Some((since.unwrap_or(intern_and_get_ident("bogus")), reason));
deprecated = Some((since, reason));
}
}

Expand All @@ -492,14 +511,20 @@ fn find_stability_generic<'a,
match stab {
Some(ref mut s) => {
let (since, reason) = deprecated.unwrap();
s.deprecated_since = Some(since);
s.deprecated_since = since;
s.reason = reason;
}
None => {
diagnostic.span_err(item_sp, "deprecated attribute must be paired with \
either stable or unstable attribute");
}
}
} else if stab.as_ref().map_or(false, |s| s.level == Unstable && s.issue.is_none()) {
// non-deprecated unstable items need to point to issues.
// FIXME: uncomment this error
// diagnostic.span_err(item_sp,
// "non-deprecated unstable items need to point \
// to an issue with `issue = \"NNN\"`");
}

(stab, used_attrs)
Expand Down
Loading

0 comments on commit b4945b9

Please sign in to comment.