Skip to content

Commit 9cced55

Browse files
committed
syntax: remove all remaining uses of #ast, and #ast / qquote itself.
1 parent 80d6bc8 commit 9cced55

File tree

11 files changed

+95
-466
lines changed

11 files changed

+95
-466
lines changed

src/librustc/middle/astencode.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
10331033
trait fake_ext_ctxt {
10341034
fn cfg() -> ast::crate_cfg;
10351035
fn parse_sess() -> parse::parse_sess;
1036+
fn call_site() -> span;
1037+
fn ident_of(st: ~str) -> ast::ident;
10361038
}
10371039

10381040
#[cfg(test)]
@@ -1042,6 +1044,16 @@ type fake_session = parse::parse_sess;
10421044
impl fake_session: fake_ext_ctxt {
10431045
fn cfg() -> ast::crate_cfg { ~[] }
10441046
fn parse_sess() -> parse::parse_sess { self }
1047+
fn call_site() -> span {
1048+
codemap::span {
1049+
lo: codemap::BytePos(0),
1050+
hi: codemap::BytePos(0),
1051+
expn_info: None
1052+
}
1053+
}
1054+
fn ident_of(st: ~str) -> ast::ident {
1055+
self.interner.intern(@st)
1056+
}
10451057
}
10461058

10471059
#[cfg(test)]
@@ -1050,7 +1062,8 @@ fn mk_ctxt() -> fake_ext_ctxt {
10501062
}
10511063

10521064
#[cfg(test)]
1053-
fn roundtrip(in_item: @ast::item) {
1065+
fn roundtrip(in_item: Option<@ast::item>) {
1066+
let in_item = in_item.get();
10541067
let bytes = do io::with_bytes_writer |wr| {
10551068
let ebml_w = writer::Serializer(wr);
10561069
encode_item_ast(ebml_w, in_item);
@@ -1074,45 +1087,45 @@ fn roundtrip(in_item: @ast::item) {
10741087
#[test]
10751088
fn test_basic() {
10761089
let ext_cx = mk_ctxt();
1077-
roundtrip(#ast[item]{
1090+
roundtrip(quote_item!(
10781091
fn foo() {}
1079-
});
1092+
));
10801093
}
10811094

10821095
#[test]
10831096
fn test_smalltalk() {
10841097
let ext_cx = mk_ctxt();
1085-
roundtrip(#ast[item]{
1098+
roundtrip(quote_item!(
10861099
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
1087-
});
1100+
));
10881101
}
10891102

10901103
#[test]
10911104
fn test_more() {
10921105
let ext_cx = mk_ctxt();
1093-
roundtrip(#ast[item]{
1106+
roundtrip(quote_item!(
10941107
fn foo(x: uint, y: uint) -> uint {
10951108
let z = x + y;
10961109
return z;
10971110
}
1098-
});
1111+
));
10991112
}
11001113

11011114
#[test]
11021115
fn test_simplification() {
11031116
let ext_cx = mk_ctxt();
1104-
let item_in = ast::ii_item(#ast[item] {
1117+
let item_in = ast::ii_item(quote_item!(
11051118
fn new_int_alist<B: Copy>() -> alist<int, B> {
11061119
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
11071120
return {eq_fn: eq_int, mut data: ~[]};
11081121
}
1109-
});
1122+
).get());
11101123
let item_out = simplify_ast(item_in);
1111-
let item_exp = ast::ii_item(#ast[item] {
1124+
let item_exp = ast::ii_item(quote_item!(
11121125
fn new_int_alist<B: Copy>() -> alist<int, B> {
11131126
return {eq_fn: eq_int, mut data: ~[]};
11141127
}
1115-
});
1128+
).get());
11161129
match (item_out, item_exp) {
11171130
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
11181131
assert pprust::item_to_str(item_out, ext_cx.parse_sess().interner)

src/libsyntax/ext/auto_serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ priv impl ext_ctxt {
309309
fn lambda(blk: ast::blk) -> @ast::expr {
310310
let ext_cx = self;
311311
let blk_e = self.expr(blk.span, ast::expr_block(blk));
312-
#ast{ || $(blk_e) }
312+
quote_expr!( || $blk_e )
313313
}
314314

315315
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {

src/libsyntax/ext/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
109109
syntax_expanders.insert(~"log_syntax",
110110
builtin_normal_tt(
111111
ext::log_syntax::expand_syntax_ext));
112-
syntax_expanders.insert(~"ast",
113-
builtin(ext::qquote::expand_ast));
114112
syntax_expanders.insert(~"deriving_eq",
115113
item_decorator(
116114
ext::deriving::expand_deriving_eq));

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ast::{crate, expr_, expr_mac, mac_invoc, mac_invoc_tt,
1414
tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
1515
use fold::*;
1616
use ext::base::*;
17-
use ext::qquote::{qq_helper};
1817
use parse::{parser, parse_expr_from_source_str, new_parser_from_tts};
1918

2019

@@ -169,7 +168,12 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
169168
None | Some(normal(_)) | Some(macro_defining(_))
170169
| Some(normal_tt(_)) | Some(item_tt(*)) => items,
171170
Some(item_decorator(dec_fn)) => {
172-
dec_fn(cx, attr.span, attr.node.value, items)
171+
cx.bt_push(ExpandedFrom({call_site: attr.span,
172+
callie: {name: copy mname,
173+
span: None}}));
174+
let r = dec_fn(cx, attr.span, attr.node.value, items);
175+
cx.bt_pop();
176+
r
173177
}
174178
}
175179
}

0 commit comments

Comments
 (0)