Skip to content

Commit eea265e

Browse files
committed
syntax/ext: Remove the trait-object indirection of the ext_ctxt object.
1 parent 8e9eba8 commit eea265e

File tree

1 file changed

+82
-106
lines changed

1 file changed

+82
-106
lines changed

src/libsyntax/ext/base.rs

Lines changed: 82 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -202,131 +202,107 @@ 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 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;
205+
pub struct ext_ctxt {
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
229217
}
230218

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-
}
219+
pub impl ext_ctxt {
220+
fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
221+
fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
222+
fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
223+
fn call_site(&self) -> span {
224+
match *self.backtrace {
225+
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
226+
None => self.bug("missing top span")
255227
}
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}) => {
228+
}
229+
fn print_backtrace(&self) { }
230+
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
231+
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
232+
fn mod_pop(&self) { self.mod_path.pop(); }
233+
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
234+
fn bt_push(&self, ei: codemap::ExpnInfo) {
235+
match ei {
236+
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
264237
*self.backtrace =
265238
Some(@ExpandedFrom(CallInfo {
266239
call_site: span {lo: cs.lo, hi: cs.hi,
267240
expn_info: *self.backtrace},
268241
callee: copy *callee}));
269-
}
270242
}
271243
}
272-
fn bt_pop(&self) {
273-
match *self.backtrace {
274-
Some(@ExpandedFrom(CallInfo {
275-
call_site: span {expn_info: prev, _}, _
276-
})) => {
244+
}
245+
fn bt_pop(&self) {
246+
match *self.backtrace {
247+
Some(@ExpandedFrom(
248+
CallInfo {
249+
call_site: span {expn_info: prev, _}, _
250+
})) => {
277251
*self.backtrace = prev
278-
}
279-
_ => self.bug("tried to pop without a push")
280252
}
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)
253+
_ => self.bug("tried to pop without a push")
320254
}
321255
}
322-
let imp: @CtxtRepr = @CtxtRepr {
256+
fn span_fatal(&self, sp: span, msg: &str) -> ! {
257+
self.print_backtrace();
258+
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
259+
}
260+
fn span_err(&self, sp: span, msg: &str) {
261+
self.print_backtrace();
262+
self.parse_sess.span_diagnostic.span_err(sp, msg);
263+
}
264+
fn span_warn(&self, sp: span, msg: &str) {
265+
self.print_backtrace();
266+
self.parse_sess.span_diagnostic.span_warn(sp, msg);
267+
}
268+
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
269+
self.print_backtrace();
270+
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
271+
}
272+
fn span_bug(&self, sp: span, msg: &str) -> ! {
273+
self.print_backtrace();
274+
self.parse_sess.span_diagnostic.span_bug(sp, msg);
275+
}
276+
fn bug(&self, msg: &str) -> ! {
277+
self.print_backtrace();
278+
self.parse_sess.span_diagnostic.handler().bug(msg);
279+
}
280+
fn next_id(&self) -> ast::node_id {
281+
parse::next_node_id(self.parse_sess)
282+
}
283+
fn trace_macros(&self) -> bool {
284+
*self.trace_mac
285+
}
286+
fn set_trace_macros(&self, x: bool) {
287+
*self.trace_mac = x
288+
}
289+
fn str_of(&self, id: ast::ident) -> ~str {
290+
copy *self.parse_sess.interner.get(id)
291+
}
292+
fn ident_of(&self, st: &str) -> ast::ident {
293+
self.parse_sess.interner.intern(st)
294+
}
295+
}
296+
297+
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
298+
-> @ext_ctxt {
299+
@ext_ctxt {
323300
parse_sess: parse_sess,
324301
cfg: cfg,
325302
backtrace: @mut None,
326303
mod_path: @mut ~[],
327304
trace_mac: @mut false
328-
};
329-
((imp) as @ext_ctxt)
305+
}
330306
}
331307

332308
pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str {

0 commit comments

Comments
 (0)