1
Fork 0

librustc: De-@str NameAndSpan

This commit is contained in:
Patrick Walton 2014-01-30 15:53:09 -08:00 committed by Huon Wilson
parent a4dd3fe2f2
commit c5cbfe89f8
5 changed files with 38 additions and 25 deletions

View file

@ -171,7 +171,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
cx.ext_cx.bt_push(ExpnInfo { cx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: NameAndSpan { callee: NameAndSpan {
name: @"test", name: ~"test",
format: MacroAttribute, format: MacroAttribute,
span: None span: None
} }

View file

@ -160,7 +160,7 @@ pub struct LocWithOpt {
pub struct FileMapAndLine {fm: @FileMap, line: uint} pub struct FileMapAndLine {fm: @FileMap, line: uint}
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos} pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
#[deriving(IterBytes)] #[deriving(Clone, IterBytes)]
pub enum MacroFormat { pub enum MacroFormat {
// e.g. #[deriving(...)] <item> // e.g. #[deriving(...)] <item>
MacroAttribute, MacroAttribute,
@ -168,9 +168,9 @@ pub enum MacroFormat {
MacroBang MacroBang
} }
#[deriving(IterBytes)] #[deriving(Clone, IterBytes)]
pub struct NameAndSpan { pub struct NameAndSpan {
name: @str, name: ~str,
// the format with which the macro was invoked. // the format with which the macro was invoked.
format: MacroFormat, format: MacroFormat,
span: Option<Span> span: Option<Span>

View file

@ -335,7 +335,8 @@ impl<'a> ExtCtxt<'a> {
Some(@ExpnInfo { 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: *callee}); callee: (*callee).clone()
});
} }
} }
} }

View file

@ -944,7 +944,7 @@ impl<'a> TraitDef<'a> {
to_set.expn_info = Some(@codemap::ExpnInfo { to_set.expn_info = Some(@codemap::ExpnInfo {
call_site: to_set, call_site: to_set,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
name: format!("deriving({})", trait_name).to_managed(), name: format!("deriving({})", trait_name),
format: codemap::MacroAttribute, format: codemap::MacroAttribute,
span: Some(self.span) span: Some(self.span)
} }

View file

@ -54,13 +54,14 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
return e; return e;
} }
let extname = &pth.segments[0].identifier; let extname = &pth.segments[0].identifier;
let extnamestr = ident_to_str(extname); let extnamestr = token::get_ident(extname.name);
// leaving explicit deref here to highlight unbox op: // leaving explicit deref here to highlight unbox op:
let marked_after = match fld.extsbox.find(&extname.name) { let marked_after = match fld.extsbox.find(&extname.name) {
None => { None => {
fld.cx.span_err( fld.cx.span_err(
pth.span, pth.span,
format!("macro undefined: '{}'", extnamestr)); format!("macro undefined: '{}'",
extnamestr.get()));
// let compilation continue // let compilation continue
return e; return e;
@ -69,7 +70,7 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: e.span, call_site: e.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr.get().to_str(),
format: MacroBang, format: MacroBang,
span: exp_span, span: exp_span,
}, },
@ -94,7 +95,7 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
pth.span, pth.span,
format!( format!(
"non-expr macro in expr pos: {}", "non-expr macro in expr pos: {}",
extnamestr extnamestr.get()
) )
); );
return e; return e;
@ -107,7 +108,8 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
_ => { _ => {
fld.cx.span_err( fld.cx.span_err(
pth.span, pth.span,
format!("'{}' is not a tt-style macro", extnamestr) format!("'{}' is not a tt-style macro",
extnamestr.get())
); );
return e; return e;
} }
@ -226,7 +228,7 @@ pub fn expand_mod_items(module_: &ast::Mod, fld: &mut MacroExpander) -> ast::Mod
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
name: mname.get().to_managed(), name: mname.get().to_str(),
format: MacroAttribute, format: MacroAttribute,
span: None span: None
} }
@ -295,12 +297,13 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
}; };
let extname = &pth.segments[0].identifier; let extname = &pth.segments[0].identifier;
let extnamestr = ident_to_str(extname); let extnamestr = token::get_ident(extname.name);
let fm = fresh_mark(); let fm = fresh_mark();
let expanded = match fld.extsbox.find(&extname.name) { let expanded = match fld.extsbox.find(&extname.name) {
None => { None => {
fld.cx.span_err(pth.span, fld.cx.span_err(pth.span,
format!("macro undefined: '{}!'", extnamestr)); format!("macro undefined: '{}!'",
extnamestr.get()));
// let compilation continue // let compilation continue
return SmallVector::zero(); return SmallVector::zero();
} }
@ -309,14 +312,15 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
if it.ident.name != parse::token::special_idents::invalid.name { if it.ident.name != parse::token::special_idents::invalid.name {
fld.cx.span_err(pth.span, fld.cx.span_err(pth.span,
format!("macro {}! expects no ident argument, \ format!("macro {}! expects no ident argument, \
given '{}'", extnamestr, given '{}'",
extnamestr.get(),
ident_to_str(&it.ident))); ident_to_str(&it.ident)));
return SmallVector::zero(); return SmallVector::zero();
} }
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr.get().to_str(),
format: MacroBang, format: MacroBang,
span: span span: span
} }
@ -328,13 +332,14 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
Some(&IdentTT(ref expander, span)) => { Some(&IdentTT(ref expander, span)) => {
if it.ident.name == parse::token::special_idents::invalid.name { if it.ident.name == parse::token::special_idents::invalid.name {
fld.cx.span_err(pth.span, fld.cx.span_err(pth.span,
format!("macro {}! expects an ident argument", extnamestr)); format!("macro {}! expects an ident argument",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr.get().to_str(),
format: MacroBang, format: MacroBang,
span: span span: span
} }
@ -344,7 +349,9 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
expander.expand(fld.cx, it.span, it.ident, marked_tts) expander.expand(fld.cx, it.span, it.ident, marked_tts)
} }
_ => { _ => {
fld.cx.span_err(it.span, format!("{}! is not legal in item position", extnamestr)); fld.cx.span_err(it.span,
format!("{}! is not legal in item position",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
}; };
@ -356,7 +363,9 @@ pub fn expand_item_mac(it: @ast::Item, fld: &mut MacroExpander)
.collect() .collect()
} }
MRExpr(_) => { MRExpr(_) => {
fld.cx.span_err(pth.span, format!("expr macro in item position: {}", extnamestr)); fld.cx.span_err(pth.span,
format!("expr macro in item position: {}",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
MRAny(any_macro) => { MRAny(any_macro) => {
@ -475,10 +484,11 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
return SmallVector::zero(); return SmallVector::zero();
} }
let extname = &pth.segments[0].identifier; let extname = &pth.segments[0].identifier;
let extnamestr = ident_to_str(extname); let extnamestr = token::get_ident(extname.name);
let marked_after = match fld.extsbox.find(&extname.name) { let marked_after = match fld.extsbox.find(&extname.name) {
None => { None => {
fld.cx.span_err(pth.span, format!("macro undefined: '{}'", extnamestr)); fld.cx.span_err(pth.span, format!("macro undefined: '{}'",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
@ -486,7 +496,7 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: s.span, call_site: s.span,
callee: NameAndSpan { callee: NameAndSpan {
name: extnamestr, name: extnamestr.get().to_str(),
format: MacroBang, format: MacroBang,
span: exp_span, span: exp_span,
} }
@ -511,7 +521,8 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
MRAny(any_macro) => any_macro.make_stmt(), MRAny(any_macro) => any_macro.make_stmt(),
_ => { _ => {
fld.cx.span_err(pth.span, fld.cx.span_err(pth.span,
format!("non-stmt macro in stmt pos: {}", extnamestr)); format!("non-stmt macro in stmt pos: {}",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
}; };
@ -520,7 +531,8 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
} }
_ => { _ => {
fld.cx.span_err(pth.span, format!("'{}' is not a tt-style macro", extnamestr)); fld.cx.span_err(pth.span, format!("'{}' is not a tt-style macro",
extnamestr.get()));
return SmallVector::zero(); return SmallVector::zero();
} }
}; };