about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2014-01-21 23:09:53 -0800
committerSteven Fackler <sfackler@gmail.com>2014-01-23 09:01:36 -0800
commitd908e97da34ecc419024ddcf5004033920ebb9a9 (patch)
treefc65d429f6aff281da985f0531367fbc2d20eebe /src/libsyntax/ext/expand.rs
parentf8477c9da5ed784f5981611b6c12623cd2b44806 (diff)
Redo exported macro serialization
The old method of serializing the AST gives totally bogus spans if the
expansion of an imported macro causes compilation errors. The best
solution seems to be to serialize the actual textual macro definition
and load it the same way the std-macros are. I'm not totally confident
that getting the source from the CodeMap will always do the right thing,
but it seems to work in simple cases.
Diffstat (limited to 'src/libsyntax/ext/expand.rs')
-rw-r--r--src/libsyntax/ext/expand.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index f547f32e21d..0534aa39848 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -406,9 +406,20 @@ pub fn expand_view_item(vi: &ast::ViewItem,
 fn load_extern_macros(crate: &ast::ViewItem, fld: &mut MacroExpander) {
     let MacroCrate { lib, cnum } = fld.cx.loader.load_crate(crate);
 
+    let crate_name = match crate.node {
+        ast::ViewItemExternMod(ref name, _, _) => token::ident_to_str(name),
+        _ => unreachable!(),
+    };
+    let name = format!("<{} macros>", crate_name).to_managed();
+
     let exported_macros = fld.cx.loader.get_exported_macros(cnum);
-    for &it in exported_macros.iter() {
-        expand_item_mac(it, fld);
+    for source in exported_macros.iter() {
+        let item = parse::parse_item_from_source_str(name,
+                                                     source.to_managed(),
+                                                     fld.cx.cfg(),
+                                                     fld.cx.parse_sess())
+                .expect("expected a serialized item");
+        expand_item_mac(item, fld);
     }
 
     let path = match lib {
@@ -944,7 +955,6 @@ pub fn inject_std_macros(parse_sess: @parse::ParseSess,
     let sm = match parse_item_from_source_str(@"<std-macros>",
                                               std_macros(),
                                               cfg.clone(),
-                                              ~[],
                                               parse_sess) {
         Some(item) => item,
         None => fail!("expected core macros to parse correctly")
@@ -1212,7 +1222,7 @@ mod test {
             fail!("lolwut")
         }
 
-        fn get_exported_macros(&mut self, _: ast::CrateNum) -> ~[@ast::Item] {
+        fn get_exported_macros(&mut self, _: ast::CrateNum) -> ~[~str] {
             fail!("lolwut")
         }
 
@@ -1289,7 +1299,7 @@ mod test {
         let item_ast = parse::parse_item_from_source_str(
             @"<test>",
             src,
-            cfg,~[],sess);
+            cfg,sess);
         match item_ast {
             Some(_) => (), // success
             None => fail!("expected this to parse")