Do not rely on newtype enum dereference

This commit is contained in:
Seo Sanghyeon
2013-07-02 18:31:00 +09:00
parent c9b9462e8f
commit 2e65782c17
5 changed files with 29 additions and 37 deletions

View File

@@ -17,7 +17,7 @@ use front::config;
use std::vec; use std::vec;
use syntax::ast_util::*; use syntax::ast_util::*;
use syntax::attr; 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::codemap;
use syntax::ext::base::ExtCtxt; use syntax::ext::base::ExtCtxt;
use syntax::fold; use syntax::fold;
@@ -72,13 +72,13 @@ fn generate_test_harness(sess: session::Session,
}; };
let ext_cx = cx.ext_cx; let ext_cx = cx.ext_cx;
ext_cx.bt_push(ExpandedFrom(CallInfo { ext_cx.bt_push(ExpnInfo {
call_site: dummy_sp(), call_site: dummy_sp(),
callee: NameAndSpan { callee: NameAndSpan {
name: @"test", name: @"test",
span: None span: None
} }
})); });
let precursor = @fold::AstFoldFns { let precursor = @fold::AstFoldFns {
fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ), fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),

View File

@@ -174,16 +174,11 @@ pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
#[deriving(IterBytes)] #[deriving(IterBytes)]
pub struct NameAndSpan {name: @str, span: Option<span>} 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 /// Extra information for tracking macro expansion of spans
#[deriving(IterBytes)] #[deriving(IterBytes)]
pub enum ExpnInfo { pub struct ExpnInfo {
ExpandedFrom(CallInfo) call_site: span,
callee: NameAndSpan
} }
pub type FileName = @str; pub type FileName = @str;

View File

@@ -11,8 +11,7 @@
use ast; use ast;
use ast::Name; use ast::Name;
use codemap; use codemap;
use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom}; use codemap::{CodeMap, span, ExpnInfo};
use codemap::CallInfo;
use diagnostic::span_handler; use diagnostic::span_handler;
use ext; use ext;
use parse; use parse;
@@ -243,7 +242,7 @@ impl ExtCtxt {
pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg } pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
pub fn call_site(&self) -> span { pub fn call_site(&self) -> span {
match *self.backtrace { match *self.backtrace {
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, Some(@ExpnInfo {call_site: cs, _}) => cs,
None => self.bug("missing top span") 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 mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
pub fn bt_push(&self, ei: codemap::ExpnInfo) { pub fn bt_push(&self, ei: codemap::ExpnInfo) {
match ei { match ei {
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { ExpnInfo {call_site: cs, callee: ref callee} => {
*self.backtrace = *self.backtrace =
Some(@ExpandedFrom(CallInfo { Some(@ExpnInfo {
call_site: span {lo: cs.lo, hi: cs.hi, call_site: span {lo: cs.lo, hi: cs.hi,
expn_info: *self.backtrace}, expn_info: *self.backtrace},
callee: copy *callee})); callee: copy *callee});
} }
} }
} }
pub fn bt_pop(&self) { pub fn bt_pop(&self) {
match *self.backtrace { match *self.backtrace {
Some(@ExpandedFrom( Some(@ExpnInfo {
CallInfo { call_site: span {expn_info: prev, _}, _}) => {
call_site: span {expn_info: prev, _}, _
})) => {
*self.backtrace = prev *self.backtrace = prev
} }
_ => self.bug("tried to pop without a push") _ => self.bug("tried to pop without a push")

View File

@@ -16,7 +16,7 @@ use ast;
use ast_util::{new_rename, new_mark, resolve}; use ast_util::{new_rename, new_mark, resolve};
use attr; use attr;
use codemap; use codemap;
use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan, spanned}; use codemap::{span, ExpnInfo, NameAndSpan, spanned};
use ext::base::*; use ext::base::*;
use fold::*; use fold::*;
use parse; use parse;
@@ -60,13 +60,13 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
expander: exp, expander: exp,
span: exp_sp span: exp_sp
}))) => { }))) => {
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpnInfo {
call_site: s, call_site: s,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: exp_sp, span: exp_sp,
}, },
})); });
let expanded = match exp(cx, mac.span, *tts) { let expanded = match exp(cx, mac.span, *tts) {
MRExpr(e) => e, MRExpr(e) => e,
@@ -131,13 +131,13 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
match (*extsbox).find(&intern(mname)) { match (*extsbox).find(&intern(mname)) {
Some(@SE(ItemDecorator(dec_fn))) => { Some(@SE(ItemDecorator(dec_fn))) => {
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
name: mname, name: mname,
span: None span: None
} }
})); });
let r = dec_fn(cx, attr.span, attr.node.value, items); let r = dec_fn(cx, attr.span, attr.node.value, items);
cx.bt_pop(); cx.bt_pop();
r r
@@ -227,13 +227,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
given '%s'", extnamestr, given '%s'", extnamestr,
ident_to_str(&it.ident))); ident_to_str(&it.ident)));
} }
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: expand.span span: expand.span
} }
})); });
((*expand).expander)(cx, it.span, tts) ((*expand).expander)(cx, it.span, tts)
} }
Some(@SE(IdentTT(ref expand))) => { Some(@SE(IdentTT(ref expand))) => {
@@ -242,13 +242,13 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
fmt!("macro %s! expects an ident argument", fmt!("macro %s! expects an ident argument",
extnamestr)); extnamestr));
} }
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr,
span: expand.span span: expand.span
} }
})); });
((*expand).expander)(cx, it.span, it.ident, tts) ((*expand).expander)(cx, it.span, it.ident, tts)
} }
_ => cx.span_fatal( _ => cx.span_fatal(
@@ -319,10 +319,10 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
Some(@SE(NormalTT( Some(@SE(NormalTT(
SyntaxExpanderTT{expander: exp, span: exp_sp}))) => { SyntaxExpanderTT{expander: exp, span: exp_sp}))) => {
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpnInfo {
call_site: sp, call_site: sp,
callee: NameAndSpan { name: extnamestr, span: exp_sp } callee: NameAndSpan { name: extnamestr, span: exp_sp }
})); });
let expanded = match exp(cx, mac.span, tts) { let expanded = match exp(cx, mac.span, tts) {
MRExpr(e) => MRExpr(e) =>
@codemap::spanned { node: stmt_expr(e, cx.next_id()), @codemap::spanned { node: stmt_expr(e, cx.next_id()),

View File

@@ -10,8 +10,8 @@
use ast; use ast;
use codemap; use codemap;
use codemap::{Pos, ExpandedFrom, span}; use codemap::{Pos, span};
use codemap::{CallInfo, NameAndSpan}; use codemap::{ExpnInfo, NameAndSpan};
use ext::base::*; use ext::base::*;
use ext::base; use ext::base;
use ext::build::AstBuilder; 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 // recur along an ExpnInfo chain to find the original expression
fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
match *expn_info { match *expn_info {
ExpandedFrom(CallInfo { call_site: ref call_site, _ }) => { ExpnInfo { call_site: ref call_site, _ } => {
match call_site.expn_info { match call_site.expn_info {
Some(next_expn_info) => { Some(next_expn_info) => {
match *next_expn_info { match *next_expn_info {
ExpandedFrom(CallInfo { ExpnInfo {
callee: NameAndSpan { name: ref name, _ }, callee: NameAndSpan { name: ref name, _ },
_ _
}) => { } => {
// Don't recurse into file using "include!" // Don't recurse into file using "include!"
if "include" == *name { if "include" == *name {
expn_info expn_info