use serialize::{Encodable, Decodable, Encoder, Decoder};
+use parse::token::intern;
+use ast::Name;
// _____________________________________________________________________________
// Pos, BytePos, CharPos
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub enum ExpnFormat {
/// e.g. #[derive(...)] <item>
- MacroAttribute(String),
+ MacroAttribute(Name),
/// e.g. `format!()`
- MacroBang(String),
+ MacroBang(Name),
/// Syntax sugar expansion performed by the compiler (libsyntax::expand).
CompilerExpansion(CompilerExpansionFormat),
}
}
impl NameAndSpan {
- pub fn name(&self) -> &str{
+ pub fn name(&self) -> Name {
match self.format {
- ExpnFormat::MacroAttribute(ref s) => &s,
- ExpnFormat::MacroBang(ref s) => &s,
- ExpnFormat::CompilerExpansion(ce) => ce.name(),
+ ExpnFormat::MacroAttribute(s) => s,
+ ExpnFormat::MacroBang(s) => s,
+ ExpnFormat::CompilerExpansion(ce) => intern(ce.name()),
}
- }
+ }
}
/// Extra information for tracking spans of macro and syntax sugar expansion
use ext::base;
use ext::base::*;
use feature_gate;
-use parse::token::InternedString;
+use parse::token::{intern, InternedString};
use parse::token;
use ptr::P;
let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: sp,
callee: codemap::NameAndSpan {
- format: codemap::MacroBang("asm".to_string()),
+ format: codemap::MacroBang(intern("asm")),
span: None,
allow_internal_unstable: false,
},
use diagnostic::SpanHandler;
use fold::MoveMap;
use owned_slice::OwnedSlice;
-use parse::token::InternedString;
+use parse::token::{intern, InternedString};
use parse::token::special_idents;
use ptr::P;
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: to_set,
callee: codemap::NameAndSpan {
- format: codemap::MacroAttribute(format!("derive({})", trait_name)),
+ format: codemap::MacroAttribute(intern(&format!("derive({})", trait_name))),
span: Some(self.span),
allow_internal_unstable: false,
}
fld.cx.bt_push(ExpnInfo {
call_site: span,
callee: NameAndSpan {
- format: MacroBang(extname.to_string()),
+ format: MacroBang(extname),
span: exp_span,
allow_internal_unstable: allow_internal_unstable,
},
fld.cx.bt_push(ExpnInfo {
call_site: it.span,
callee: NameAndSpan {
- format: MacroBang(extname.to_string()),
+ format: MacroBang(extname),
span: span,
allow_internal_unstable: allow_internal_unstable,
}
fld.cx.bt_push(ExpnInfo {
call_site: it.span,
callee: NameAndSpan {
- format: MacroBang(extname.to_string()),
+ format: MacroBang(extname),
span: span,
allow_internal_unstable: allow_internal_unstable,
}
fld.cx.bt_push(ExpnInfo {
call_site: it.span,
callee: NameAndSpan {
- format: MacroBang(extname.to_string()),
+ format: MacroBang(extname),
span: None,
// `macro_rules!` doesn't directly allow
// unstable (this is orthogonal to whether
fld.cx.bt_push(ExpnInfo {
call_site: span,
callee: NameAndSpan {
- format: MacroBang(extname.to_string()),
+ format: MacroBang(extname),
span: tt_span,
allow_internal_unstable: allow_internal_unstable,
}
new_attrs: &mut Vec<ast::Attribute>)
{
for attr in a.attrs() {
- let mname = attr.name();
- match fld.cx.syntax_env.find(&intern(&mname)) {
+ let mname = intern(&attr.name());
+ match fld.cx.syntax_env.find(&mname) {
Some(rc) => match *rc {
Decorator(ref dec) => {
attr::mark_used(&attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
- format: MacroAttribute(mname.to_string()),
+ format: MacroAttribute(mname),
span: Some(attr.span),
// attributes can do whatever they like,
// for now.
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
- format: MacroAttribute(mname.to_string()),
+ format: MacroAttribute(mname),
span: Some(attr.span),
// attributes can do whatever they like,
// for now.
}
for attr in &modifiers {
- let mname = attr.name();
+ let mname = intern(&attr.name());
- match fld.cx.syntax_env.find(&intern(&mname)) {
+ match fld.cx.syntax_env.find(&mname) {
Some(rc) => match *rc {
MultiModifier(ref mac) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
- format: MacroAttribute(mname.to_string()),
+ format: MacroAttribute(mname),
span: Some(attr.span),
// attributes can do whatever they like,
// for now
}
for attr in &modifiers {
- let mname = attr.name();
+ let mname = intern(&attr.name());
- match fld.cx.syntax_env.find(&intern(&mname)) {
+ match fld.cx.syntax_env.find(&mname) {
Some(rc) => match *rc {
Modifier(ref mac) => {
attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
- format: MacroAttribute(mname.to_string()),
+ format: MacroAttribute(mname),
span: Some(attr.span),
// attributes can do whatever they like,
// for now
use codemap;
use fold::Folder;
use fold;
-use parse::token::InternedString;
-use parse::token::special_idents;
+use parse::token::{intern, InternedString, special_idents};
use parse::{token, ParseSess};
use ptr::P;
use util::small_vector::SmallVector;
let info = ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
- format: MacroAttribute("std_inject".to_string()),
+ format: MacroAttribute(intern("std_inject")),
span: None,
allow_internal_unstable: true,
}
use fold::{Folder, MoveMap};
use fold;
use owned_slice::OwnedSlice;
-use parse::token::InternedString;
+use parse::token::{intern, InternedString};
use parse::{token, ParseSess};
use print::pprust;
use {ast, ast_util};
cx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
- format: MacroAttribute("test".to_string()),
+ format: MacroAttribute(intern("test")),
span: None,
allow_internal_unstable: false,
}
let info = ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
- format: MacroAttribute("test".to_string()),
+ format: MacroAttribute(intern("test")),
span: None,
allow_internal_unstable: true,
}
cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan {
- name: "".to_string(),
- format: syntax::codemap::MacroBang,
+ format: syntax::codemap::MacroBang(parse::token::intern("")),
allow_internal_unstable: false,
span: None,
}
cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan {
- name: "".to_string(),
- format: syntax::codemap::MacroBang,
+ format: syntax::codemap::MacroBang(parse::token::intern("")),
allow_internal_unstable: false,
span: None,
}
use syntax::codemap::DUMMY_SP;
use syntax::print::pprust::*;
+use syntax::parse::token::intern;
fn main() {
let ps = syntax::parse::ParseSess::new();
cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan {
- name: "".to_string(),
- format: syntax::codemap::MacroBang,
+ format: syntax::codemap::MacroBang(intern("")),
allow_internal_unstable: false,
span: None,
}