Skip to content

Commit 5eb6d19

Browse files
committed
syntax: Use the new for protocol
1 parent 3ce9dba commit 5eb6d19

File tree

9 files changed

+182
-12
lines changed

9 files changed

+182
-12
lines changed

src/libsyntax/abi.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static AbiDatas: &'static [AbiData] = &[
8181
AbiData {abi: RustIntrinsic, name: "rust-intrinsic", abi_arch: RustArch},
8282
];
8383

84+
#[cfg(stage0)]
8485
fn each_abi(op: &fn(abi: Abi) -> bool) {
8586
/*!
8687
*
@@ -93,6 +94,15 @@ fn each_abi(op: &fn(abi: Abi) -> bool) {
9394
}
9495
}
9596
}
97+
#[cfg(not(stage0))]
98+
fn each_abi(op: &fn(abi: Abi) -> bool) -> bool {
99+
/*!
100+
*
101+
* Iterates through each of the defined ABIs.
102+
*/
103+
104+
AbiDatas.each(|abi_data| op(abi_data.abi))
105+
}
96106

97107
pub fn lookup(name: &str) -> Option<Abi> {
98108
/*!
@@ -189,6 +199,7 @@ pub impl AbiSet {
189199
self.bits |= (1 << abi.index());
190200
}
191201

202+
#[cfg(stage0)]
192203
fn each(&self, op: &fn(abi: Abi) -> bool) {
193204
for each_abi |abi| {
194205
if self.contains(abi) {
@@ -198,6 +209,10 @@ pub impl AbiSet {
198209
}
199210
}
200211
}
212+
#[cfg(not(stage0))]
213+
fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
214+
each_abi(|abi| !self.contains(abi) || op(abi))
215+
}
201216

202217
fn is_empty(&self) -> bool {
203218
self.bits == 0
@@ -252,17 +267,31 @@ pub impl AbiSet {
252267
}
253268
}
254269

270+
#[cfg(stage0)]
255271
impl to_bytes::IterBytes for Abi {
256272
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
257273
self.index().iter_bytes(lsb0, f)
258274
}
259275
}
276+
#[cfg(not(stage0))]
277+
impl to_bytes::IterBytes for Abi {
278+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
279+
self.index().iter_bytes(lsb0, f)
280+
}
281+
}
260282

283+
#[cfg(stage0)]
261284
impl to_bytes::IterBytes for AbiSet {
262285
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
263286
self.bits.iter_bytes(lsb0, f)
264287
}
265288
}
289+
#[cfg(not(stage0))]
290+
impl to_bytes::IterBytes for AbiSet {
291+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
292+
self.bits.iter_bytes(lsb0, f)
293+
}
294+
}
266295

267296
impl ToStr for Abi {
268297
fn to_str(&self) -> ~str {

src/libsyntax/ast.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,18 @@ impl<D:Decoder> Decodable<D> for ident {
9797
}
9898
}
9999
100+
#[cfg(stage0)]
100101
impl to_bytes::IterBytes for ident {
101102
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
102103
self.repr.iter_bytes(lsb0, f)
103104
}
104105
}
106+
#[cfg(not(stage0))]
107+
impl to_bytes::IterBytes for ident {
108+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
109+
self.repr.iter_bytes(lsb0, f)
110+
}
111+
}
105112
106113
// Functions may or may not have names.
107114
pub type fn_ident = Option<ident>;
@@ -284,6 +291,7 @@ pub enum binding_mode {
284291
bind_infer
285292
}
286293
294+
#[cfg(stage0)]
287295
impl to_bytes::IterBytes for binding_mode {
288296
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
289297
match *self {
@@ -297,6 +305,18 @@ impl to_bytes::IterBytes for binding_mode {
297305
}
298306
}
299307
}
308+
#[cfg(not(stage0))]
309+
impl to_bytes::IterBytes for binding_mode {
310+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
311+
match *self {
312+
bind_by_copy => 0u8.iter_bytes(lsb0, f),
313+
314+
bind_by_ref(ref m) => to_bytes::iter_bytes_2(&1u8, m, lsb0, f),
315+
316+
bind_infer => 2u8.iter_bytes(lsb0, f),
317+
}
318+
}
319+
}
300320
301321
#[auto_encode]
302322
#[auto_decode]
@@ -330,11 +350,18 @@ pub enum pat_ {
330350
#[deriving(Eq)]
331351
pub enum mutability { m_mutbl, m_imm, m_const, }
332352
353+
#[cfg(stage0)]
333354
impl to_bytes::IterBytes for mutability {
334355
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
335356
(*self as u8).iter_bytes(lsb0, f)
336357
}
337358
}
359+
#[cfg(not(stage0))]
360+
impl to_bytes::IterBytes for mutability {
361+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
362+
(*self as u8).iter_bytes(lsb0, f)
363+
}
364+
}
338365
339366
#[auto_encode]
340367
#[auto_decode]
@@ -345,11 +372,18 @@ pub enum Sigil {
345372
ManagedSigil
346373
}
347374
375+
#[cfg(stage0)]
348376
impl to_bytes::IterBytes for Sigil {
349377
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
350378
(*self as uint).iter_bytes(lsb0, f)
351379
}
352380
}
381+
#[cfg(not(stage0))]
382+
impl to_bytes::IterBytes for Sigil {
383+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
384+
(*self as uint).iter_bytes(lsb0, f)
385+
}
386+
}
353387
354388
impl ToStr for Sigil {
355389
fn to_str(&self) -> ~str {
@@ -744,11 +778,18 @@ impl ToStr for int_ty {
744778
}
745779
}
746780
781+
#[cfg(stage0)]
747782
impl to_bytes::IterBytes for int_ty {
748783
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
749784
(*self as u8).iter_bytes(lsb0, f)
750785
}
751786
}
787+
#[cfg(not(stage0))]
788+
impl to_bytes::IterBytes for int_ty {
789+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
790+
(*self as u8).iter_bytes(lsb0, f)
791+
}
792+
}
752793
753794
#[auto_encode]
754795
#[auto_decode]
@@ -761,11 +802,18 @@ impl ToStr for uint_ty {
761802
}
762803
}
763804
805+
#[cfg(stage0)]
764806
impl to_bytes::IterBytes for uint_ty {
765807
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
766808
(*self as u8).iter_bytes(lsb0, f)
767809
}
768810
}
811+
#[cfg(not(stage0))]
812+
impl to_bytes::IterBytes for uint_ty {
813+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
814+
(*self as u8).iter_bytes(lsb0, f)
815+
}
816+
}
769817
770818
#[auto_encode]
771819
#[auto_decode]
@@ -778,11 +826,18 @@ impl ToStr for float_ty {
778826
}
779827
}
780828
829+
#[cfg(stage0)]
781830
impl to_bytes::IterBytes for float_ty {
782831
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
783832
(*self as u8).iter_bytes(lsb0, f)
784833
}
785834
}
835+
#[cfg(not(stage0))]
836+
impl to_bytes::IterBytes for float_ty {
837+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
838+
(*self as u8).iter_bytes(lsb0, f)
839+
}
840+
}
786841
787842
// NB Eq method appears below.
788843
#[auto_encode]
@@ -823,11 +878,18 @@ impl ToStr for Onceness {
823878
}
824879
}
825880
881+
#[cfg(stage0)]
826882
impl to_bytes::IterBytes for Onceness {
827883
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
828884
(*self as uint).iter_bytes(lsb0, f);
829885
}
830886
}
887+
#[cfg(not(stage0))]
888+
impl to_bytes::IterBytes for Onceness {
889+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
890+
(*self as uint).iter_bytes(lsb0, f)
891+
}
892+
}
831893
832894
#[auto_encode]
833895
#[auto_decode]
@@ -874,11 +936,18 @@ pub enum ty_ {
874936
ty_infer,
875937
}
876938
939+
#[cfg(stage0)]
877940
impl to_bytes::IterBytes for Ty {
878941
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
879942
to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f);
880943
}
881944
}
945+
#[cfg(not(stage0))]
946+
impl to_bytes::IterBytes for Ty {
947+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
948+
to_bytes::iter_bytes_2(&self.span.lo, &self.span.hi, lsb0, f)
949+
}
950+
}
882951
883952
#[auto_encode]
884953
#[auto_decode]
@@ -941,11 +1010,18 @@ impl ToStr for purity {
9411010
}
9421011
}
9431012
1013+
#[cfg(stage0)]
9441014
impl to_bytes::IterBytes for purity {
9451015
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
9461016
(*self as u8).iter_bytes(lsb0, f)
9471017
}
9481018
}
1019+
#[cfg(not(stage0))]
1020+
impl to_bytes::IterBytes for purity {
1021+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
1022+
(*self as u8).iter_bytes(lsb0, f)
1023+
}
1024+
}
9491025
9501026
#[auto_encode]
9511027
#[auto_decode]
@@ -956,11 +1032,18 @@ pub enum ret_style {
9561032
return_val, // everything else
9571033
}
9581034
1035+
#[cfg(stage0)]
9591036
impl to_bytes::IterBytes for ret_style {
9601037
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
9611038
(*self as u8).iter_bytes(lsb0, f)
9621039
}
9631040
}
1041+
#[cfg(not(stage0))]
1042+
impl to_bytes::IterBytes for ret_style {
1043+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
1044+
(*self as u8).iter_bytes(lsb0, f)
1045+
}
1046+
}
9641047
9651048
#[auto_encode]
9661049
#[auto_decode]

src/libsyntax/ast_util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,21 @@ pub fn is_call_expr(e: @expr) -> bool {
191191
}
192192
193193
// This makes def_id hashable
194+
#[cfg(stage0)]
194195
impl to_bytes::IterBytes for def_id {
195196
#[inline(always)]
196197
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
197198
to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f);
198199
}
199200
}
201+
// This makes def_id hashable
202+
#[cfg(not(stage0))]
203+
impl to_bytes::IterBytes for def_id {
204+
#[inline(always)]
205+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
206+
to_bytes::iter_bytes_2(&self.crate, &self.node, lsb0, f)
207+
}
208+
}
200209
201210
pub fn block_from_expr(e: @expr) -> blk {
202211
let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);

src/libsyntax/codemap.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ impl Sub<BytePos, BytePos> for BytePos {
6565
}
6666
}
6767

68+
#[cfg(stage0)]
6869
impl to_bytes::IterBytes for BytePos {
6970
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
7071
(**self).iter_bytes(lsb0, f)
7172
}
7273
}
74+
#[cfg(not(stage0))]
75+
impl to_bytes::IterBytes for BytePos {
76+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
77+
(**self).iter_bytes(lsb0, f)
78+
}
79+
}
7380

7481
impl Pos for CharPos {
7582
fn from_uint(n: uint) -> CharPos { CharPos(n) }
@@ -83,11 +90,18 @@ impl cmp::Ord for CharPos {
8390
fn gt(&self, other: &CharPos) -> bool { **self > **other }
8491
}
8592

93+
#[cfg(stage0)]
8694
impl to_bytes::IterBytes for CharPos {
8795
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
8896
(**self).iter_bytes(lsb0, f)
8997
}
9098
}
99+
#[cfg(not(stage0))]
100+
impl to_bytes::IterBytes for CharPos {
101+
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
102+
(**self).iter_bytes(lsb0, f)
103+
}
104+
}
91105

92106
impl Add<CharPos,CharPos> for CharPos {
93107
fn add(&self, rhs: &CharPos) -> CharPos {

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,8 @@ pub fn expand_item(extsbox: @mut SyntaxEnv,
195195
}
196196

197197
// does this attribute list contain "macro_escape" ?
198-
pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool{
199-
let mut accum = false;
200-
do attrs.each |attr| {
201-
let mname = attr::get_attr_name(attr);
202-
if (mname == @~"macro_escape") {
203-
accum = true;
204-
false
205-
} else {
206-
true
207-
}
208-
}
209-
accum
198+
pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool {
199+
attrs.any(|attr| "macro_escape" == *attr::get_attr_name(attr))
210200
}
211201

212202
// this macro disables (one layer of) macro

0 commit comments

Comments
 (0)