]> git.proxmox.com Git - rustc.git/blobdiff - src/libsyntax/ast_util.rs
Imported Upstream version 1.7.0+dfsg1
[rustc.git] / src / libsyntax / ast_util.rs
index 489c61b83da75b3108a7783ecd9fee89e9912e8b..ba4d1e2193e5f0f49be54071dd73dca53783f282 100644 (file)
 
 use ast::*;
 use ast;
-use ast_util;
 use codemap;
 use codemap::Span;
-use owned_slice::OwnedSlice;
 use parse::token;
 use print::pprust;
 use ptr::P;
@@ -28,144 +26,10 @@ pub fn path_name_i(idents: &[Ident]) -> String {
     idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
 }
 
-pub fn stmt_id(s: &Stmt) -> Option<NodeId> {
-    match s.node {
-      StmtDecl(_, id) => Some(id),
-      StmtExpr(_, id) => Some(id),
-      StmtSemi(_, id) => Some(id),
-      StmtMac(..) => None,
-    }
-}
-
-pub fn binop_to_string(op: BinOp_) -> &'static str {
-    match op {
-        BiAdd => "+",
-        BiSub => "-",
-        BiMul => "*",
-        BiDiv => "/",
-        BiRem => "%",
-        BiAnd => "&&",
-        BiOr => "||",
-        BiBitXor => "^",
-        BiBitAnd => "&",
-        BiBitOr => "|",
-        BiShl => "<<",
-        BiShr => ">>",
-        BiEq => "==",
-        BiLt => "<",
-        BiLe => "<=",
-        BiNe => "!=",
-        BiGe => ">=",
-        BiGt => ">"
-    }
-}
-
-pub fn lazy_binop(b: BinOp_) -> bool {
-    match b {
-      BiAnd => true,
-      BiOr => true,
-      _ => false
-    }
-}
-
-pub fn is_shift_binop(b: BinOp_) -> bool {
-    match b {
-      BiShl => true,
-      BiShr => true,
-      _ => false
-    }
-}
-
-pub fn is_comparison_binop(b: BinOp_) -> bool {
-    match b {
-        BiEq | BiLt | BiLe | BiNe | BiGt | BiGe =>
-            true,
-        BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
-        BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr =>
-            false,
-    }
-}
-
-/// Returns `true` if the binary operator takes its arguments by value
-pub fn is_by_value_binop(b: BinOp_) -> bool {
-    !is_comparison_binop(b)
-}
-
-/// Returns `true` if the unary operator takes its argument by value
-pub fn is_by_value_unop(u: UnOp) -> bool {
-    match u {
-        UnNeg | UnNot => true,
-        _ => false,
-    }
-}
-
-pub fn unop_to_string(op: UnOp) -> &'static str {
-    match op {
-        UnDeref => "*",
-        UnNot => "!",
-        UnNeg => "-",
-    }
-}
-
 pub fn is_path(e: P<Expr>) -> bool {
     match e.node { ExprPath(..) => true, _ => false }
 }
 
-pub fn int_ty_to_string(t: IntTy) -> &'static str {
-    match t {
-        TyIs => "isize",
-        TyI8 => "i8",
-        TyI16 => "i16",
-        TyI32 => "i32",
-        TyI64 => "i64"
-    }
-}
-
-pub fn int_val_to_string(t: IntTy, val: i64) -> String {
-    // cast to a u64 so we can correctly print INT64_MIN. All integral types
-    // are parsed as u64, so we wouldn't want to print an extra negative
-    // sign.
-    format!("{}{}", val as u64, int_ty_to_string(t))
-}
-
-pub fn int_ty_max(t: IntTy) -> u64 {
-    match t {
-        TyI8 => 0x80,
-        TyI16 => 0x8000,
-        TyIs | TyI32 => 0x80000000, // actually ni about TyIs
-        TyI64 => 0x8000000000000000
-    }
-}
-
-pub fn uint_ty_to_string(t: UintTy) -> &'static str {
-    match t {
-        TyUs => "usize",
-        TyU8 => "u8",
-        TyU16 => "u16",
-        TyU32 => "u32",
-        TyU64 => "u64"
-    }
-}
-
-pub fn uint_val_to_string(t: UintTy, val: u64) -> String {
-    format!("{}{}", val, uint_ty_to_string(t))
-}
-
-pub fn uint_ty_max(t: UintTy) -> u64 {
-    match t {
-        TyU8 => 0xff,
-        TyU16 => 0xffff,
-        TyUs | TyU32 => 0xffffffff, // actually ni about TyUs
-        TyU64 => 0xffffffffffffffff
-    }
-}
-
-pub fn float_ty_to_string(t: FloatTy) -> &'static str {
-    match t {
-        TyF32 => "f32",
-        TyF64 => "f64",
-    }
-}
 
 // convert a span and an identifier to the corresponding
 // 1-segment path
@@ -176,10 +40,10 @@ pub fn ident_to_path(s: Span, identifier: Ident) -> Path {
         segments: vec!(
             ast::PathSegment {
                 identifier: identifier,
-                parameters: ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
+                parameters: ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
                     lifetimes: Vec::new(),
-                    types: OwnedSlice::empty(),
-                    bindings: OwnedSlice::empty(),
+                    types: P::empty(),
+                    bindings: P::empty(),
                 })
             }
         ),
@@ -204,7 +68,7 @@ pub fn path_to_ident(path: &Path) -> Option<Ident> {
 pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> {
     P(Pat {
         id: id,
-        node: PatIdent(BindByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None),
+        node: PatIdent(BindingMode::ByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None),
         span: s
     })
 }
@@ -236,17 +100,6 @@ pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
     }
 }
 
-pub fn empty_generics() -> Generics {
-    Generics {
-        lifetimes: Vec::new(),
-        ty_params: OwnedSlice::empty(),
-        where_clause: WhereClause {
-            id: DUMMY_NODE_ID,
-            predicates: Vec::new(),
-        }
-    }
-}
-
 // ______________________________________________________________________
 // Enumerating the IDs which appear in an AST
 
@@ -351,7 +204,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
 
     fn visit_stmt(&mut self, statement: &Stmt) {
         self.operation
-            .visit_id(ast_util::stmt_id(statement).expect("attempted to visit unexpanded stmt"));
+            .visit_id(statement.node.id().expect("attempted to visit unexpanded stmt"));
         visit::walk_stmt(self, statement)
     }
 
@@ -519,14 +372,6 @@ pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> boo
     })
 }
 
-/// Returns true if this literal is a string and false otherwise.
-pub fn lit_is_str(lit: &Lit) -> bool {
-    match lit.node {
-        LitStr(..) => true,
-        _ => false,
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use ast::*;