Skip to content

Commit 65fdc6f

Browse files
committed
---
yaml --- r: 73335 b: refs/heads/dist-snap c: 743e4b0 h: refs/heads/master i: 73333: 9175e8d 73331: 9ff3780 73327: bedf586 v: v3
1 parent 1834bd2 commit 65fdc6f

38 files changed

+2262
-1679
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: 64963d6cbaea86e0d2a58f507e57a76da7512e3e
10+
refs/heads/dist-snap: 743e4b044c0ed6e6b323eff7e4d07299fa59e1fb
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::ast_util::*;
1717
use syntax::attr;
1818
use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
1919
use syntax::codemap;
20-
use syntax::ext::base::ExtCtxt;
20+
use syntax::ext::base::{mk_ctxt, ext_ctxt};
2121
use syntax::fold;
2222
use syntax::print::pprust;
2323
use syntax::{ast, ast_util};
@@ -36,7 +36,7 @@ struct TestCtxt {
3636
sess: session::Session,
3737
crate: @ast::crate,
3838
path: ~[ast::ident],
39-
ext_cx: @ExtCtxt,
39+
ext_cx: @ext_ctxt,
4040
testfns: ~[Test]
4141
}
4242

@@ -64,7 +64,7 @@ fn generate_test_harness(sess: session::Session,
6464
let cx: @mut TestCtxt = @mut TestCtxt {
6565
sess: sess,
6666
crate: crate,
67-
ext_cx: ExtCtxt::new(sess.parse_sess, copy sess.opts.cfg),
67+
ext_cx: mk_ctxt(sess.parse_sess, copy sess.opts.cfg),
6868
path: ~[],
6969
testfns: ~[]
7070
};

branches/dist-snap/src/librustpkg/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::semver;
1919
use std::term;
2020
use syntax::ast_util::*;
2121
use syntax::codemap::{dummy_sp, spanned, dummy_spanned};
22-
use syntax::ext::base::ExtCtxt;
22+
use syntax::ext::base::{mk_ctxt, ext_ctxt};
2323
use syntax::{ast, attr, codemap, diagnostic, fold};
2424
use syntax::ast::{meta_name_value, meta_list};
2525
use syntax::attr::{mk_attr};
@@ -178,7 +178,7 @@ struct ListenerFn {
178178
struct ReadyCtx {
179179
sess: session::Session,
180180
crate: @ast::crate,
181-
ext_cx: @ExtCtxt,
181+
ext_cx: @ext_ctxt,
182182
path: ~[ast::ident],
183183
fns: ~[ListenerFn]
184184
}
@@ -247,7 +247,7 @@ pub fn ready_crate(sess: session::Session,
247247
let ctx = @mut ReadyCtx {
248248
sess: sess,
249249
crate: crate,
250-
ext_cx: ExtCtxt::new(sess.parse_sess, copy sess.opts.cfg),
250+
ext_cx: mk_ctxt(sess.parse_sess, copy sess.opts.cfg),
251251
path: ~[],
252252
fns: ~[]
253253
};

branches/dist-snap/src/libsyntax/ext/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn next_state(s: State) -> Option<State> {
3737
}
3838
}
3939

40-
pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
40+
pub fn expand_asm(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree])
4141
-> base::MacResult {
4242
let p = parse::new_parser_from_tts(cx.parse_sess(),
4343
cx.cfg(),

branches/dist-snap/src/libsyntax/ext/auto_encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use codemap::span;
1515
use ext::base::*;
1616

1717
pub fn expand_auto_encode(
18-
cx: @ExtCtxt,
18+
cx: @ext_ctxt,
1919
span: span,
2020
_mitem: @ast::meta_item,
2121
in_items: ~[@ast::item]
@@ -25,7 +25,7 @@ pub fn expand_auto_encode(
2525
}
2626

2727
pub fn expand_auto_decode(
28-
cx: @ExtCtxt,
28+
cx: @ext_ctxt,
2929
span: span,
3030
_mitem: @ast::meta_item,
3131
in_items: ~[@ast::item]

branches/dist-snap/src/libsyntax/ext/base.rs

Lines changed: 119 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct MacroDef {
3333
ext: SyntaxExtension
3434
}
3535

36-
pub type ItemDecorator = @fn(@ExtCtxt,
36+
pub type ItemDecorator = @fn(@ext_ctxt,
3737
span,
3838
@ast::meta_item,
3939
~[@ast::item])
@@ -44,7 +44,7 @@ pub struct SyntaxExpanderTT {
4444
span: Option<span>
4545
}
4646

47-
pub type SyntaxExpanderTTFun = @fn(@ExtCtxt,
47+
pub type SyntaxExpanderTTFun = @fn(@ext_ctxt,
4848
span,
4949
&[ast::token_tree])
5050
-> MacResult;
@@ -54,7 +54,7 @@ pub struct SyntaxExpanderTTItem {
5454
span: Option<span>
5555
}
5656

57-
pub type SyntaxExpanderTTItemFun = @fn(@ExtCtxt,
57+
pub type SyntaxExpanderTTItemFun = @fn(@ext_ctxt,
5858
span,
5959
ast::ident,
6060
~[ast::token_tree])
@@ -202,109 +202,134 @@ pub fn syntax_expander_table() -> SyntaxEnv {
202202
// One of these is made during expansion and incrementally updated as we go;
203203
// when a macro expansion occurs, the resulting nodes have the backtrace()
204204
// -> expn_info of their expansion context stored into their span.
205-
pub struct ExtCtxt {
206-
parse_sess: @mut parse::ParseSess,
207-
cfg: ast::crate_cfg,
208-
backtrace: @mut Option<@ExpnInfo>,
209-
210-
// These two @mut's should really not be here,
211-
// but the self types for CtxtRepr are all wrong
212-
// and there are bugs in the code for object
213-
// types that make this hard to get right at the
214-
// moment. - nmatsakis
215-
mod_path: @mut ~[ast::ident],
216-
trace_mac: @mut bool
205+
pub trait ext_ctxt {
206+
fn codemap(&self) -> @CodeMap;
207+
fn parse_sess(&self) -> @mut parse::ParseSess;
208+
fn cfg(&self) -> ast::crate_cfg;
209+
fn call_site(&self) -> span;
210+
fn print_backtrace(&self);
211+
fn backtrace(&self) -> Option<@ExpnInfo>;
212+
fn mod_push(&self, mod_name: ast::ident);
213+
fn mod_pop(&self);
214+
fn mod_path(&self) -> ~[ast::ident];
215+
fn bt_push(&self, ei: codemap::ExpnInfo);
216+
fn bt_pop(&self);
217+
fn span_fatal(&self, sp: span, msg: &str) -> !;
218+
fn span_err(&self, sp: span, msg: &str);
219+
fn span_warn(&self, sp: span, msg: &str);
220+
fn span_unimpl(&self, sp: span, msg: &str) -> !;
221+
fn span_bug(&self, sp: span, msg: &str) -> !;
222+
fn bug(&self, msg: &str) -> !;
223+
fn next_id(&self) -> ast::node_id;
224+
fn trace_macros(&self) -> bool;
225+
fn set_trace_macros(&self, x: bool);
226+
/* for unhygienic identifier transformation */
227+
fn str_of(&self, id: ast::ident) -> ~str;
228+
fn ident_of(&self, st: &str) -> ast::ident;
217229
}
218230

219-
pub impl ExtCtxt {
220-
fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) -> @ExtCtxt {
221-
@ExtCtxt {
222-
parse_sess: parse_sess,
223-
cfg: cfg,
224-
backtrace: @mut None,
225-
mod_path: @mut ~[],
226-
trace_mac: @mut false
227-
}
228-
}
229-
230-
fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
231-
fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
232-
fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
233-
fn call_site(&self) -> span {
234-
match *self.backtrace {
235-
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
236-
None => self.bug("missing top span")
231+
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
232+
-> @ext_ctxt {
233+
struct CtxtRepr {
234+
parse_sess: @mut parse::ParseSess,
235+
cfg: ast::crate_cfg,
236+
backtrace: @mut Option<@ExpnInfo>,
237+
238+
// These two @mut's should really not be here,
239+
// but the self types for CtxtRepr are all wrong
240+
// and there are bugs in the code for object
241+
// types that make this hard to get right at the
242+
// moment. - nmatsakis
243+
mod_path: @mut ~[ast::ident],
244+
trace_mac: @mut bool
245+
}
246+
impl ext_ctxt for CtxtRepr {
247+
fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
248+
fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
249+
fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
250+
fn call_site(&self) -> span {
251+
match *self.backtrace {
252+
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
253+
None => self.bug("missing top span")
254+
}
237255
}
238-
}
239-
fn print_backtrace(&self) { }
240-
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
241-
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
242-
fn mod_pop(&self) { self.mod_path.pop(); }
243-
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
244-
fn bt_push(&self, ei: codemap::ExpnInfo) {
245-
match ei {
246-
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
256+
fn print_backtrace(&self) { }
257+
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
258+
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
259+
fn mod_pop(&self) { self.mod_path.pop(); }
260+
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
261+
fn bt_push(&self, ei: codemap::ExpnInfo) {
262+
match ei {
263+
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
247264
*self.backtrace =
248265
Some(@ExpandedFrom(CallInfo {
249266
call_site: span {lo: cs.lo, hi: cs.hi,
250267
expn_info: *self.backtrace},
251268
callee: copy *callee}));
269+
}
252270
}
253271
}
254-
}
255-
fn bt_pop(&self) {
256-
match *self.backtrace {
257-
Some(@ExpandedFrom(
258-
CallInfo {
259-
call_site: span {expn_info: prev, _}, _
260-
})) => {
272+
fn bt_pop(&self) {
273+
match *self.backtrace {
274+
Some(@ExpandedFrom(CallInfo {
275+
call_site: span {expn_info: prev, _}, _
276+
})) => {
261277
*self.backtrace = prev
278+
}
279+
_ => self.bug("tried to pop without a push")
262280
}
263-
_ => self.bug("tried to pop without a push")
281+
}
282+
fn span_fatal(&self, sp: span, msg: &str) -> ! {
283+
self.print_backtrace();
284+
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
285+
}
286+
fn span_err(&self, sp: span, msg: &str) {
287+
self.print_backtrace();
288+
self.parse_sess.span_diagnostic.span_err(sp, msg);
289+
}
290+
fn span_warn(&self, sp: span, msg: &str) {
291+
self.print_backtrace();
292+
self.parse_sess.span_diagnostic.span_warn(sp, msg);
293+
}
294+
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
295+
self.print_backtrace();
296+
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
297+
}
298+
fn span_bug(&self, sp: span, msg: &str) -> ! {
299+
self.print_backtrace();
300+
self.parse_sess.span_diagnostic.span_bug(sp, msg);
301+
}
302+
fn bug(&self, msg: &str) -> ! {
303+
self.print_backtrace();
304+
self.parse_sess.span_diagnostic.handler().bug(msg);
305+
}
306+
fn next_id(&self) -> ast::node_id {
307+
return parse::next_node_id(self.parse_sess);
308+
}
309+
fn trace_macros(&self) -> bool {
310+
*self.trace_mac
311+
}
312+
fn set_trace_macros(&self, x: bool) {
313+
*self.trace_mac = x
314+
}
315+
fn str_of(&self, id: ast::ident) -> ~str {
316+
copy *self.parse_sess.interner.get(id)
317+
}
318+
fn ident_of(&self, st: &str) -> ast::ident {
319+
self.parse_sess.interner.intern(st)
264320
}
265321
}
266-
fn span_fatal(&self, sp: span, msg: &str) -> ! {
267-
self.print_backtrace();
268-
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
269-
}
270-
fn span_err(&self, sp: span, msg: &str) {
271-
self.print_backtrace();
272-
self.parse_sess.span_diagnostic.span_err(sp, msg);
273-
}
274-
fn span_warn(&self, sp: span, msg: &str) {
275-
self.print_backtrace();
276-
self.parse_sess.span_diagnostic.span_warn(sp, msg);
277-
}
278-
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
279-
self.print_backtrace();
280-
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
281-
}
282-
fn span_bug(&self, sp: span, msg: &str) -> ! {
283-
self.print_backtrace();
284-
self.parse_sess.span_diagnostic.span_bug(sp, msg);
285-
}
286-
fn bug(&self, msg: &str) -> ! {
287-
self.print_backtrace();
288-
self.parse_sess.span_diagnostic.handler().bug(msg);
289-
}
290-
fn next_id(&self) -> ast::node_id {
291-
parse::next_node_id(self.parse_sess)
292-
}
293-
fn trace_macros(&self) -> bool {
294-
*self.trace_mac
295-
}
296-
fn set_trace_macros(&self, x: bool) {
297-
*self.trace_mac = x
298-
}
299-
fn str_of(&self, id: ast::ident) -> ~str {
300-
copy *self.parse_sess.interner.get(id)
301-
}
302-
fn ident_of(&self, st: &str) -> ast::ident {
303-
self.parse_sess.interner.intern(st)
304-
}
322+
let imp: @CtxtRepr = @CtxtRepr {
323+
parse_sess: parse_sess,
324+
cfg: cfg,
325+
backtrace: @mut None,
326+
mod_path: @mut ~[],
327+
trace_mac: @mut false
328+
};
329+
((imp) as @ext_ctxt)
305330
}
306331

307-
pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::expr, err_msg: ~str) -> ~str {
332+
pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str {
308333
match expr.node {
309334
ast::expr_lit(l) => match l.node {
310335
ast::lit_str(s) => copy *s,
@@ -314,7 +339,7 @@ pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::expr, err_msg: ~str) -> ~str {
314339
}
315340
}
316341

317-
pub fn expr_to_ident(cx: @ExtCtxt,
342+
pub fn expr_to_ident(cx: @ext_ctxt,
318343
expr: @ast::expr,
319344
err_msg: &str) -> ast::ident {
320345
match expr.node {
@@ -328,14 +353,14 @@ pub fn expr_to_ident(cx: @ExtCtxt,
328353
}
329354
}
330355

331-
pub fn check_zero_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree],
356+
pub fn check_zero_tts(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree],
332357
name: &str) {
333358
if tts.len() != 0 {
334359
cx.span_fatal(sp, fmt!("%s takes no arguments", name));
335360
}
336361
}
337362

338-
pub fn get_single_str_from_tts(cx: @ExtCtxt,
363+
pub fn get_single_str_from_tts(cx: @ext_ctxt,
339364
sp: span,
340365
tts: &[ast::token_tree],
341366
name: &str) -> ~str {
@@ -350,7 +375,7 @@ pub fn get_single_str_from_tts(cx: @ExtCtxt,
350375
}
351376
}
352377

353-
pub fn get_exprs_from_tts(cx: @ExtCtxt, tts: &[ast::token_tree])
378+
pub fn get_exprs_from_tts(cx: @ext_ctxt, tts: &[ast::token_tree])
354379
-> ~[@ast::expr] {
355380
let p = parse::new_parser_from_tts(cx.parse_sess(),
356381
cx.cfg(),

0 commit comments

Comments
 (0)