Skip to content

Update libsyntax and rustc to use serialization2 #3690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 1 addition & 108 deletions src/libsyntax/ext/auto_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,7 @@ fn expand(cx: ext_ctxt,
}
}

trait ext_ctxt_helpers {
fn helper_path(base_path: @ast::path, helper_name: ~str) -> @ast::path;
fn path(span: span, strs: ~[ast::ident]) -> @ast::path;
fn path_tps(span: span, strs: ~[ast::ident],
tps: ~[@ast::ty]) -> @ast::path;
fn ty_path(span: span, strs: ~[ast::ident], tps: ~[@ast::ty]) -> @ast::ty;
fn ty_fn(span: span,
-input_tys: ~[@ast::ty],
-output: @ast::ty) -> @ast::ty;
fn ty_nil(span: span) -> @ast::ty;
fn expr(span: span, node: ast::expr_) -> @ast::expr;
fn var_ref(span: span, name: ast::ident) -> @ast::expr;
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk;
fn expr_blk(expr: @ast::expr) -> ast::blk;
fn binder_pat(span: span, nm: ast::ident) -> @ast::pat;
fn stmt(expr: @ast::expr) -> @ast::stmt;
fn alt_stmt(arms: ~[ast::arm], span: span, -v: @ast::expr) -> @ast::stmt;
fn lit_str(span: span, s: @~str) -> @ast::expr;
fn lit_uint(span: span, i: uint) -> @ast::expr;
fn lambda(blk: ast::blk) -> @ast::expr;
fn clone_folder() -> fold::ast_fold;
fn clone(v: @ast::expr) -> @ast::expr;
fn clone_ty(v: @ast::ty) -> @ast::ty;
fn clone_ty_param(v: ast::ty_param) -> ast::ty_param;
fn at(span: span, expr: @ast::expr) -> @ast::expr;
}

impl ext_ctxt: ext_ctxt_helpers {
priv impl ext_ctxt {
fn helper_path(base_path: @ast::path,
helper_name: ~str) -> @ast::path {
let head = vec::init(base_path.idents);
Expand All @@ -162,22 +135,6 @@ impl ext_ctxt: ext_ctxt_helpers {
tail)))]))
}

fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
@{span: span, global: false, idents: strs, rp: None, types: ~[]}
}

fn path_tps(span: span, strs: ~[ast::ident],
tps: ~[@ast::ty]) -> @ast::path {
@{span: span, global: false, idents: strs, rp: None, types: tps}
}

fn ty_path(span: span, strs: ~[ast::ident],
tps: ~[@ast::ty]) -> @ast::ty {
@{id: self.next_id(),
node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()),
span: span}
}

fn ty_fn(span: span,
-input_tys: ~[@ast::ty],
-output: @ast::ty) -> @ast::ty {
Expand All @@ -202,48 +159,10 @@ impl ext_ctxt: ext_ctxt_helpers {
@{id: self.next_id(), node: ast::ty_nil, span: span}
}

fn expr(span: span, node: ast::expr_) -> @ast::expr {
@{id: self.next_id(), callee_id: self.next_id(),
node: node, span: span}
}

fn var_ref(span: span, name: ast::ident) -> @ast::expr {
self.expr(span, ast::expr_path(self.path(span, ~[name])))
}

fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
{node: {view_items: ~[],
stmts: stmts,
expr: None,
id: self.next_id(),
rules: ast::default_blk},
span: span}
}

fn expr_blk(expr: @ast::expr) -> ast::blk {
{node: {view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.next_id(),
rules: ast::default_blk},
span: expr.span}
}

fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
let path = @{span: span, global: false, idents: ~[nm],
rp: None, types: ~[]};
@{id: self.next_id(),
node: ast::pat_ident(ast::bind_by_implicit_ref,
path,
None),
span: span}
}

fn stmt(expr: @ast::expr) -> @ast::stmt {
@{node: ast::stmt_semi(expr, self.next_id()),
span: expr.span}
}

fn alt_stmt(arms: ~[ast::arm],
span: span, -v: @ast::expr) -> @ast::stmt {
self.stmt(
Expand All @@ -252,32 +171,6 @@ impl ext_ctxt: ext_ctxt_helpers {
ast::expr_match(v, arms)))
}

fn lit_str(span: span, s: @~str) -> @ast::expr {
self.expr(
span,
ast::expr_vstore(
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_str(s),
span: span})),
ast::expr_vstore_uniq))
}

fn lit_uint(span: span, i: uint) -> @ast::expr {
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_uint(i as u64, ast::ty_u),
span: span}))
}

fn lambda(blk: ast::blk) -> @ast::expr {
let ext_cx = self;
let blk_e = self.expr(blk.span, ast::expr_block(blk));
#ast{ || $(blk_e) }
}

fn clone_folder() -> fold::ast_fold {
fold::make_fold(@{
new_id: |_id| self.next_id(),
Expand Down
80 changes: 80 additions & 0 deletions src/libsyntax/ext/auto_serialize2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,86 @@ fn expand_auto_deserialize(
}

priv impl ext_ctxt {
fn expr(span: span, node: ast::expr_) -> @ast::expr {
@{id: self.next_id(), callee_id: self.next_id(),
node: node, span: span}
}

fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
@{span: span, global: false, idents: strs, rp: None, types: ~[]}
}

fn path_tps(span: span, strs: ~[ast::ident],
tps: ~[@ast::ty]) -> @ast::path {
@{span: span, global: false, idents: strs, rp: None, types: tps}
}

fn ty_path(span: span, strs: ~[ast::ident],
tps: ~[@ast::ty]) -> @ast::ty {
@{id: self.next_id(),
node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()),
span: span}
}

fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
let path = @{span: span, global: false, idents: ~[nm],
rp: None, types: ~[]};
@{id: self.next_id(),
node: ast::pat_ident(ast::bind_by_implicit_ref,
path,
None),
span: span}
}

fn stmt(expr: @ast::expr) -> @ast::stmt {
@{node: ast::stmt_semi(expr, self.next_id()),
span: expr.span}
}

fn lit_str(span: span, s: @~str) -> @ast::expr {
self.expr(
span,
ast::expr_vstore(
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_str(s),
span: span})),
ast::expr_vstore_uniq))
}

fn lit_uint(span: span, i: uint) -> @ast::expr {
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_uint(i as u64, ast::ty_u),
span: span}))
}

fn lambda(blk: ast::blk) -> @ast::expr {
let ext_cx = self;
let blk_e = self.expr(blk.span, ast::expr_block(blk));
#ast{ || $(blk_e) }
}

fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
{node: {view_items: ~[],
stmts: stmts,
expr: None,
id: self.next_id(),
rules: ast::default_blk},
span: span}
}

fn expr_blk(expr: @ast::expr) -> ast::blk {
{node: {view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.next_id(),
rules: ast::default_blk},
span: expr.span}
}

fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr {
self.expr(span, ast::expr_path(self.path(span, strs)))
}
Expand Down
64 changes: 64 additions & 0 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum syntax_extension {

// A temporary hard-coded map of methods for expanding syntax extension
// AST nodes into full ASTs
#[cfg(stage0)]
fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
fn builtin(f: syntax_expander_) -> syntax_extension
{normal({expander: f, span: None})}
Expand Down Expand Up @@ -122,6 +123,69 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
return syntax_expanders;
}

#[cfg(stage1)]
#[cfg(stage2)]
fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
fn builtin(f: syntax_expander_) -> syntax_extension
{normal({expander: f, span: None})}
fn builtin_expr_tt(f: syntax_expander_tt_) -> syntax_extension {
expr_tt({expander: f, span: None})
}
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
item_tt({expander: f, span: None})
}
let syntax_expanders = HashMap();
syntax_expanders.insert(~"macro",
macro_defining(ext::simplext::add_new_extension));
syntax_expanders.insert(~"macro_rules",
builtin_item_tt(
ext::tt::macro_rules::add_new_extension));
syntax_expanders.insert(~"fmt", builtin(ext::fmt::expand_syntax_ext));
syntax_expanders.insert(
~"auto_serialize",
item_decorator(ext::auto_serialize2::expand_auto_serialize));
syntax_expanders.insert(
~"auto_deserialize",
item_decorator(ext::auto_serialize2::expand_auto_deserialize));
syntax_expanders.insert(
~"auto_serialize2",
item_decorator(ext::auto_serialize2::expand_auto_serialize));
syntax_expanders.insert(
~"auto_deserialize2",
item_decorator(ext::auto_serialize2::expand_auto_deserialize));
syntax_expanders.insert(~"env", builtin(ext::env::expand_syntax_ext));
syntax_expanders.insert(~"concat_idents",
builtin(ext::concat_idents::expand_syntax_ext));
syntax_expanders.insert(~"ident_to_str",
builtin(ext::ident_to_str::expand_syntax_ext));
syntax_expanders.insert(~"log_syntax",
builtin_expr_tt(
ext::log_syntax::expand_syntax_ext));
syntax_expanders.insert(~"ast",
builtin(ext::qquote::expand_ast));
syntax_expanders.insert(~"line",
builtin(ext::source_util::expand_line));
syntax_expanders.insert(~"col",
builtin(ext::source_util::expand_col));
syntax_expanders.insert(~"file",
builtin(ext::source_util::expand_file));
syntax_expanders.insert(~"stringify",
builtin(ext::source_util::expand_stringify));
syntax_expanders.insert(~"include",
builtin(ext::source_util::expand_include));
syntax_expanders.insert(~"include_str",
builtin(ext::source_util::expand_include_str));
syntax_expanders.insert(~"include_bin",
builtin(ext::source_util::expand_include_bin));
syntax_expanders.insert(~"module_path",
builtin(ext::source_util::expand_mod));
syntax_expanders.insert(~"proto",
builtin_item_tt(ext::pipes::expand_proto));
syntax_expanders.insert(
~"trace_macros",
builtin_expr_tt(ext::trace_macros::expand_trace_macros));
return syntax_expanders;
}

// One of these is made during expansion and incrementally updated as we go;
// when a macro expansion occurs, the resulting nodes have the backtrace()
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/syntax.rc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod ext {
mod ident_to_str;
#[legacy_exports]
mod log_syntax;
#[cfg(stage0)]
#[legacy_exports]
mod auto_serialize;
#[legacy_exports]
Expand Down
Loading