1
Fork 0

Move ExpnInfo to Name

This commit is contained in:
Manish Goregaokar 2015-08-27 05:41:53 +05:30
parent 4ec7b713dd
commit 25cbb4385e
9 changed files with 37 additions and 38 deletions

View file

@ -29,6 +29,8 @@ use std::io::{self, Read};
use serialize::{Encodable, Decodable, Encoder, Decoder}; use serialize::{Encodable, Decodable, Encoder, Decoder};
use parse::token::intern;
use ast::Name;
// _____________________________________________________________________________ // _____________________________________________________________________________
// Pos, BytePos, CharPos // Pos, BytePos, CharPos
@ -260,9 +262,9 @@ pub struct FileMapAndBytePos { pub fm: Rc<FileMap>, pub pos: BytePos }
#[derive(Clone, Hash, Debug, PartialEq, Eq)] #[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub enum ExpnFormat { pub enum ExpnFormat {
/// e.g. #[derive(...)] <item> /// e.g. #[derive(...)] <item>
MacroAttribute(String), MacroAttribute(Name),
/// e.g. `format!()` /// e.g. `format!()`
MacroBang(String), MacroBang(Name),
/// Syntax sugar expansion performed by the compiler (libsyntax::expand). /// Syntax sugar expansion performed by the compiler (libsyntax::expand).
CompilerExpansion(CompilerExpansionFormat), CompilerExpansion(CompilerExpansionFormat),
} }
@ -302,13 +304,13 @@ pub struct NameAndSpan {
} }
impl NameAndSpan { impl NameAndSpan {
pub fn name(&self) -> &str{ pub fn name(&self) -> Name {
match self.format { match self.format {
ExpnFormat::MacroAttribute(ref s) => &s, ExpnFormat::MacroAttribute(s) => s,
ExpnFormat::MacroBang(ref s) => &s, ExpnFormat::MacroBang(s) => s,
ExpnFormat::CompilerExpansion(ce) => ce.name(), ExpnFormat::CompilerExpansion(ce) => intern(ce.name()),
} }
} }
} }
/// Extra information for tracking spans of macro and syntax sugar expansion /// Extra information for tracking spans of macro and syntax sugar expansion

View file

@ -19,7 +19,7 @@ use codemap::Span;
use ext::base; use ext::base;
use ext::base::*; use ext::base::*;
use feature_gate; use feature_gate;
use parse::token::InternedString; use parse::token::{intern, InternedString};
use parse::token; use parse::token;
use ptr::P; 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 { let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: sp, call_site: sp,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
format: codemap::MacroBang("asm".to_string()), format: codemap::MacroBang(intern("asm")),
span: None, span: None,
allow_internal_unstable: false, allow_internal_unstable: false,
}, },

View file

@ -205,7 +205,7 @@ use codemap::Span;
use diagnostic::SpanHandler; use diagnostic::SpanHandler;
use fold::MoveMap; use fold::MoveMap;
use owned_slice::OwnedSlice; use owned_slice::OwnedSlice;
use parse::token::InternedString; use parse::token::{intern, InternedString};
use parse::token::special_idents; use parse::token::special_idents;
use ptr::P; use ptr::P;
@ -1436,7 +1436,7 @@ impl<'a> TraitDef<'a> {
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo { to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
call_site: to_set, call_site: to_set,
callee: codemap::NameAndSpan { callee: codemap::NameAndSpan {
format: codemap::MacroAttribute(format!("derive({})", trait_name)), format: codemap::MacroAttribute(intern(&format!("derive({})", trait_name))),
span: Some(self.span), span: Some(self.span),
allow_internal_unstable: false, allow_internal_unstable: false,
} }

View file

@ -543,7 +543,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: span, call_site: span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroBang(extname.to_string()), format: MacroBang(extname),
span: exp_span, span: exp_span,
allow_internal_unstable: allow_internal_unstable, allow_internal_unstable: allow_internal_unstable,
}, },
@ -721,7 +721,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroBang(extname.to_string()), format: MacroBang(extname),
span: span, span: span,
allow_internal_unstable: allow_internal_unstable, allow_internal_unstable: allow_internal_unstable,
} }
@ -740,7 +740,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroBang(extname.to_string()), format: MacroBang(extname),
span: span, span: span,
allow_internal_unstable: allow_internal_unstable, allow_internal_unstable: allow_internal_unstable,
} }
@ -760,7 +760,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: it.span, call_site: it.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroBang(extname.to_string()), format: MacroBang(extname),
span: None, span: None,
// `macro_rules!` doesn't directly allow // `macro_rules!` doesn't directly allow
// unstable (this is orthogonal to whether // 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 { fld.cx.bt_push(ExpnInfo {
call_site: span, call_site: span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroBang(extname.to_string()), format: MacroBang(extname),
span: tt_span, span: tt_span,
allow_internal_unstable: allow_internal_unstable, allow_internal_unstable: allow_internal_unstable,
} }
@ -1289,8 +1289,8 @@ fn expand_decorators(a: Annotatable,
new_attrs: &mut Vec<ast::Attribute>) new_attrs: &mut Vec<ast::Attribute>)
{ {
for attr in a.attrs() { for attr in a.attrs() {
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 { Some(rc) => match *rc {
Decorator(ref dec) => { Decorator(ref dec) => {
attr::mark_used(&attr); attr::mark_used(&attr);
@ -1298,7 +1298,7 @@ fn expand_decorators(a: Annotatable,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute(mname.to_string()), format: MacroAttribute(mname),
span: Some(attr.span), span: Some(attr.span),
// attributes can do whatever they like, // attributes can do whatever they like,
// for now. // for now.
@ -1325,7 +1325,7 @@ fn expand_decorators(a: Annotatable,
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute(mname.to_string()), format: MacroAttribute(mname),
span: Some(attr.span), span: Some(attr.span),
// attributes can do whatever they like, // attributes can do whatever they like,
// for now. // for now.
@ -1366,16 +1366,16 @@ fn expand_item_multi_modifier(mut it: Annotatable,
} }
for attr in &modifiers { 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 { Some(rc) => match *rc {
MultiModifier(ref mac) => { MultiModifier(ref mac) => {
attr::mark_used(attr); attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute(mname.to_string()), format: MacroAttribute(mname),
span: Some(attr.span), span: Some(attr.span),
// attributes can do whatever they like, // attributes can do whatever they like,
// for now // for now
@ -1414,16 +1414,16 @@ fn expand_item_modifiers(mut it: P<ast::Item>,
} }
for attr in &modifiers { 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 { Some(rc) => match *rc {
Modifier(ref mac) => { Modifier(ref mac) => {
attr::mark_used(attr); attr::mark_used(attr);
fld.cx.bt_push(ExpnInfo { fld.cx.bt_push(ExpnInfo {
call_site: attr.span, call_site: attr.span,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute(mname.to_string()), format: MacroAttribute(mname),
span: Some(attr.span), span: Some(attr.span),
// attributes can do whatever they like, // attributes can do whatever they like,
// for now // for now

View file

@ -14,8 +14,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
use codemap; use codemap;
use fold::Folder; use fold::Folder;
use fold; use fold;
use parse::token::InternedString; use parse::token::{intern, InternedString, special_idents};
use parse::token::special_idents;
use parse::{token, ParseSess}; use parse::{token, ParseSess};
use ptr::P; use ptr::P;
use util::small_vector::SmallVector; use util::small_vector::SmallVector;
@ -27,7 +26,7 @@ fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
let info = ExpnInfo { let info = ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute("std_inject".to_string()), format: MacroAttribute(intern("std_inject")),
span: None, span: None,
allow_internal_unstable: true, allow_internal_unstable: true,
} }

View file

@ -30,7 +30,7 @@ use ext::expand::ExpansionConfig;
use fold::{Folder, MoveMap}; use fold::{Folder, MoveMap};
use fold; use fold;
use owned_slice::OwnedSlice; use owned_slice::OwnedSlice;
use parse::token::InternedString; use parse::token::{intern, InternedString};
use parse::{token, ParseSess}; use parse::{token, ParseSess};
use print::pprust; use print::pprust;
use {ast, ast_util}; use {ast, ast_util};
@ -265,7 +265,7 @@ fn generate_test_harness(sess: &ParseSess,
cx.ext_cx.bt_push(ExpnInfo { cx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute("test".to_string()), format: MacroAttribute(intern("test")),
span: None, span: None,
allow_internal_unstable: false, allow_internal_unstable: false,
} }
@ -297,7 +297,7 @@ fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
let info = ExpnInfo { let info = ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: NameAndSpan { callee: NameAndSpan {
format: MacroAttribute("test".to_string()), format: MacroAttribute(intern("test")),
span: None, span: None,
allow_internal_unstable: true, allow_internal_unstable: true,
} }

View file

@ -27,8 +27,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
name: "".to_string(), format: syntax::codemap::MacroBang(parse::token::intern("")),
format: syntax::codemap::MacroBang,
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }

View file

@ -31,8 +31,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
name: "".to_string(), format: syntax::codemap::MacroBang(parse::token::intern("")),
format: syntax::codemap::MacroBang,
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }

View file

@ -16,6 +16,7 @@ extern crate syntax;
use syntax::codemap::DUMMY_SP; use syntax::codemap::DUMMY_SP;
use syntax::print::pprust::*; use syntax::print::pprust::*;
use syntax::parse::token::intern;
fn main() { fn main() {
let ps = syntax::parse::ParseSess::new(); let ps = syntax::parse::ParseSess::new();
@ -27,8 +28,7 @@ fn main() {
cx.bt_push(syntax::codemap::ExpnInfo { cx.bt_push(syntax::codemap::ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: syntax::codemap::NameAndSpan { callee: syntax::codemap::NameAndSpan {
name: "".to_string(), format: syntax::codemap::MacroBang(intern("")),
format: syntax::codemap::MacroBang,
allow_internal_unstable: false, allow_internal_unstable: false,
span: None, span: None,
} }