88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- //! Used by `rustc` when loading a plugin.
11+ //! Used by `rustc` when loading a plugin, or a crate with exported macros .
1212
1313use session:: Session ;
1414use metadata:: creader:: CrateReader ;
@@ -21,17 +21,14 @@ use syntax::ast;
2121use syntax:: attr;
2222use syntax:: visit;
2323use syntax:: visit:: Visitor ;
24- use syntax:: ext:: expand:: ExportedMacros ;
2524use syntax:: attr:: AttrMetaMethods ;
2625
27- /// Plugin-related crate metadata .
26+ /// Metadata for a single plugin crate .
2827pub struct PluginMetadata {
29- /// Source code of macros exported by the crate.
30- pub macros : Vec < String > ,
31- /// Path to the shared library file.
32- pub lib : Option < Path > ,
33- /// Symbol name of the plugin registrar function.
34- pub registrar_symbol : Option < String > ,
28+ /// Macros exported by the crate.
29+ pub macros : Vec < ast:: MacroDef > ,
30+ /// Path to the shared library file, and registrar function symbol.
31+ pub registrar : Option < ( Path , String ) > ,
3532}
3633
3734/// Pointer to a registrar function.
@@ -40,8 +37,8 @@ pub type PluginRegistrarFun =
4037
4138/// Information about loaded plugins.
4239pub struct Plugins {
43- /// Source code of exported macros.
44- pub macros : Vec < ExportedMacros > ,
40+ /// Imported macros.
41+ pub macros : Vec < ast :: MacroDef > ,
4542 /// Registrars, as function pointers.
4643 pub registrars : Vec < PluginRegistrarFun > ,
4744}
@@ -90,7 +87,7 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
9087impl < ' a , ' v > Visitor < ' v > for PluginLoader < ' a > {
9188 fn visit_view_item ( & mut self , vi : & ast:: ViewItem ) {
9289 match vi. node {
93- ast:: ViewItemExternCrate ( name , _, _) => {
90+ ast:: ViewItemExternCrate ( _ , _, _) => {
9491 let mut plugin_phase = false ;
9592
9693 for attr in vi. attrs . iter ( ) . filter ( |a| a. check_name ( "phase" ) ) {
@@ -107,17 +104,13 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
107104
108105 if !plugin_phase { return ; }
109106
110- let PluginMetadata { macros, lib , registrar_symbol } =
107+ let PluginMetadata { macros, registrar } =
111108 self . reader . read_plugin_metadata ( vi) ;
112109
113- self . plugins . macros . push ( ExportedMacros {
114- crate_name : name,
115- macros : macros,
116- } ) ;
110+ self . plugins . macros . extend ( macros. into_iter ( ) ) ;
117111
118- match ( lib, registrar_symbol) {
119- ( Some ( lib) , Some ( symbol) )
120- => self . dylink_registrar ( vi, lib, symbol) ,
112+ match registrar {
113+ Some ( ( lib, symbol) ) => self . dylink_registrar ( vi, lib, symbol) ,
121114 _ => ( ) ,
122115 }
123116 }
0 commit comments