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
  • Loading branch information
erickt committed Aug 13, 2015
2 parents 58b7487 + 3ffcf14 commit 89091d8
Show file tree
Hide file tree
Showing 29 changed files with 347 additions and 306 deletions.
25 changes: 21 additions & 4 deletions syntex_syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ pub enum Expr_ {
/// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`.
ExprStruct(Path, Vec<Field>, Option<P<Expr>>),

/// A vector literal constructed from one repeated element.
/// 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.
Expand Down Expand Up @@ -1471,6 +1471,8 @@ pub enum Ty_ {
/// TyInfer means the type should be inferred instead of it having been
/// specified. This can appear anywhere in a type.
TyInfer,
// A macro in the type position.
TyMac(Mac)
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
Expand Down Expand Up @@ -1656,14 +1658,29 @@ pub type Variant = Spanned<Variant_>;

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum PathListItem_ {
PathListIdent { name: Ident, id: NodeId },
PathListMod { id: NodeId }
PathListIdent {
name: Ident,
/// renamed in list, eg `use foo::{bar as baz};`
rename: Option<Ident>,
id: NodeId
},
PathListMod {
/// renamed in list, eg `use foo::{self as baz};`
rename: Option<Ident>,
id: NodeId
}
}

impl PathListItem_ {
pub fn id(&self) -> NodeId {
match *self {
PathListIdent { id, .. } | PathListMod { id } => id
PathListIdent { id, .. } | PathListMod { id, .. } => id
}
}

pub fn rename(&self) -> Option<Ident> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions syntex_syntax/src/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ pub const COMMAND_LINE_SP: Span = Span { lo: BytePos(0),
hi: BytePos(0),
expn_id: COMMAND_LINE_EXPN };

impl Span {
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
pub fn substitute_dummy(self, other: Span) -> Span {
if self == DUMMY_SP { other } else { self }
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub struct Spanned<T> {
pub node: T,
Expand Down
2 changes: 1 addition & 1 deletion syntex_syntax/src/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
}

// URLs can be unavoidably longer than the line limit, so we allow them.
// Allowed format is: `[name]: http://rust-lang.org/`
// Allowed format is: `[name]: https://www.rust-lang.org/`
let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http");

if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) {
Expand Down
33 changes: 29 additions & 4 deletions syntex_syntax/src/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ pub trait MacResult {
fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
make_stmts_default!(self)
}

fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
None
}
}

macro_rules! make_MacEager {
Expand Down Expand Up @@ -267,6 +271,7 @@ make_MacEager! {
items: SmallVector<P<ast::Item>>,
impl_items: SmallVector<P<ast::ImplItem>>,
stmts: SmallVector<P<ast::Stmt>>,
ty: P<ast::Ty>,
}

impl MacResult for MacEager {
Expand Down Expand Up @@ -304,6 +309,10 @@ impl MacResult for MacEager {
}
None
}

fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
self.ty
}
}

/// Fill-in macro expansion result, to allow compilation to continue
Expand Down Expand Up @@ -350,15 +359,24 @@ impl DummyResult {
}
}

pub fn raw_ty(sp: Span) -> P<ast::Ty> {
P(ast::Ty {
id: ast::DUMMY_NODE_ID,
node: ast::TyInfer,
span: sp
})
}
}

impl MacResult for DummyResult {
fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> {
Some(DummyResult::raw_expr(self.span))
}

fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
Some(P(DummyResult::raw_pat(self.span)))
}

fn make_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Item>>> {
// this code needs a comment... why not always just return the Some() ?
if self.expr_only {
Expand All @@ -367,13 +385,15 @@ impl MacResult for DummyResult {
Some(SmallVector::zero())
}
}

fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::ImplItem>>> {
if self.expr_only {
None
} else {
Some(SmallVector::zero())
}
}

fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
Some(SmallVector::one(P(
codemap::respan(self.span,
Expand Down Expand Up @@ -551,7 +571,7 @@ pub struct ExtCtxt<'a> {
pub cfg: ast::CrateConfig,
pub backtrace: ExpnId,
pub ecfg: expand::ExpansionConfig<'a>,
pub use_std: bool,
pub crate_root: Option<&'static str>,

pub mod_path: Vec<ast::Ident> ,
pub exported_macros: Vec<ast::MacroDef>,
Expand All @@ -570,7 +590,7 @@ impl<'a> ExtCtxt<'a> {
backtrace: NO_EXPANSION,
mod_path: Vec::new(),
ecfg: ecfg,
use_std: true,
crate_root: None,
exported_macros: Vec::new(),
syntax_env: env,
recursion_count: 0,
Expand Down Expand Up @@ -738,8 +758,13 @@ impl<'a> ExtCtxt<'a> {
pub fn ident_of(&self, st: &str) -> ast::Ident {
str_to_ident(st)
}
pub fn ident_of_std(&self, st: &str) -> ast::Ident {
self.ident_of(if self.use_std { "std" } else { st })
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
let mut v = Vec::new();
if let Some(s) = self.crate_root {
v.push(self.ident_of(s));
}
v.extend(components.iter().map(|s| self.ident_of(s)));
return v
}
pub fn name_of(&self, st: &str) -> ast::Name {
token::intern(st)
Expand Down
82 changes: 15 additions & 67 deletions syntex_syntax/src/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.ty_path(
self.path_all(DUMMY_SP,
true,
vec!(
self.ident_of_std("core"),
self.ident_of("option"),
self.ident_of("Option")
),
self.std_path(&["option", "Option"]),
Vec::new(),
vec!( ty ),
Vec::new()))
Expand Down Expand Up @@ -713,11 +709,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr(sp, ast::ExprVec(exprs))
}
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
self.expr_call_global(sp,
vec!(self.ident_of_std("collections"),
self.ident_of("vec"),
self.ident_of("Vec"),
self.ident_of("new")),
self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
Vec::new())
}
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
Expand All @@ -733,20 +725,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {


fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let some = vec!(
self.ident_of_std("core"),
self.ident_of("option"),
self.ident_of("Option"),
self.ident_of("Some"));
let some = self.std_path(&["option", "Option", "Some"]);
self.expr_call_global(sp, some, vec!(expr))
}

fn expr_none(&self, sp: Span) -> P<ast::Expr> {
let none = self.path_global(sp, vec!(
self.ident_of_std("core"),
self.ident_of("option"),
self.ident_of("Option"),
self.ident_of("None")));
let none = self.std_path(&["option", "Option", "None"]);
let none = self.path_global(sp, none);
self.expr_path(none)
}

Expand All @@ -769,10 +754,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple);
self.expr_call_global(
span,
vec!(
self.ident_of_std("core"),
self.ident_of("rt"),
self.ident_of("begin_unwind")),
self.std_path(&["rt", "begin_unwind"]),
vec!(
self.expr_str(span, msg),
expr_file_line_ptr))
Expand All @@ -785,37 +767,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let ok = vec!(
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Ok"));
let ok = self.std_path(&["result", "Result", "Ok"]);
self.expr_call_global(sp, ok, vec!(expr))
}

fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
let err = vec!(
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Err"));
let err = self.std_path(&["result", "Result", "Err"]);
self.expr_call_global(sp, err, vec!(expr))
}

fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
let ok = vec![
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Ok")
];
let ok = self.std_path(&["result", "Result", "Ok"]);
let ok_path = self.path_global(sp, ok);
let err = vec![
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Err")
];
let err = self.std_path(&["result", "Result", "Err"]);
let err_path = self.path_global(sp, err);

let binding_variable = self.ident_of("__try_var");
Expand Down Expand Up @@ -876,41 +840,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = vec!(
self.ident_of_std("core"),
self.ident_of("option"),
self.ident_of("Option"),
self.ident_of("Some"));
let some = self.std_path(&["option", "Option", "Some"]);
let path = self.path_global(span, some);
self.pat_enum(span, path, vec!(pat))
}

fn pat_none(&self, span: Span) -> P<ast::Pat> {
let some = vec!(
self.ident_of_std("core"),
self.ident_of("option"),
self.ident_of("Option"),
self.ident_of("None"));
let some = self.std_path(&["option", "Option", "None"]);
let path = self.path_global(span, some);
self.pat_enum(span, path, vec!())
}

fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = vec!(
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Ok"));
let some = self.std_path(&["result", "Result", "Ok"]);
let path = self.path_global(span, some);
self.pat_enum(span, path, vec!(pat))
}

fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
let some = vec!(
self.ident_of_std("core"),
self.ident_of("result"),
self.ident_of("Result"),
self.ident_of("Err"));
let some = self.std_path(&["result", "Result", "Err"]);
let path = self.path_global(span, some);
self.pat_enum(span, path, vec!(pat))
}
Expand Down Expand Up @@ -1193,7 +1141,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
let imports = imports.iter().map(|id| {
respan(sp, ast::PathListIdent { name: *id, id: ast::DUMMY_NODE_ID })
respan(sp, ast::PathListIdent { name: *id, rename: None, id: ast::DUMMY_NODE_ID })
}).collect();

self.item_use(sp, vis,
Expand Down
9 changes: 4 additions & 5 deletions syntex_syntax/src/ext/deriving/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt,
item: &Annotatable,
push: &mut FnMut(Annotatable))
{
let path = Path::new(vec![
if cx.use_std { "std" } else { "core" },
"marker",
"Copy",
]);
let mut v = cx.crate_root.map(|s| vec![s]).unwrap_or(Vec::new());
v.push("marker");
v.push("Copy");
let path = Path::new(v);

let trait_def = TraitDef {
span: span,
Expand Down
7 changes: 1 addition & 6 deletions syntex_syntax/src/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ fn cs_clone(
substr: &Substructure) -> P<Expr> {
let ctor_path;
let all_fields;
let fn_path = vec![
cx.ident_of_std("core"),
cx.ident_of("clone"),
cx.ident_of("Clone"),
cx.ident_of("clone"),
];
let fn_path = cx.std_path(&["clone", "Clone", "clone"]);
let subcall = |field: &FieldInfo| {
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];

Expand Down
12 changes: 2 additions & 10 deletions syntex_syntax/src/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,9 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
substr: &Substructure) -> P<Expr> {
let test_id = cx.ident_of("__test");
let equals_path = cx.path_global(span,
vec!(cx.ident_of_std("core"),
cx.ident_of("cmp"),
cx.ident_of("Ordering"),
cx.ident_of("Equal")));
cx.std_path(&["cmp", "Ordering", "Equal"]));

let cmp_path = vec![
cx.ident_of_std("core"),
cx.ident_of("cmp"),
cx.ident_of("Ord"),
cx.ident_of("cmp"),
];
let cmp_path = cx.std_path(&["cmp", "Ord", "cmp"]);

/*
Builds:
Expand Down
Loading

0 comments on commit 89091d8

Please sign in to comment.