Move ExpnInfo to Name
This commit is contained in:
parent
4ec7b713dd
commit
25cbb4385e
@ -29,6 +29,8 @@ use std::io::{self, Read};
|
||||
|
||||
use serialize::{Encodable, Decodable, Encoder, Decoder};
|
||||
|
||||
use parse::token::intern;
|
||||
use ast::Name;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
// Pos, BytePos, CharPos
|
||||
@ -260,9 +262,9 @@ pub struct FileMapAndBytePos { pub fm: Rc<FileMap>, pub pos: BytePos }
|
||||
#[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),
|
||||
}
|
||||
@ -302,13 +304,13 @@ pub struct NameAndSpan {
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -19,7 +19,7 @@ use codemap::Span;
|
||||
use ext::base;
|
||||
use ext::base::*;
|
||||
use feature_gate;
|
||||
use parse::token::InternedString;
|
||||
use parse::token::{intern, InternedString};
|
||||
use parse::token;
|
||||
use ptr::P;
|
||||
|
||||
@ -211,7 +211,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||
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,
|
||||
},
|
||||
|
@ -205,7 +205,7 @@ use codemap::Span;
|
||||
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;
|
||||
|
||||
@ -1436,7 +1436,7 @@ impl<'a> TraitDef<'a> {
|
||||
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,
|
||||
}
|
||||
|
@ -543,7 +543,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac,
|
||||
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,
|
||||
},
|
||||
@ -721,7 +721,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
||||
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,
|
||||
}
|
||||
@ -740,7 +740,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
||||
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,
|
||||
}
|
||||
@ -760,7 +760,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
|
||||
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
|
||||
@ -1087,7 +1087,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
|
||||
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,
|
||||
}
|
||||
@ -1289,8 +1289,8 @@ fn expand_decorators(a: Annotatable,
|
||||
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);
|
||||
@ -1298,7 +1298,7 @@ fn expand_decorators(a: Annotatable,
|
||||
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.
|
||||
@ -1325,7 +1325,7 @@ fn expand_decorators(a: Annotatable,
|
||||
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.
|
||||
@ -1366,16 +1366,16 @@ fn expand_item_multi_modifier(mut it: Annotatable,
|
||||
}
|
||||
|
||||
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
|
||||
@ -1414,16 +1414,16 @@ fn expand_item_modifiers(mut it: P<ast::Item>,
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -14,8 +14,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
|
||||
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;
|
||||
@ -27,7 +26,7 @@ fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
|
||||
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,
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ use ext::expand::ExpansionConfig;
|
||||
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};
|
||||
@ -265,7 +265,7 @@ fn generate_test_harness(sess: &ParseSess,
|
||||
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,
|
||||
}
|
||||
@ -297,7 +297,7 @@ fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
|
||||
let info = ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: NameAndSpan {
|
||||
format: MacroAttribute("test".to_string()),
|
||||
format: MacroAttribute(intern("test")),
|
||||
span: None,
|
||||
allow_internal_unstable: true,
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ fn main() {
|
||||
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,
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ fn main() {
|
||||
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,
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ extern crate syntax;
|
||||
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
use syntax::print::pprust::*;
|
||||
use syntax::parse::token::intern;
|
||||
|
||||
fn main() {
|
||||
let ps = syntax::parse::ParseSess::new();
|
||||
@ -27,8 +28,7 @@ fn main() {
|
||||
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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user