Skip to content

Commit

Permalink
Move ExpnInfo to Name
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Aug 27, 2015
1 parent 4ec7b71 commit 25cbb43
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 38 deletions.
16 changes: 9 additions & 7 deletions src/libsyntax/codemap.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/asm.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/generic/mod.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
}
Expand Down
30 changes: 15 additions & 15 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -1289,16 +1289,16 @@ 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);

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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/std_inject.rs
Expand Up @@ -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;
Expand All @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/test.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail-fulldeps/qquote.rs
Expand Up @@ -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,
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/run-fail-fulldeps/qquote.rs
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass-fulldeps/qquote.rs
Expand Up @@ -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();
Expand All @@ -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,
}
Expand Down

0 comments on commit 25cbb43

Please sign in to comment.