@@ -17,19 +17,15 @@ use syntax_pos::{Span, ExpnId, NO_EXPANSION};
1717use errors:: DiagnosticBuilder ;
1818use ext:: expand:: { self , Invocation , Expansion } ;
1919use ext:: hygiene:: Mark ;
20- use ext:: tt:: macro_rules;
21- use fold;
20+ use fold:: { self , Folder } ;
2221use parse;
2322use parse:: parser:: { self , Parser } ;
2423use parse:: token;
2524use parse:: token:: { InternedString , str_to_ident} ;
2625use ptr:: P ;
2726use std_inject;
2827use util:: small_vector:: SmallVector ;
29- use fold:: Folder ;
30- use feature_gate;
3128
32- use std:: collections:: HashMap ;
3329use std:: path:: PathBuf ;
3430use std:: rc:: Rc ;
3531use std:: default:: Default ;
@@ -659,35 +655,30 @@ pub enum SyntaxExtension {
659655pub type NamedSyntaxExtension = ( Name , SyntaxExtension ) ;
660656
661657pub trait Resolver {
662- fn load_crate ( & mut self , extern_crate : & ast:: Item , allows_macros : bool ) -> Vec < LoadedMacro > ;
663658 fn next_node_id ( & mut self ) -> ast:: NodeId ;
664659
665660 fn visit_expansion ( & mut self , mark : Mark , expansion : & Expansion ) ;
666- fn add_macro ( & mut self , scope : Mark , ident : ast:: Ident , ext : Rc < SyntaxExtension > ) ;
661+ fn add_macro ( & mut self , scope : Mark , def : ast:: MacroDef ) ;
662+ fn add_ext ( & mut self , scope : Mark , ident : ast:: Ident , ext : Rc < SyntaxExtension > ) ;
667663 fn add_expansions_at_stmt ( & mut self , id : ast:: NodeId , macros : Vec < Mark > ) ;
668664
669665 fn find_attr_invoc ( & mut self , attrs : & mut Vec < Attribute > ) -> Option < Attribute > ;
670666 fn resolve_invoc ( & mut self , scope : Mark , invoc : & Invocation ) -> Option < Rc < SyntaxExtension > > ;
671- }
672-
673- pub enum LoadedMacro {
674- Def ( ast:: MacroDef ) ,
675- CustomDerive ( String , Box < MultiItemModifier > ) ,
667+ fn resolve_derive_mode ( & mut self , ident : ast:: Ident ) -> Option < Rc < MultiItemModifier > > ;
676668}
677669
678670pub struct DummyResolver ;
679671
680672impl Resolver for DummyResolver {
681- fn load_crate ( & mut self , _extern_crate : & ast:: Item , _allows_macros : bool ) -> Vec < LoadedMacro > {
682- Vec :: new ( )
683- }
684673 fn next_node_id ( & mut self ) -> ast:: NodeId { ast:: DUMMY_NODE_ID }
685674
686675 fn visit_expansion ( & mut self , _invoc : Mark , _expansion : & Expansion ) { }
687- fn add_macro ( & mut self , _scope : Mark , _ident : ast:: Ident , _ext : Rc < SyntaxExtension > ) { }
676+ fn add_macro ( & mut self , _scope : Mark , _def : ast:: MacroDef ) { }
677+ fn add_ext ( & mut self , _scope : Mark , _ident : ast:: Ident , _ext : Rc < SyntaxExtension > ) { }
688678 fn add_expansions_at_stmt ( & mut self , _id : ast:: NodeId , _macros : Vec < Mark > ) { }
689679
690680 fn find_attr_invoc ( & mut self , _attrs : & mut Vec < Attribute > ) -> Option < Attribute > { None }
681+ fn resolve_derive_mode ( & mut self , _ident : ast:: Ident ) -> Option < Rc < MultiItemModifier > > { None }
691682 fn resolve_invoc ( & mut self , _scope : Mark , _invoc : & Invocation ) -> Option < Rc < SyntaxExtension > > {
692683 None
693684 }
@@ -717,8 +708,6 @@ pub struct ExtCtxt<'a> {
717708 pub ecfg : expand:: ExpansionConfig < ' a > ,
718709 pub crate_root : Option < & ' static str > ,
719710 pub resolver : & ' a mut Resolver ,
720- pub exported_macros : Vec < ast:: MacroDef > ,
721- pub derive_modes : HashMap < InternedString , Box < MultiItemModifier > > ,
722711 pub current_expansion : ExpansionData ,
723712}
724713
@@ -732,9 +721,7 @@ impl<'a> ExtCtxt<'a> {
732721 cfg : cfg,
733722 ecfg : ecfg,
734723 crate_root : None ,
735- exported_macros : Vec :: new ( ) ,
736724 resolver : resolver,
737- derive_modes : HashMap :: new ( ) ,
738725 current_expansion : ExpansionData {
739726 mark : Mark :: root ( ) ,
740727 depth : 0 ,
@@ -811,31 +798,6 @@ impl<'a> ExtCtxt<'a> {
811798 }
812799 pub fn bt_pop ( & mut self ) { }
813800
814- pub fn insert_macro ( & mut self , def : ast:: MacroDef ) {
815- if def. export {
816- self . exported_macros . push ( def. clone ( ) ) ;
817- }
818- if def. use_locally {
819- let ext = macro_rules:: compile ( self . parse_sess , & def) ;
820- self . resolver . add_macro ( self . current_expansion . mark , def. ident , Rc :: new ( ext) ) ;
821- }
822- }
823-
824- pub fn insert_custom_derive ( & mut self , name : & str , ext : Box < MultiItemModifier > , sp : Span ) {
825- if !self . ecfg . enable_rustc_macro ( ) {
826- feature_gate:: emit_feature_err ( & self . parse_sess . span_diagnostic ,
827- "rustc_macro" ,
828- sp,
829- feature_gate:: GateIssue :: Language ,
830- "loading custom derive macro crates \
831- is experimentally supported") ;
832- }
833- let name = token:: intern_and_get_ident ( name) ;
834- if self . derive_modes . insert ( name. clone ( ) , ext) . is_some ( ) {
835- self . span_err ( sp, & format ! ( "cannot shadow existing derive mode `{}`" , name) ) ;
836- }
837- }
838-
839801 pub fn struct_span_warn ( & self ,
840802 sp : Span ,
841803 msg : & str )
@@ -922,7 +884,7 @@ impl<'a> ExtCtxt<'a> {
922884
923885 for ( name, extension) in user_exts {
924886 let ident = ast:: Ident :: with_empty_ctxt ( name) ;
925- self . resolver . add_macro ( Mark :: root ( ) , ident, Rc :: new ( extension) ) ;
887+ self . resolver . add_ext ( Mark :: root ( ) , ident, Rc :: new ( extension) ) ;
926888 }
927889
928890 let mut module = ModuleData {
0 commit comments