syntax: Use the new for protocol

This commit is contained in:
Alex Crichton 2013-05-02 18:33:33 -04:00
parent 3ce9dba677
commit 5eb6d19803
9 changed files with 182 additions and 12 deletions

View File

@ -81,6 +81,7 @@ pub struct AbiSet {
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 @@ fn add(&mut self, abi: Abi) {
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 @@ fn each(&self, op: &fn(abi: Abi) -> bool) {
}
}
}
#[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 @@ fn check_valid(&self) -> Option<(Abi, Abi)> {
}
}
#[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 {

View File

@ -97,11 +97,18 @@ fn decode(d: &mut D) -> 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 @@ fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
}
}
}
#[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 @@ fn to_str(&self) -> ~str {
}
}
#[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 @@ fn to_str(&self) -> ~str {
}
}
#[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 @@ fn to_str(&self) -> ~str {
}
}
#[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 @@ fn to_str(&self) -> ~str {
}
}
#[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 @@ fn to_str(&self) -> ~str {
}
}
#[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]

View File

@ -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);

View File

@ -65,11 +65,18 @@ fn sub(&self, rhs: &BytePos) -> 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 @@ fn ge(&self, other: &CharPos) -> bool { **self >= **other }
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 {

View File

@ -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

View File

@ -100,6 +100,7 @@ fn to_ty(&self, cx: @ext_ctxt) -> @ast::Ty {
/// 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 @@ fn reachable(&self, f: &fn(state) -> bool) {
}
}
}
/// 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_;

View File

@ -132,12 +132,20 @@ fn ne(&self, other: &OptVec<A>) -> bool {
}
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 @@ fn size_hint(&self) -> Option<uint> {
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)
}

View File

@ -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.

View File

@ -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