syntax/ext: Remove the trait-object indirection of the ext_ctxt object.
This commit is contained in:
parent
8e9eba8013
commit
eea265ea16
|
@ -202,131 +202,107 @@ 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 struct ext_ctxt {
|
||||
parse_sess: @mut parse::ParseSess,
|
||||
cfg: ast::crate_cfg,
|
||||
backtrace: @mut Option<@ExpnInfo>,
|
||||
|
||||
// These two @mut's should really not be here,
|
||||
// but the self types for CtxtRepr are all wrong
|
||||
// and there are bugs in the code for object
|
||||
// types that make this hard to get right at the
|
||||
// moment. - nmatsakis
|
||||
mod_path: @mut ~[ast::ident],
|
||||
trace_mac: @mut bool
|
||||
}
|
||||
|
||||
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
|
||||
-> @ext_ctxt {
|
||||
struct CtxtRepr {
|
||||
parse_sess: @mut parse::ParseSess,
|
||||
cfg: ast::crate_cfg,
|
||||
backtrace: @mut Option<@ExpnInfo>,
|
||||
|
||||
// These two @mut's should really not be here,
|
||||
// but the self types for CtxtRepr are all wrong
|
||||
// and there are bugs in the code for object
|
||||
// types that make this hard to get right at the
|
||||
// moment. - nmatsakis
|
||||
mod_path: @mut ~[ast::ident],
|
||||
trace_mac: @mut bool
|
||||
}
|
||||
impl ext_ctxt for CtxtRepr {
|
||||
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 }
|
||||
fn call_site(&self) -> span {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
|
||||
None => self.bug("missing top span")
|
||||
}
|
||||
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 }
|
||||
fn call_site(&self) -> span {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
|
||||
None => self.bug("missing top span")
|
||||
}
|
||||
fn print_backtrace(&self) { }
|
||||
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
|
||||
fn mod_pop(&self) { self.mod_path.pop(); }
|
||||
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
|
||||
fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
|
||||
}
|
||||
fn print_backtrace(&self) { }
|
||||
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
|
||||
fn mod_pop(&self) { self.mod_path.pop(); }
|
||||
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
|
||||
fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
|
||||
*self.backtrace =
|
||||
Some(@ExpandedFrom(CallInfo {
|
||||
call_site: span {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: *self.backtrace},
|
||||
callee: copy *callee}));
|
||||
}
|
||||
}
|
||||
}
|
||||
fn bt_pop(&self) {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {
|
||||
call_site: span {expn_info: prev, _}, _
|
||||
})) => {
|
||||
*self.backtrace = prev
|
||||
}
|
||||
_ => self.bug("tried to pop without a push")
|
||||
}
|
||||
}
|
||||
fn span_fatal(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
|
||||
}
|
||||
fn span_err(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_err(sp, msg);
|
||||
}
|
||||
fn span_warn(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_warn(sp, msg);
|
||||
}
|
||||
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
|
||||
}
|
||||
fn span_bug(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||
}
|
||||
fn bug(&self, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
fn next_id(&self) -> ast::node_id {
|
||||
return parse::next_node_id(self.parse_sess);
|
||||
}
|
||||
fn trace_macros(&self) -> bool {
|
||||
*self.trace_mac
|
||||
}
|
||||
fn set_trace_macros(&self, x: bool) {
|
||||
*self.trace_mac = x
|
||||
}
|
||||
fn str_of(&self, id: ast::ident) -> ~str {
|
||||
copy *self.parse_sess.interner.get(id)
|
||||
}
|
||||
fn ident_of(&self, st: &str) -> ast::ident {
|
||||
self.parse_sess.interner.intern(st)
|
||||
}
|
||||
}
|
||||
let imp: @CtxtRepr = @CtxtRepr {
|
||||
fn bt_pop(&self) {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(
|
||||
CallInfo {
|
||||
call_site: span {expn_info: prev, _}, _
|
||||
})) => {
|
||||
*self.backtrace = prev
|
||||
}
|
||||
_ => self.bug("tried to pop without a push")
|
||||
}
|
||||
}
|
||||
fn span_fatal(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
|
||||
}
|
||||
fn span_err(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_err(sp, msg);
|
||||
}
|
||||
fn span_warn(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_warn(sp, msg);
|
||||
}
|
||||
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
|
||||
}
|
||||
fn span_bug(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||
}
|
||||
fn bug(&self, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
fn next_id(&self) -> ast::node_id {
|
||||
parse::next_node_id(self.parse_sess)
|
||||
}
|
||||
fn trace_macros(&self) -> bool {
|
||||
*self.trace_mac
|
||||
}
|
||||
fn set_trace_macros(&self, x: bool) {
|
||||
*self.trace_mac = x
|
||||
}
|
||||
fn str_of(&self, id: ast::ident) -> ~str {
|
||||
copy *self.parse_sess.interner.get(id)
|
||||
}
|
||||
fn ident_of(&self, st: &str) -> ast::ident {
|
||||
self.parse_sess.interner.intern(st)
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue