1
Fork 0

syntax/ext: Remove the trait-object indirection of the ext_ctxt object.

This commit is contained in:
Huon Wilson 2013-05-17 20:10:26 +10:00
parent 8e9eba8013
commit eea265ea16

View file

@ -202,35 +202,7 @@ pub fn syntax_expander_table() -> SyntaxEnv {
// One of these is made during expansion and incrementally updated as we go;
// when a macro expansion occurs, the resulting nodes have the backtrace()
// -> expn_info of their expansion context stored into their span.
pub trait ext_ctxt {
fn codemap(&self) -> @CodeMap;
fn parse_sess(&self) -> @mut parse::ParseSess;
fn cfg(&self) -> ast::crate_cfg;
fn call_site(&self) -> span;
fn print_backtrace(&self);
fn backtrace(&self) -> Option<@ExpnInfo>;
fn mod_push(&self, mod_name: ast::ident);
fn mod_pop(&self);
fn mod_path(&self) -> ~[ast::ident];
fn bt_push(&self, ei: codemap::ExpnInfo);
fn bt_pop(&self);
fn span_fatal(&self, sp: span, msg: &str) -> !;
fn span_err(&self, sp: span, msg: &str);
fn span_warn(&self, sp: span, msg: &str);
fn span_unimpl(&self, sp: span, msg: &str) -> !;
fn span_bug(&self, sp: span, msg: &str) -> !;
fn bug(&self, msg: &str) -> !;
fn next_id(&self) -> ast::node_id;
fn trace_macros(&self) -> bool;
fn set_trace_macros(&self, x: bool);
/* for unhygienic identifier transformation */
fn str_of(&self, id: ast::ident) -> ~str;
fn ident_of(&self, st: &str) -> ast::ident;
}
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
-> @ext_ctxt {
struct CtxtRepr {
pub struct ext_ctxt {
parse_sess: @mut parse::ParseSess,
cfg: ast::crate_cfg,
backtrace: @mut Option<@ExpnInfo>,
@ -242,8 +214,9 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
// moment. - nmatsakis
mod_path: @mut ~[ast::ident],
trace_mac: @mut bool
}
impl ext_ctxt for CtxtRepr {
}
pub impl ext_ctxt {
fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
@ -271,7 +244,8 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
}
fn bt_pop(&self) {
match *self.backtrace {
Some(@ExpandedFrom(CallInfo {
Some(@ExpandedFrom(
CallInfo {
call_site: span {expn_info: prev, _}, _
})) => {
*self.backtrace = prev
@ -304,7 +278,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
self.parse_sess.span_diagnostic.handler().bug(msg);
}
fn next_id(&self) -> ast::node_id {
return parse::next_node_id(self.parse_sess);
parse::next_node_id(self.parse_sess)
}
fn trace_macros(&self) -> bool {
*self.trace_mac
@ -318,15 +292,17 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
fn ident_of(&self, st: &str) -> ast::ident {
self.parse_sess.interner.intern(st)
}
}
let imp: @CtxtRepr = @CtxtRepr {
}
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
-> @ext_ctxt {
@ext_ctxt {
parse_sess: parse_sess,
cfg: cfg,
backtrace: @mut None,
mod_path: @mut ~[],
trace_mac: @mut false
};
((imp) as @ext_ctxt)
}
}
pub fn expr_to_str(cx: @ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str {