Skip to content

Commit 8d19f44

Browse files
committed
syntax: add IterBytes impls for some ast types
1 parent 4bfe0f7 commit 8d19f44

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/libsyntax/ast.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use opt_vec::OptVec;
1717
use core::cast;
1818
use core::option::{None, Option, Some};
1919
use core::to_bytes;
20+
use core::to_bytes::IterBytes;
2021
use core::to_str::ToStr;
2122
use std::serialize::{Encodable, Decodable, Encoder, Decoder};
2223

@@ -121,6 +122,20 @@ pub struct Lifetime {
121122
ident: ident
122123
}
123124

125+
#[cfg(stage0)]
126+
impl to_bytes::IterBytes for Lifetime {
127+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
128+
to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
129+
}
130+
}
131+
132+
#[cfg(not(stage0))]
133+
impl to_bytes::IterBytes for Lifetime {
134+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
135+
to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
136+
}
137+
}
138+
124139
// a "Path" is essentially Rust's notion of a name;
125140
// for instance: core::cmp::Eq . It's represented
126141
// as a sequence of identifiers, along with a bunch
@@ -1057,6 +1072,32 @@ pub enum self_ty_ {
10571072
sty_uniq(mutability) // `~self`
10581073
}
10591074
1075+
#[cfg(stage0)]
1076+
impl to_bytes::IterBytes for self_ty_ {
1077+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
1078+
match *self {
1079+
sty_static => 0u8.iter_bytes(lsb0, f),
1080+
sty_value => 1u8.iter_bytes(lsb0, f),
1081+
sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
1082+
sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
1083+
sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
1084+
}
1085+
}
1086+
}
1087+
1088+
#[cfg(not(stage0))]
1089+
impl to_bytes::IterBytes for self_ty_ {
1090+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
1091+
match *self {
1092+
sty_static => 0u8.iter_bytes(lsb0, f),
1093+
sty_value => 1u8.iter_bytes(lsb0, f),
1094+
sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
1095+
sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
1096+
sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
1097+
}
1098+
}
1099+
}
1100+
10601101
pub type self_ty = spanned<self_ty_>;
10611102
10621103
#[auto_encode]

src/libsyntax/codemap.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ impl<D:Decoder> Decodable<D> for span {
152152
}
153153
}
154154

155+
#[cfg(stage0)]
156+
impl to_bytes::IterBytes for span {
157+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
158+
to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f);
159+
}
160+
}
161+
162+
#[cfg(not(stage0))]
163+
impl to_bytes::IterBytes for span {
164+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
165+
to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f)
166+
}
167+
}
168+
155169
pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> {
156170
respan(mk_sp(lo, hi), t)
157171
}
@@ -199,16 +213,62 @@ pub struct FileMapAndLine {fm: @FileMap, line: uint}
199213
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
200214
pub struct NameAndSpan {name: ~str, span: Option<span>}
201215

216+
#[cfg(stage0)]
217+
impl to_bytes::IterBytes for NameAndSpan {
218+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
219+
to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
220+
}
221+
}
222+
223+
#[cfg(not(stage0))]
224+
impl to_bytes::IterBytes for NameAndSpan {
225+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
226+
to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
227+
}
228+
}
229+
202230
pub struct CallInfo {
203231
call_site: span,
204232
callee: NameAndSpan
205233
}
206234

235+
#[cfg(stage0)]
236+
impl to_bytes::IterBytes for CallInfo {
237+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
238+
to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
239+
}
240+
}
241+
242+
#[cfg(not(stage0))]
243+
impl to_bytes::IterBytes for CallInfo {
244+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
245+
to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
246+
}
247+
}
248+
207249
/// Extra information for tracking macro expansion of spans
208250
pub enum ExpnInfo {
209251
ExpandedFrom(CallInfo)
210252
}
211253

254+
#[cfg(stage0)]
255+
impl to_bytes::IterBytes for ExpnInfo {
256+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
257+
match *self {
258+
ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
259+
}
260+
}
261+
}
262+
263+
#[cfg(not(stage0))]
264+
impl to_bytes::IterBytes for ExpnInfo {
265+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
266+
match *self {
267+
ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
268+
}
269+
}
270+
}
271+
212272
pub type FileName = ~str;
213273

214274
pub struct FileLines

0 commit comments

Comments
 (0)