]> git.lizzy.rs Git - rust.git/commitdiff
syntax: add IterBytes impls for some ast types
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Sat, 27 Apr 2013 17:57:07 +0000 (10:57 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Wed, 15 May 2013 03:10:46 +0000 (20:10 -0700)
src/libsyntax/ast.rs
src/libsyntax/codemap.rs

index 94bd9a185891229448ccf969f4a2ca754c5c6c2a..4ef38c300c62f11d24ea487a49e29d46e73dbe23 100644 (file)
@@ -17,6 +17,7 @@
 use core::cast;
 use core::option::{None, Option, Some};
 use core::to_bytes;
+use core::to_bytes::IterBytes;
 use core::to_str::ToStr;
 use std::serialize::{Encodable, Decodable, Encoder, Decoder};
 
@@ -121,6 +122,20 @@ pub struct Lifetime {
     ident: ident
 }
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for Lifetime {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for Lifetime {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
+    }
+}
+
 // a "Path" is essentially Rust's notion of a name;
 // for instance: core::cmp::Eq  .  It's represented
 // as a sequence of identifiers, along with a bunch
@@ -1057,6 +1072,32 @@ pub enum self_ty_ {
     sty_uniq(mutability)                       // `~self`
 }
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for self_ty_ {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        match *self {
+            sty_static => 0u8.iter_bytes(lsb0, f),
+            sty_value => 1u8.iter_bytes(lsb0, f),
+            sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
+            sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
+            sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
+        }
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for self_ty_ {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        match *self {
+            sty_static => 0u8.iter_bytes(lsb0, f),
+            sty_value => 1u8.iter_bytes(lsb0, f),
+            sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
+            sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
+            sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
+        }
+    }
+}
+
 pub type self_ty = spanned<self_ty_>;
 
 #[auto_encode]
index e0392b476e458ca8095e18022d3ad03efb1ef38d..cd0b29f2a1e3f12024a055812eea467873a0d8f6 100644 (file)
@@ -152,6 +152,20 @@ fn decode(_d: &mut D) -> span {
     }
 }
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for span {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f);
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for span {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f)
+    }
+}
+
 pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> {
     respan(mk_sp(lo, hi), t)
 }
@@ -199,16 +213,62 @@ pub struct FileMapAndLine {fm: @FileMap, line: uint}
 pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
 pub struct NameAndSpan {name: ~str, span: Option<span>}
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for NameAndSpan {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for NameAndSpan {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
+    }
+}
+
 pub struct CallInfo {
     call_site: span,
     callee: NameAndSpan
 }
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for CallInfo {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for CallInfo {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
+    }
+}
+
 /// Extra information for tracking macro expansion of spans
 pub enum ExpnInfo {
     ExpandedFrom(CallInfo)
 }
 
+#[cfg(stage0)]
+impl to_bytes::IterBytes for ExpnInfo {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
+        match *self {
+            ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
+        }
+    }
+}
+
+#[cfg(not(stage0))]
+impl to_bytes::IterBytes for ExpnInfo {
+    fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
+        match *self {
+            ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
+        }
+    }
+}
+
 pub type FileName = ~str;
 
 pub struct FileLines