about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-05-02 18:33:33 -0400
committerAlex Crichton <alex@alexcrichton.com>2013-05-10 02:46:18 -0400
commit5eb6d19803ebcb5279f8a42b584a4d81152fa82d (patch)
treef64e9e944ccaaf83b8a993c0ce1c404f22c9cd41 /src/libsyntax
parent3ce9dba6775c7e1dbfb510626c073a8f926b6880 (diff)
downloadrust-5eb6d19803ebcb5279f8a42b584a4d81152fa82d.tar.gz
rust-5eb6d19803ebcb5279f8a42b584a4d81152fa82d.zip
syntax: Use the new `for` protocol
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/abi.rs29
-rw-r--r--src/libsyntax/ast.rs83
-rw-r--r--src/libsyntax/ast_util.rs9
-rw-r--r--src/libsyntax/codemap.rs14
-rw-r--r--src/libsyntax/ext/expand.rs14
-rw-r--r--src/libsyntax/ext/pipes/proto.rs16
-rw-r--r--src/libsyntax/opt_vec.rs14
-rw-r--r--src/libsyntax/parse/obsolete.rs8
-rw-r--r--src/libsyntax/parse/token.rs7
9 files changed, 182 insertions, 12 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs
index 75782e9ca67..f266b8871a2 100644
--- a/src/libsyntax/abi.rs
+++ b/src/libsyntax/abi.rs
@@ -81,6 +81,7 @@ static AbiDatas: &'static [AbiData] = &[
     AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
 ];
 
+#[cfg(stage0)]
 fn each_abi(op: &fn(abi: Abi) -> bool) {
     /*!
      *
@@ -93,6 +94,15 @@ fn each_abi(op: &fn(abi: Abi) -> bool) {
         }
     }
 }
+#[cfg(not(stage0))]
+fn each_abi(op: &fn(abi: Abi) -> bool) -> bool {
+    /*!
+     *
+     * Iterates through each of the defined ABIs.
+     */
+
+    AbiDatas.each(|abi_data| op(abi_data.abi))
+}
 
 pub fn lookup(name: &str) -> Option<Abi> {
     /*!
@@ -189,6 +199,7 @@ pub impl AbiSet {
         self.bits |= (1 << abi.index());
     }
 
+    #[cfg(stage0)]
     fn each(&self, op: &fn(abi: Abi) -> bool) {
         for each_abi |abi| {
             if self.contains(abi) {
@@ -198,6 +209,10 @@ pub impl AbiSet {
             }
         }
     }
+    #[cfg(not(stage0))]
+    fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
+        each_abi(|abi| !self.contains(abi) || op(abi))
+    }
 
     fn is_empty(&self) -> bool {
         self.bits == 0
@@ -252,17 +267,31 @@ pub impl AbiSet {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Abi {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.index().iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Abi {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.index().iter_bytes(lsb0, f)
+    }
+}
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for AbiSet {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.bits.iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for AbiSet {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.bits.iter_bytes(lsb0, f)
+    }
+}
 
 impl ToStr for Abi {
     fn to_str(&self) -> ~str {
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index c8fc04eaea1..c516ebc402f 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -97,11 +97,18 @@ impl<D:Decoder> Decodable<D> for ident {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ident {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         self.repr.iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ident {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        self.repr.iter_bytes(lsb0, f)
+    }
+}
 
 // Functions may or may not have names.
 pub type fn_ident = Option<ident>;
@@ -284,6 +291,7 @@ pub enum binding_mode {
     bind_infer
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for binding_mode {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         match *self {
@@ -297,6 +305,18 @@ impl to_bytes::IterBytes for binding_mode {
         }
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for binding_mode {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        match *self {
+          bind_by_copy => 0u8.iter_bytes(lsb0, f),
+
+          bind_by_ref(ref m) => to_bytes::iter_bytes_2(&1u8, m, lsb0, f),
+
+          bind_infer => 2u8.iter_bytes(lsb0, f),
+        }
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -330,11 +350,18 @@ pub enum pat_ {
 #[deriving(Eq)]
 pub enum mutability { m_mutbl, m_imm, m_const, }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for mutability {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for mutability {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -345,11 +372,18 @@ pub enum Sigil {
     ManagedSigil
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Sigil {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Sigil {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 impl ToStr for Sigil {
     fn to_str(&self) -> ~str {
@@ -744,11 +778,18 @@ impl ToStr for int_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for int_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for int_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -761,11 +802,18 @@ impl ToStr for uint_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for uint_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for uint_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -778,11 +826,18 @@ impl ToStr for float_ty {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for float_ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for float_ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 // NB Eq method appears below.
 #[auto_encode]
@@ -823,11 +878,18 @@ impl ToStr for Onceness {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Onceness {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Onceness {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -874,11 +936,18 @@ pub enum ty_ {
     ty_infer,
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for Ty {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Ty {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -941,11 +1010,18 @@ impl ToStr for purity {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for purity {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for purity {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
@@ -956,11 +1032,18 @@ pub enum ret_style {
     return_val, // everything else
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ret_style {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as u8).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ret_style {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as u8).iter_bytes(lsb0, f)
+    }
+}
 
 #[auto_encode]
 #[auto_decode]
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 77277dea814..ceff868d11f 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -191,12 +191,21 @@ pub fn is_call_expr(e: @expr) -> bool {
 }
 
 // This makes def_id hashable
+#[cfg(stage0)]
 impl to_bytes::IterBytes for def_id {
     #[inline(always)]
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f);
     }
 }
+// This makes def_id hashable
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for def_id {
+    #[inline(always)]
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f)
+    }
+}
 
 pub fn block_from_expr(e: @expr) -> blk {
     let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 846097550d1..053ed76d66b 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -65,11 +65,18 @@ impl Sub<BytePos, BytePos> for BytePos {
     }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for BytePos {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for BytePos {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 impl Pos for CharPos {
     fn from_uint(n: uint) -> CharPos { CharPos(n) }
@@ -83,11 +90,18 @@ impl cmp::Ord for CharPos {
     fn gt(&self, other: &CharPos) -> bool { **self > **other }
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for CharPos {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f)
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for CharPos {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 impl Add<CharPos,CharPos> for CharPos {
     fn add(&self, rhs: &CharPos) -> CharPos {
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 68c74c2d12b..5129fa6ebd2 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -195,18 +195,8 @@ pub fn expand_item(extsbox: @mut SyntaxEnv,
 }
 
 // does this attribute list contain "macro_escape" ?
-pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool{
-    let mut accum = false;
-    do attrs.each |attr| {
-        let mname = attr::get_attr_name(attr);
-        if (mname == @~"macro_escape") {
-            accum = true;
-            false
-        } else {
-            true
-        }
-    }
-    accum
+pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool {
+    attrs.any(|attr| "macro_escape" == *attr::get_attr_name(attr))
 }
 
 // this macro disables (one layer of) macro
diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs
index 647c7741bd8..7c78ec066d0 100644
--- a/src/libsyntax/ext/pipes/proto.rs
+++ b/src/libsyntax/ext/pipes/proto.rs
@@ -100,6 +100,7 @@ pub impl state_ {
 
     /// Iterate over the states that can be reached in one message
     /// from this state.
+    #[cfg(stage0)]
     fn reachable(&self, f: &fn(state) -> bool) {
         for self.messages.each |m| {
             match *m {
@@ -111,6 +112,21 @@ pub impl state_ {
             }
         }
     }
+    /// Iterate over the states that can be reached in one message
+    /// from this state.
+    #[cfg(not(stage0))]
+    fn reachable(&self, f: &fn(state) -> bool) -> bool {
+        for self.messages.each |m| {
+            match *m {
+              message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
+                let state = self.proto.get_state((*id));
+                if !f(state) { return false; }
+              }
+              _ => ()
+            }
+        }
+        return true;
+    }
 }
 
 pub type protocol = @mut protocol_;
diff --git a/src/libsyntax/opt_vec.rs b/src/libsyntax/opt_vec.rs
index 600ab964e52..6110579863d 100644
--- a/src/libsyntax/opt_vec.rs
+++ b/src/libsyntax/opt_vec.rs
@@ -132,12 +132,20 @@ impl<A:Eq> Eq for OptVec<A> {
 }
 
 impl<A> BaseIter<A> for OptVec<A> {
+    #[cfg(stage0)]
     fn each(&self, blk: &fn(v: &A) -> bool) {
         match *self {
             Empty => {}
             Vec(ref v) => v.each(blk)
         }
     }
+    #[cfg(not(stage0))]
+    fn each(&self, blk: &fn(v: &A) -> bool) -> bool {
+        match *self {
+            Empty => true,
+            Vec(ref v) => v.each(blk)
+        }
+    }
 
     fn size_hint(&self) -> Option<uint> {
         Some(self.len())
@@ -146,10 +154,16 @@ impl<A> BaseIter<A> for OptVec<A> {
 
 impl<A> old_iter::ExtendedIter<A> for OptVec<A> {
     #[inline(always)]
+    #[cfg(stage0)]
     fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) {
         old_iter::eachi(self, blk)
     }
     #[inline(always)]
+    #[cfg(not(stage0))]
+    fn eachi(&self, blk: &fn(v: uint, v: &A) -> bool) -> bool {
+        old_iter::eachi(self, blk)
+    }
+    #[inline(always)]
     fn all(&self, blk: &fn(&A) -> bool) -> bool {
         old_iter::all(self, blk)
     }
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index e486a6254e7..a4ac038cf46 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -62,12 +62,20 @@ pub enum ObsoleteSyntax {
     ObsoleteFixedLengthVectorType,
 }
 
+#[cfg(stage0)]
 impl to_bytes::IterBytes for ObsoleteSyntax {
     #[inline(always)]
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (*self as uint).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ObsoleteSyntax {
+    #[inline(always)]
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (*self as uint).iter_bytes(lsb0, f)
+    }
+}
 
 pub impl Parser {
     /// Reports an obsolete syntax non-fatal error.
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index fe7bd5b3bc1..15441b6fcfc 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -355,11 +355,18 @@ impl<'self> Equiv<@~str> for StringRef<'self> {
     fn equiv(&self, other: &@~str) -> bool { str::eq_slice(**self, **other) }
 }
 
+#[cfg(stage0)]
 impl<'self> to_bytes::IterBytes for StringRef<'self> {
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
         (**self).iter_bytes(lsb0, f);
     }
 }
+#[cfg(not(stage0))]
+impl<'self> to_bytes::IterBytes for StringRef<'self> {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        (**self).iter_bytes(lsb0, f)
+    }
+}
 
 /**
  * Maps a token to a record specifying the corresponding binary