@@ -19,12 +19,12 @@ use codemap::Span;
1919use owned_slice:: OwnedSlice ;
2020use parse:: token;
2121use print:: pprust;
22+ use ptr:: P ;
2223use visit:: Visitor ;
2324use visit;
2425
2526use std:: cell:: Cell ;
2627use std:: cmp;
27- use std:: gc:: { Gc , GC } ;
2828use std:: u32;
2929
3030pub fn path_name_i ( idents : & [ Ident ] ) -> String {
@@ -98,7 +98,7 @@ pub fn unop_to_string(op: UnOp) -> &'static str {
9898 }
9999}
100100
101- pub fn is_path ( e : Gc < Expr > ) -> bool {
101+ pub fn is_path ( e : P < Expr > ) -> bool {
102102 return match e. node { ExprPath ( _) => true , _ => false } ;
103103}
104104
@@ -166,21 +166,6 @@ pub fn float_ty_to_string(t: FloatTy) -> String {
166166 }
167167}
168168
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-
184169// convert a span and an identifier to the corresponding
185170// 1-segment path
186171pub fn ident_to_path ( s : Span , identifier : Ident ) -> Path {
@@ -197,10 +182,12 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
197182 }
198183}
199184
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+ } )
204191}
205192
206193pub fn name_to_dummy_lifetime ( name : Name ) -> Lifetime {
@@ -226,57 +213,6 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident {
226213 token:: gensym_ident ( pretty. as_slice ( ) )
227214}
228215
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-
280216pub fn struct_field_visibility ( field : ast:: StructField ) -> Visibility {
281217 match field. node . kind {
282218 ast:: NamedField ( _, v) | ast:: UnnamedField ( v) => v
@@ -603,13 +539,6 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
603539 visitor. result . get ( )
604540}
605541
606- pub fn is_item_impl ( item : Gc < ast:: Item > ) -> bool {
607- match item. node {
608- ItemImpl ( ..) => true ,
609- _ => false
610- }
611- }
612-
613542pub fn walk_pat ( pat : & Pat , it: |& Pat | -> bool) -> bool {
614543 if !it ( pat) {
615544 return false ;
@@ -678,7 +607,7 @@ pub fn struct_def_is_tuple_like(struct_def: &ast::StructDef) -> bool {
678607
679608/// Returns true if the given pattern consists solely of an identifier
680609/// 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 {
682611 match pat. node {
683612 ast:: PatIdent ( ..) => true ,
684613 _ => false ,
@@ -713,28 +642,13 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo
713642}
714643
715644/// 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 {
717646 match lit. node {
718647 LitStr ( ..) => true ,
719648 _ => false ,
720649 }
721650}
722651
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-
738652/// Returns true if the static with the given mutability and attributes
739653/// has a significant address and false otherwise.
740654pub fn static_has_significant_address ( mutbl : ast:: Mutability ,
@@ -757,13 +671,13 @@ pub trait PostExpansionMethod {
757671 fn pe_abi ( & self ) -> Abi ;
758672 fn pe_explicit_self < ' a > ( & ' a self ) -> & ' a ast:: ExplicitSelf ;
759673 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 ;
762676 fn pe_vis ( & self ) -> ast:: Visibility ;
763677}
764678
765679macro_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 ) => {
767681 fn $meth_name<' a>( & ' a self ) -> $field_ty {
768682 match self . node {
769683 $field_pat => $result,
@@ -784,8 +698,8 @@ impl PostExpansionMethod for Method {
784698 mf_method ! ( pe_explicit_self, & ' a ast:: ExplicitSelf ,
785699 MethDecl ( _, _, _, ref explicit_self, _, _, _, _) , explicit_self)
786700 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)
789703 mf_method ! ( pe_vis, ast:: Visibility , MethDecl ( _, _, _, _, _, _, _, vis) , vis)
790704}
791705
0 commit comments