@@ -19,12 +19,12 @@ use codemap::Span;
19
19
use owned_slice:: OwnedSlice ;
20
20
use parse:: token;
21
21
use print:: pprust;
22
+ use ptr:: P ;
22
23
use visit:: Visitor ;
23
24
use visit;
24
25
25
26
use std:: cell:: Cell ;
26
27
use std:: cmp;
27
- use std:: gc:: { Gc , GC } ;
28
28
use std:: u32;
29
29
30
30
pub fn path_name_i ( idents : & [ Ident ] ) -> String {
@@ -98,7 +98,7 @@ pub fn unop_to_string(op: UnOp) -> &'static str {
98
98
}
99
99
}
100
100
101
- pub fn is_path ( e : Gc < Expr > ) -> bool {
101
+ pub fn is_path ( e : P < Expr > ) -> bool {
102
102
return match e. node { ExprPath ( _) => true , _ => false } ;
103
103
}
104
104
@@ -166,21 +166,6 @@ pub fn float_ty_to_string(t: FloatTy) -> String {
166
166
}
167
167
}
168
168
169
- pub fn is_call_expr ( e : Gc < Expr > ) -> bool {
170
- match e. node { ExprCall ( ..) => true , _ => false }
171
- }
172
-
173
- pub fn block_from_expr ( e : Gc < Expr > ) -> P < Block > {
174
- P ( Block {
175
- view_items : Vec :: new ( ) ,
176
- stmts : Vec :: new ( ) ,
177
- expr : Some ( e) ,
178
- id : e. id ,
179
- rules : DefaultBlock ,
180
- span : e. span
181
- } )
182
- }
183
-
184
169
// convert a span and an identifier to the corresponding
185
170
// 1-segment path
186
171
pub fn ident_to_path ( s : Span , identifier : Ident ) -> Path {
@@ -197,10 +182,12 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
197
182
}
198
183
}
199
184
200
- pub fn ident_to_pat ( id : NodeId , s : Span , i : Ident ) -> Gc < Pat > {
201
- box ( GC ) ast:: Pat { id : id,
202
- node : PatIdent ( BindByValue ( MutImmutable ) , codemap:: Spanned { span : s, node : i} , None ) ,
203
- span : s }
185
+ pub fn ident_to_pat ( id : NodeId , s : Span , i : Ident ) -> P < Pat > {
186
+ P ( Pat {
187
+ id : id,
188
+ node : PatIdent ( BindByValue ( MutImmutable ) , codemap:: Spanned { span : s, node : i} , None ) ,
189
+ span : s
190
+ } )
204
191
}
205
192
206
193
pub fn name_to_dummy_lifetime ( name : Name ) -> Lifetime {
@@ -226,57 +213,6 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident {
226
213
token:: gensym_ident ( pretty. as_slice ( ) )
227
214
}
228
215
229
- pub fn trait_method_to_ty_method ( method : & Method ) -> TypeMethod {
230
- match method. node {
231
- MethDecl ( ident,
232
- ref generics,
233
- abi,
234
- explicit_self,
235
- fn_style,
236
- decl,
237
- _,
238
- vis) => {
239
- TypeMethod {
240
- ident : ident,
241
- attrs : method. attrs . clone ( ) ,
242
- fn_style : fn_style,
243
- decl : decl,
244
- generics : generics. clone ( ) ,
245
- explicit_self : explicit_self,
246
- id : method. id ,
247
- span : method. span ,
248
- vis : vis,
249
- abi : abi,
250
- }
251
- } ,
252
- MethMac ( _) => fail ! ( "expected non-macro method declaration" )
253
- }
254
- }
255
-
256
- /// extract a TypeMethod from a TraitItem. if the TraitItem is
257
- /// a default, pull out the useful fields to make a TypeMethod
258
- //
259
- // NB: to be used only after expansion is complete, and macros are gone.
260
- pub fn trait_item_to_ty_method ( method : & TraitItem ) -> TypeMethod {
261
- match * method {
262
- RequiredMethod ( ref m) => ( * m) . clone ( ) ,
263
- ProvidedMethod ( ref m) => trait_method_to_ty_method ( & * * m) ,
264
- }
265
- }
266
-
267
- pub fn split_trait_methods ( trait_methods : & [ TraitItem ] )
268
- -> ( Vec < TypeMethod > , Vec < Gc < Method > > ) {
269
- let mut reqd = Vec :: new ( ) ;
270
- let mut provd = Vec :: new ( ) ;
271
- for trt_method in trait_methods. iter ( ) {
272
- match * trt_method {
273
- RequiredMethod ( ref tm) => reqd. push ( ( * tm) . clone ( ) ) ,
274
- ProvidedMethod ( m) => provd. push ( m)
275
- }
276
- } ;
277
- ( reqd, provd)
278
- }
279
-
280
216
pub fn struct_field_visibility ( field : ast:: StructField ) -> Visibility {
281
217
match field. node . kind {
282
218
ast:: NamedField ( _, v) | ast:: UnnamedField ( v) => v
@@ -603,13 +539,6 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
603
539
visitor. result . get ( )
604
540
}
605
541
606
- pub fn is_item_impl ( item : Gc < ast:: Item > ) -> bool {
607
- match item. node {
608
- ItemImpl ( ..) => true ,
609
- _ => false
610
- }
611
- }
612
-
613
542
pub fn walk_pat ( pat : & Pat , it: |& Pat | -> bool) -> bool {
614
543
if !it ( pat) {
615
544
return false ;
@@ -678,7 +607,7 @@ pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
678
607
679
608
/// Returns true if the given pattern consists solely of an identifier
680
609
/// and false otherwise.
681
- pub fn pat_is_ident ( pat : Gc < ast:: Pat > ) -> bool {
610
+ pub fn pat_is_ident ( pat : P < ast:: Pat > ) -> bool {
682
611
match pat. node {
683
612
ast:: PatIdent ( ..) => true ,
684
613
_ => false ,
@@ -713,28 +642,13 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo
713
642
}
714
643
715
644
/// Returns true if this literal is a string and false otherwise.
716
- pub fn lit_is_str ( lit : Gc < Lit > ) -> bool {
645
+ pub fn lit_is_str ( lit : & Lit ) -> bool {
717
646
match lit. node {
718
647
LitStr ( ..) => true ,
719
648
_ => false ,
720
649
}
721
650
}
722
651
723
- pub fn get_inner_tys ( ty : P < Ty > ) -> Vec < P < Ty > > {
724
- match ty. node {
725
- ast:: TyRptr ( _, mut_ty) | ast:: TyPtr ( mut_ty) => {
726
- vec ! ( mut_ty. ty)
727
- }
728
- ast:: TyBox ( ty)
729
- | ast:: TyVec ( ty)
730
- | ast:: TyUniq ( ty)
731
- | ast:: TyFixedLengthVec ( ty, _) => vec ! ( ty) ,
732
- ast:: TyTup ( ref tys) => tys. clone ( ) ,
733
- ast:: TyParen ( ty) => get_inner_tys ( ty) ,
734
- _ => Vec :: new ( )
735
- }
736
- }
737
-
738
652
/// Returns true if the static with the given mutability and attributes
739
653
/// has a significant address and false otherwise.
740
654
pub fn static_has_significant_address ( mutbl : ast:: Mutability ,
@@ -757,13 +671,13 @@ pub trait PostExpansionMethod {
757
671
fn pe_abi ( & self ) -> Abi ;
758
672
fn pe_explicit_self < ' a > ( & ' a self ) -> & ' a ast:: ExplicitSelf ;
759
673
fn pe_fn_style ( & self ) -> ast:: FnStyle ;
760
- fn pe_fn_decl ( & self ) -> P < ast:: FnDecl > ;
761
- fn pe_body ( & self ) -> P < ast:: Block > ;
674
+ fn pe_fn_decl < ' a > ( & ' a self ) -> & ' a ast:: FnDecl ;
675
+ fn pe_body < ' a > ( & ' a self ) -> & ' a ast:: Block ;
762
676
fn pe_vis ( & self ) -> ast:: Visibility ;
763
677
}
764
678
765
679
macro_rules! mf_method{
766
- ( $meth_name: ident, $field_ty: ty, $field_pat: pat, $result: ident ) => {
680
+ ( $meth_name: ident, $field_ty: ty, $field_pat: pat, $result: expr ) => {
767
681
fn $meth_name<' a>( & ' a self ) -> $field_ty {
768
682
match self . node {
769
683
$field_pat => $result,
@@ -784,8 +698,8 @@ impl PostExpansionMethod for Method {
784
698
mf_method ! ( pe_explicit_self, & ' a ast:: ExplicitSelf ,
785
699
MethDecl ( _, _, _, ref explicit_self, _, _, _, _) , explicit_self)
786
700
mf_method ! ( pe_fn_style, ast:: FnStyle , MethDecl ( _, _, _, _, fn_style, _, _, _) , fn_style)
787
- mf_method ! ( pe_fn_decl, P < ast:: FnDecl > , MethDecl ( _, _, _, _, _, decl, _, _) , decl)
788
- mf_method ! ( pe_body, P < ast:: Block > , MethDecl ( _, _, _, _, _, _, body, _) , body)
701
+ mf_method ! ( pe_fn_decl, & ' a ast:: FnDecl , MethDecl ( _, _, _, _, _, ref decl, _, _) , & * * decl)
702
+ mf_method ! ( pe_body, & ' a ast:: Block , MethDecl ( _, _, _, _, _, _, ref body, _) , & * * body)
789
703
mf_method ! ( pe_vis, ast:: Visibility , MethDecl ( _, _, _, _, _, _, _, vis) , vis)
790
704
}
791
705
0 commit comments