Do not rely on newtype enum dereference
This commit is contained in:
parent
c9b9462e8f
commit
2e65782c17
5 changed files with 29 additions and 37 deletions
|
@ -17,7 +17,7 @@ use front::config;
|
|||
use std::vec;
|
||||
use syntax::ast_util::*;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
|
||||
use syntax::codemap::{dummy_sp, span, ExpnInfo, NameAndSpan};
|
||||
use syntax::codemap;
|
||||
use syntax::ext::base::ExtCtxt;
|
||||
use syntax::fold;
|
||||
|
@ -72,13 +72,13 @@ fn generate_test_harness(sess: session::Session,
|
|||
};
|
||||
|
||||
let ext_cx = cx.ext_cx;
|
||||
ext_cx.bt_push(ExpandedFrom(CallInfo {
|
||||
ext_cx.bt_push(ExpnInfo {
|
||||
call_site: dummy_sp(),
|
||||
callee: NameAndSpan {
|
||||
name: @"test",
|
||||
span: None
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
let precursor = @fold::AstFoldFns {
|
||||
fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),
|
||||
|
|
|
@ -174,16 +174,11 @@ pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
|
|||
#[deriving(IterBytes)]
|
||||
pub struct NameAndSpan {name: @str, span: Option<span>}
|
||||
|
||||
#[deriving(IterBytes)]
|
||||
pub struct CallInfo {
|
||||
call_site: span,
|
||||
callee: NameAndSpan
|
||||
}
|
||||
|
||||
/// Extra information for tracking macro expansion of spans
|
||||
#[deriving(IterBytes)]
|
||||
pub enum ExpnInfo {
|
||||
ExpandedFrom(CallInfo)
|
||||
pub struct ExpnInfo {
|
||||
call_site: span,
|
||||
callee: NameAndSpan
|
||||
}
|
||||
|
||||
pub type FileName = @str;
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
use ast;
|
||||
use ast::Name;
|
||||
use codemap;
|
||||
use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom};
|
||||
use codemap::CallInfo;
|
||||
use codemap::{CodeMap, span, ExpnInfo};
|
||||
use diagnostic::span_handler;
|
||||
use ext;
|
||||
use parse;
|
||||
|
@ -243,7 +242,7 @@ impl ExtCtxt {
|
|||
pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
|
||||
pub fn call_site(&self) -> span {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
|
||||
Some(@ExpnInfo {call_site: cs, _}) => cs,
|
||||
None => self.bug("missing top span")
|
||||
}
|
||||
}
|
||||
|
@ -254,21 +253,19 @@ impl ExtCtxt {
|
|||
pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
|
||||
pub fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
|
||||
ExpnInfo {call_site: cs, callee: ref callee} => {
|
||||
*self.backtrace =
|
||||
Some(@ExpandedFrom(CallInfo {
|
||||
Some(@ExpnInfo {
|
||||
call_site: span {lo: cs.lo, hi: cs.hi,
|
||||
expn_info: *self.backtrace},
|
||||
callee: copy *callee}));
|
||||
callee: copy *callee});
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn bt_pop(&self) {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(
|
||||
CallInfo {
|
||||
call_site: span {expn_info: prev, _}, _
|
||||
})) => {
|
||||
Some(@ExpnInfo {
|
||||
call_site: span {expn_info: prev, _}, _}) => {
|
||||
*self.backtrace = prev
|
||||
}
|
||||
_ => self.bug("tried to pop without a push")
|
||||
|
|
|
@ -16,7 +16,7 @@ use ast;
|
|||
use ast_util::{new_rename, new_mark, resolve};
|
||||
use attr;
|
||||
use codemap;
|
||||
use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan, spanned};
|
||||
use codemap::{span, ExpnInfo, NameAndSpan, spanned};
|
||||
use ext::base::*;
|
||||
use fold::*;
|
||||
use parse;
|
||||
|
@ -60,13 +60,13 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
expander: exp,
|
||||
span: exp_sp
|
||||
}))) => {
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
cx.bt_push(ExpnInfo {
|
||||
call_site: s,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
span: exp_sp,
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
let expanded = match exp(cx, mac.span, *tts) {
|
||||
MRExpr(e) => e,
|
||||
|
@ -131,13 +131,13 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
|
|||
|
||||
match (*extsbox).find(&intern(mname)) {
|
||||
Some(@SE(ItemDecorator(dec_fn))) => {
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
cx.bt_push(ExpnInfo {
|
||||
call_site: attr.span,
|
||||
callee: NameAndSpan {
|
||||
name: mname,
|
||||
span: None
|
||||
}
|
||||
}));
|
||||
});
|
||||
let r = dec_fn(cx, attr.span, attr.node.value, items);
|
||||
cx.bt_pop();
|
||||
r
|
||||
|
@ -227,13 +227,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
given '%s'", extnamestr,
|
||||
ident_to_str(&it.ident)));
|
||||
}
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
cx.bt_push(ExpnInfo {
|
||||
call_site: it.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
span: expand.span
|
||||
}
|
||||
}));
|
||||
});
|
||||
((*expand).expander)(cx, it.span, tts)
|
||||
}
|
||||
Some(@SE(IdentTT(ref expand))) => {
|
||||
|
@ -242,13 +242,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
fmt!("macro %s! expects an ident argument",
|
||||
extnamestr));
|
||||
}
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
cx.bt_push(ExpnInfo {
|
||||
call_site: it.span,
|
||||
callee: NameAndSpan {
|
||||
name: extnamestr,
|
||||
span: expand.span
|
||||
}
|
||||
}));
|
||||
});
|
||||
((*expand).expander)(cx, it.span, it.ident, tts)
|
||||
}
|
||||
_ => cx.span_fatal(
|
||||
|
@ -319,10 +319,10 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
|
||||
Some(@SE(NormalTT(
|
||||
SyntaxExpanderTT{expander: exp, span: exp_sp}))) => {
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
cx.bt_push(ExpnInfo {
|
||||
call_site: sp,
|
||||
callee: NameAndSpan { name: extnamestr, span: exp_sp }
|
||||
}));
|
||||
});
|
||||
let expanded = match exp(cx, mac.span, tts) {
|
||||
MRExpr(e) =>
|
||||
@codemap::spanned { node: stmt_expr(e, cx.next_id()),
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
use ast;
|
||||
use codemap;
|
||||
use codemap::{Pos, ExpandedFrom, span};
|
||||
use codemap::{CallInfo, NameAndSpan};
|
||||
use codemap::{Pos, span};
|
||||
use codemap::{ExpnInfo, NameAndSpan};
|
||||
use ext::base::*;
|
||||
use ext::base;
|
||||
use ext::build::AstBuilder;
|
||||
|
@ -117,14 +117,14 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
// recur along an ExpnInfo chain to find the original expression
|
||||
fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
|
||||
match *expn_info {
|
||||
ExpandedFrom(CallInfo { call_site: ref call_site, _ }) => {
|
||||
ExpnInfo { call_site: ref call_site, _ } => {
|
||||
match call_site.expn_info {
|
||||
Some(next_expn_info) => {
|
||||
match *next_expn_info {
|
||||
ExpandedFrom(CallInfo {
|
||||
ExpnInfo {
|
||||
callee: NameAndSpan { name: ref name, _ },
|
||||
_
|
||||
}) => {
|
||||
} => {
|
||||
// Don't recurse into file using "include!"
|
||||
if "include" == *name {
|
||||
expn_info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue