@@ -17,19 +17,15 @@ use syntax_pos::{Span, ExpnId, NO_EXPANSION};
17
17
use errors:: DiagnosticBuilder ;
18
18
use ext:: expand:: { self , Invocation , Expansion } ;
19
19
use ext:: hygiene:: Mark ;
20
- use ext:: tt:: macro_rules;
21
- use fold;
20
+ use fold:: { self , Folder } ;
22
21
use parse;
23
22
use parse:: parser:: { self , Parser } ;
24
23
use parse:: token;
25
24
use parse:: token:: { InternedString , str_to_ident} ;
26
25
use ptr:: P ;
27
26
use std_inject;
28
27
use util:: small_vector:: SmallVector ;
29
- use fold:: Folder ;
30
- use feature_gate;
31
28
32
- use std:: collections:: HashMap ;
33
29
use std:: path:: PathBuf ;
34
30
use std:: rc:: Rc ;
35
31
use std:: default:: Default ;
@@ -659,35 +655,30 @@ pub enum SyntaxExtension {
659
655
pub type NamedSyntaxExtension = ( Name , SyntaxExtension ) ;
660
656
661
657
pub trait Resolver {
662
- fn load_crate ( & mut self , extern_crate : & ast:: Item , allows_macros : bool ) -> Vec < LoadedMacro > ;
663
658
fn next_node_id ( & mut self ) -> ast:: NodeId ;
664
659
665
660
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 > ) ;
667
663
fn add_expansions_at_stmt ( & mut self , id : ast:: NodeId , macros : Vec < Mark > ) ;
668
664
669
665
fn find_attr_invoc ( & mut self , attrs : & mut Vec < Attribute > ) -> Option < Attribute > ;
670
666
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 > > ;
676
668
}
677
669
678
670
pub struct DummyResolver ;
679
671
680
672
impl Resolver for DummyResolver {
681
- fn load_crate ( & mut self , _extern_crate : & ast:: Item , _allows_macros : bool ) -> Vec < LoadedMacro > {
682
- Vec :: new ( )
683
- }
684
673
fn next_node_id ( & mut self ) -> ast:: NodeId { ast:: DUMMY_NODE_ID }
685
674
686
675
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 > ) { }
688
678
fn add_expansions_at_stmt ( & mut self , _id : ast:: NodeId , _macros : Vec < Mark > ) { }
689
679
690
680
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 }
691
682
fn resolve_invoc ( & mut self , _scope : Mark , _invoc : & Invocation ) -> Option < Rc < SyntaxExtension > > {
692
683
None
693
684
}
@@ -717,8 +708,6 @@ pub struct ExtCtxt<'a> {
717
708
pub ecfg : expand:: ExpansionConfig < ' a > ,
718
709
pub crate_root : Option < & ' static str > ,
719
710
pub resolver : & ' a mut Resolver ,
720
- pub exported_macros : Vec < ast:: MacroDef > ,
721
- pub derive_modes : HashMap < InternedString , Box < MultiItemModifier > > ,
722
711
pub current_expansion : ExpansionData ,
723
712
}
724
713
@@ -732,9 +721,7 @@ impl<'a> ExtCtxt<'a> {
732
721
cfg : cfg,
733
722
ecfg : ecfg,
734
723
crate_root : None ,
735
- exported_macros : Vec :: new ( ) ,
736
724
resolver : resolver,
737
- derive_modes : HashMap :: new ( ) ,
738
725
current_expansion : ExpansionData {
739
726
mark : Mark :: root ( ) ,
740
727
depth : 0 ,
@@ -811,31 +798,6 @@ impl<'a> ExtCtxt<'a> {
811
798
}
812
799
pub fn bt_pop ( & mut self ) { }
813
800
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
-
839
801
pub fn struct_span_warn ( & self ,
840
802
sp : Span ,
841
803
msg : & str )
@@ -922,7 +884,7 @@ impl<'a> ExtCtxt<'a> {
922
884
923
885
for ( name, extension) in user_exts {
924
886
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) ) ;
926
888
}
927
889
928
890
let mut module = ModuleData {
0 commit comments