mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Remove all uses of pub impl
. rs=style
This commit is contained in:
parent
1e52eede31
commit
5fb254695b
@ -56,10 +56,10 @@ pub struct Condvar<'self> {
|
||||
cond: &'self sync::Condvar<'self>
|
||||
}
|
||||
|
||||
pub impl<'self> Condvar<'self> {
|
||||
impl<'self> Condvar<'self> {
|
||||
/// Atomically exit the associated ARC and block until a signal is sent.
|
||||
#[inline(always)]
|
||||
fn wait(&self) { self.wait_on(0) }
|
||||
pub fn wait(&self) { self.wait_on(0) }
|
||||
|
||||
/**
|
||||
* Atomically exit the associated ARC and block on a specified condvar
|
||||
@ -68,7 +68,7 @@ pub impl<'self> Condvar<'self> {
|
||||
* wait() is equivalent to wait_on(0).
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn wait_on(&self, condvar_id: uint) {
|
||||
pub fn wait_on(&self, condvar_id: uint) {
|
||||
assert!(!*self.failed);
|
||||
self.cond.wait_on(condvar_id);
|
||||
// This is why we need to wrap sync::condvar.
|
||||
@ -77,28 +77,28 @@ pub impl<'self> Condvar<'self> {
|
||||
|
||||
/// Wake up a blocked task. Returns false if there was no blocked task.
|
||||
#[inline(always)]
|
||||
fn signal(&self) -> bool { self.signal_on(0) }
|
||||
pub fn signal(&self) -> bool { self.signal_on(0) }
|
||||
|
||||
/**
|
||||
* Wake up a blocked task on a specified condvar (as
|
||||
* sync::cond.signal_on). Returns false if there was no blocked task.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn signal_on(&self, condvar_id: uint) -> bool {
|
||||
pub fn signal_on(&self, condvar_id: uint) -> bool {
|
||||
assert!(!*self.failed);
|
||||
self.cond.signal_on(condvar_id)
|
||||
}
|
||||
|
||||
/// Wake up all blocked tasks. Returns the number of tasks woken.
|
||||
#[inline(always)]
|
||||
fn broadcast(&self) -> uint { self.broadcast_on(0) }
|
||||
pub fn broadcast(&self) -> uint { self.broadcast_on(0) }
|
||||
|
||||
/**
|
||||
* Wake up all blocked tasks on a specified condvar (as
|
||||
* sync::cond.broadcast_on). Returns Returns the number of tasks woken.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn broadcast_on(&self, condvar_id: uint) -> uint {
|
||||
pub fn broadcast_on(&self, condvar_id: uint) -> uint {
|
||||
assert!(!*self.failed);
|
||||
self.cond.broadcast_on(condvar_id)
|
||||
}
|
||||
@ -120,8 +120,8 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
|
||||
* Access the underlying data in an atomically reference counted
|
||||
* wrapper.
|
||||
*/
|
||||
pub impl<T:Const+Owned> ARC<T> {
|
||||
fn get<'a>(&'a self) -> &'a T {
|
||||
impl<T:Const+Owned> ARC<T> {
|
||||
pub fn get<'a>(&'a self) -> &'a T {
|
||||
unsafe { &*self.x.get_immut() }
|
||||
}
|
||||
}
|
||||
@ -173,7 +173,7 @@ impl<T:Owned> Clone for MutexARC<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Owned> MutexARC<T> {
|
||||
impl<T:Owned> MutexARC<T> {
|
||||
|
||||
/**
|
||||
* Access the underlying mutable data with mutual exclusion from other
|
||||
@ -199,7 +199,7 @@ pub impl<T:Owned> MutexARC<T> {
|
||||
* blocked on the mutex) will also fail immediately.
|
||||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
pub unsafe fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
unsafe {
|
||||
let state = self.x.get();
|
||||
// Borrowck would complain about this if the function were
|
||||
@ -214,10 +214,10 @@ pub impl<T:Owned> MutexARC<T> {
|
||||
|
||||
/// As access(), but with a condvar, as sync::mutex.lock_cond().
|
||||
#[inline(always)]
|
||||
unsafe fn access_cond<'x, 'c, U>(
|
||||
&self,
|
||||
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U
|
||||
{
|
||||
pub unsafe fn access_cond<'x, 'c, U>(&self,
|
||||
blk: &fn(x: &'x mut T,
|
||||
c: &'c Condvar) -> U)
|
||||
-> U {
|
||||
let state = self.x.get();
|
||||
do (&(*state).lock).lock_cond |cond| {
|
||||
check_poison(true, (*state).failed);
|
||||
@ -302,16 +302,18 @@ pub fn rw_arc_with_condvars<T:Const + Owned>(
|
||||
RWARC { x: UnsafeAtomicRcBox::new(data), cant_nest: () }
|
||||
}
|
||||
|
||||
pub impl<T:Const + Owned> RWARC<T> {
|
||||
impl<T:Const + Owned> RWARC<T> {
|
||||
/// Duplicate a rwlock-protected ARC, as arc::clone.
|
||||
fn clone(&self) -> RWARC<T> {
|
||||
RWARC { x: self.x.clone(),
|
||||
cant_nest: () }
|
||||
pub fn clone(&self) -> RWARC<T> {
|
||||
RWARC {
|
||||
x: self.x.clone(),
|
||||
cant_nest: (),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub impl<T:Const + Owned> RWARC<T> {
|
||||
impl<T:Const + Owned> RWARC<T> {
|
||||
/**
|
||||
* Access the underlying data mutably. Locks the rwlock in write mode;
|
||||
* other readers and writers will block.
|
||||
@ -323,7 +325,7 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
* poison the ARC, so subsequent readers and writers will both also fail.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
pub fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
unsafe {
|
||||
let state = self.x.get();
|
||||
do (*borrow_rwlock(state)).write {
|
||||
@ -333,11 +335,12 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// As write(), but with a condvar, as sync::rwlock.write_cond().
|
||||
#[inline(always)]
|
||||
fn write_cond<'x, 'c, U>(&self,
|
||||
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
|
||||
-> U {
|
||||
pub fn write_cond<'x, 'c, U>(&self,
|
||||
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
|
||||
-> U {
|
||||
unsafe {
|
||||
let state = self.x.get();
|
||||
do (*borrow_rwlock(state)).write_cond |cond| {
|
||||
@ -350,6 +353,7 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the underlying data immutably. May run concurrently with other
|
||||
* reading tasks.
|
||||
@ -359,7 +363,7 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
* Failing will unlock the ARC while unwinding. However, unlike all other
|
||||
* access modes, this will not poison the ARC.
|
||||
*/
|
||||
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
|
||||
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
|
||||
unsafe {
|
||||
let state = self.x.get();
|
||||
do (*state).lock.read {
|
||||
@ -389,7 +393,7 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
* }
|
||||
* ~~~
|
||||
*/
|
||||
fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U {
|
||||
pub fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U {
|
||||
unsafe {
|
||||
let state = self.x.get();
|
||||
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
|
||||
@ -404,7 +408,8 @@ pub impl<T:Const + Owned> RWARC<T> {
|
||||
}
|
||||
|
||||
/// To be called inside of the write_downgrade block.
|
||||
fn downgrade<'a>(&self, token: RWWriteMode<'a, T>) -> RWReadMode<'a, T> {
|
||||
pub fn downgrade<'a>(&self, token: RWWriteMode<'a, T>)
|
||||
-> RWReadMode<'a, T> {
|
||||
unsafe {
|
||||
// The rwlock should assert that the token belongs to us for us.
|
||||
let state = self.x.get();
|
||||
@ -451,9 +456,9 @@ pub struct RWReadMode<'self, T> {
|
||||
token: sync::RWlockReadMode<'self>,
|
||||
}
|
||||
|
||||
pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
|
||||
impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
|
||||
/// Access the pre-downgrade RWARC in write mode.
|
||||
fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
pub fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
|
||||
match *self {
|
||||
RWWriteMode {
|
||||
data: &ref mut data,
|
||||
@ -466,10 +471,11 @@ pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the pre-downgrade RWARC in write mode with a condvar.
|
||||
fn write_cond<'x, 'c, U>(&mut self,
|
||||
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
|
||||
-> U {
|
||||
pub fn write_cond<'x, 'c, U>(&mut self,
|
||||
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
|
||||
-> U {
|
||||
match *self {
|
||||
RWWriteMode {
|
||||
data: &ref mut data,
|
||||
@ -491,9 +497,9 @@ pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
|
||||
impl<'self, T:Const + Owned> RWReadMode<'self, T> {
|
||||
/// Access the post-downgrade rwlock in read mode.
|
||||
fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
|
||||
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
|
||||
match *self {
|
||||
RWReadMode {
|
||||
data: data,
|
||||
|
@ -166,9 +166,9 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
|
||||
(transmute(p & !1), p & 1 == 1)
|
||||
}
|
||||
|
||||
pub impl Arena {
|
||||
impl Arena {
|
||||
// Functions for the POD part of the arena
|
||||
priv fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
|
||||
fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
|
||||
// Allocate a new chunk.
|
||||
let chunk_size = at_vec::capacity(self.pod_head.data);
|
||||
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
|
||||
@ -180,7 +180,7 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
priv fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
|
||||
fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
|
||||
unsafe {
|
||||
// XXX: Borrow check
|
||||
let head = transmute_mut_region(&mut self.pod_head);
|
||||
@ -200,7 +200,7 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
priv fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
||||
@ -211,8 +211,8 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
// Functions for the non-POD part of the arena
|
||||
priv fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
|
||||
-> (*u8, *u8) {
|
||||
fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
|
||||
-> (*u8, *u8) {
|
||||
// Allocate a new chunk.
|
||||
let chunk_size = at_vec::capacity(self.head.data);
|
||||
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
|
||||
@ -224,8 +224,8 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
priv fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
|
||||
-> (*u8, *u8) {
|
||||
fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
|
||||
-> (*u8, *u8) {
|
||||
unsafe {
|
||||
let head = transmute_mut_region(&mut self.head);
|
||||
|
||||
@ -247,7 +247,7 @@ pub impl Arena {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
priv fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
let (ty_ptr, ptr) =
|
||||
@ -269,7 +269,7 @@ pub impl Arena {
|
||||
|
||||
// The external interface
|
||||
#[inline(always)]
|
||||
fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
|
||||
unsafe {
|
||||
// XXX: Borrow check
|
||||
let this = transmute_mut_region(self);
|
||||
|
@ -8,6 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::cmp;
|
||||
@ -26,14 +28,17 @@ fn small_mask(nbits: uint) -> uint {
|
||||
(1 << nbits) - 1
|
||||
}
|
||||
|
||||
pub impl SmallBitv {
|
||||
fn new(bits: uint) -> SmallBitv {
|
||||
impl SmallBitv {
|
||||
pub fn new(bits: uint) -> SmallBitv {
|
||||
SmallBitv {bits: bits}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn bits_op(&mut self, right_bits: uint, nbits: uint,
|
||||
f: &fn(uint, uint) -> uint) -> bool {
|
||||
pub fn bits_op(&mut self,
|
||||
right_bits: uint,
|
||||
nbits: uint,
|
||||
f: &fn(uint, uint) -> uint)
|
||||
-> bool {
|
||||
let mask = small_mask(nbits);
|
||||
let old_b: uint = self.bits;
|
||||
let new_b = f(old_b, right_bits);
|
||||
@ -42,32 +47,32 @@ pub impl SmallBitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
pub fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
self.bits_op(s.bits, nbits, |u1, u2| u1 | u2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
pub fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
self.bits_op(s.bits, nbits, |u1, u2| u1 & u2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
pub fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
self.bits_op(s.bits, nbits, |_u1, u2| u2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
pub fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool {
|
||||
self.bits_op(s.bits, nbits, |u1, u2| u1 & !u2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get(&self, i: uint) -> bool {
|
||||
pub fn get(&self, i: uint) -> bool {
|
||||
(self.bits & (1 << i)) != 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set(&mut self, i: uint, x: bool) {
|
||||
pub fn set(&mut self, i: uint, x: bool) {
|
||||
if x {
|
||||
self.bits |= 1<<i;
|
||||
}
|
||||
@ -77,30 +82,29 @@ pub impl SmallBitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn equals(&self, b: &SmallBitv, nbits: uint) -> bool {
|
||||
pub fn equals(&self, b: &SmallBitv, nbits: uint) -> bool {
|
||||
let mask = small_mask(nbits);
|
||||
mask & self.bits == mask & b.bits
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn clear(&mut self) { self.bits = 0; }
|
||||
pub fn clear(&mut self) { self.bits = 0; }
|
||||
|
||||
#[inline(always)]
|
||||
fn set_all(&mut self) { self.bits = !0; }
|
||||
pub fn set_all(&mut self) { self.bits = !0; }
|
||||
|
||||
#[inline(always)]
|
||||
fn is_true(&self, nbits: uint) -> bool {
|
||||
pub fn is_true(&self, nbits: uint) -> bool {
|
||||
small_mask(nbits) & !self.bits == 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn is_false(&self, nbits: uint) -> bool {
|
||||
pub fn is_false(&self, nbits: uint) -> bool {
|
||||
small_mask(nbits) & self.bits == 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn invert(&mut self) { self.bits = !self.bits; }
|
||||
|
||||
pub fn invert(&mut self) { self.bits = !self.bits; }
|
||||
}
|
||||
|
||||
struct BigBitv {
|
||||
@ -123,14 +127,17 @@ fn big_mask(nbits: uint, elem: uint) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl BigBitv {
|
||||
fn new(storage: ~[uint]) -> BigBitv {
|
||||
impl BigBitv {
|
||||
pub fn new(storage: ~[uint]) -> BigBitv {
|
||||
BigBitv {storage: storage}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn process(&mut self, b: &BigBitv, nbits: uint,
|
||||
op: &fn(uint, uint) -> uint) -> bool {
|
||||
pub fn process(&mut self,
|
||||
b: &BigBitv,
|
||||
nbits: uint,
|
||||
op: &fn(uint, uint) -> uint)
|
||||
-> bool {
|
||||
let len = b.storage.len();
|
||||
assert_eq!(self.storage.len(), len);
|
||||
let mut changed = false;
|
||||
@ -148,35 +155,35 @@ pub impl BigBitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
|
||||
pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
|
||||
uint::range(0, self.storage.len(), |i| op(&mut self.storage[i]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn invert(&mut self) { for self.each_storage |w| { *w = !*w } }
|
||||
pub fn invert(&mut self) { for self.each_storage |w| { *w = !*w } }
|
||||
|
||||
#[inline(always)]
|
||||
fn union(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
pub fn union(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
self.process(b, nbits, |w1, w2| w1 | w2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
pub fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
self.process(b, nbits, |w1, w2| w1 & w2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn become(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
pub fn become(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
self.process(b, nbits, |_, w| w)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
pub fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool {
|
||||
self.process(b, nbits, |w1, w2| w1 & !w2)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get(&self, i: uint) -> bool {
|
||||
pub fn get(&self, i: uint) -> bool {
|
||||
let w = i / uint::bits;
|
||||
let b = i % uint::bits;
|
||||
let x = 1 & self.storage[w] >> b;
|
||||
@ -184,7 +191,7 @@ pub impl BigBitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set(&mut self, i: uint, x: bool) {
|
||||
pub fn set(&mut self, i: uint, x: bool) {
|
||||
let w = i / uint::bits;
|
||||
let b = i % uint::bits;
|
||||
let flag = 1 << b;
|
||||
@ -193,7 +200,7 @@ pub impl BigBitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
|
||||
pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
|
||||
let len = b.storage.len();
|
||||
for uint::iterate(0, len) |i| {
|
||||
let mask = big_mask(nbits, i);
|
||||
@ -203,7 +210,6 @@ pub impl BigBitv {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum BitvVariant { Big(~BigBitv), Small(~SmallBitv) }
|
||||
@ -222,8 +228,7 @@ fn die() -> ! {
|
||||
fail!("Tried to do operation on bit vectors with different sizes");
|
||||
}
|
||||
|
||||
priv impl Bitv {
|
||||
|
||||
impl Bitv {
|
||||
#[inline(always)]
|
||||
fn do_op(&mut self, op: Op, other: &Bitv) -> bool {
|
||||
if self.nbits != other.nbits {
|
||||
@ -253,8 +258,8 @@ priv impl Bitv {
|
||||
|
||||
}
|
||||
|
||||
pub impl Bitv {
|
||||
fn new(nbits: uint, init: bool) -> Bitv {
|
||||
impl Bitv {
|
||||
pub fn new(nbits: uint, init: bool) -> Bitv {
|
||||
let rep = if nbits <= uint::bits {
|
||||
Small(~SmallBitv::new(if init {!0} else {0}))
|
||||
}
|
||||
@ -275,7 +280,7 @@ pub impl Bitv {
|
||||
* the same length. Returns 'true' if `self` changed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn union(&mut self, v1: &Bitv) -> bool { self.do_op(Union, v1) }
|
||||
pub fn union(&mut self, v1: &Bitv) -> bool { self.do_op(Union, v1) }
|
||||
|
||||
/**
|
||||
* Calculates the intersection of two bitvectors
|
||||
@ -284,7 +289,9 @@ pub impl Bitv {
|
||||
* must be the same length. Returns 'true' if `self` changed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn intersect(&mut self, v1: &Bitv) -> bool { self.do_op(Intersect, v1) }
|
||||
pub fn intersect(&mut self, v1: &Bitv) -> bool {
|
||||
self.do_op(Intersect, v1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the value of `v1` to `self`
|
||||
@ -293,16 +300,16 @@ pub impl Bitv {
|
||||
* changed
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn assign(&mut self, v: &Bitv) -> bool { self.do_op(Assign, v) }
|
||||
pub fn assign(&mut self, v: &Bitv) -> bool { self.do_op(Assign, v) }
|
||||
|
||||
/// Retrieve the value at index `i`
|
||||
#[inline(always)]
|
||||
fn get(&self, i: uint) -> bool {
|
||||
assert!((i < self.nbits));
|
||||
match self.rep {
|
||||
Big(ref b) => b.get(i),
|
||||
Small(ref s) => s.get(i)
|
||||
}
|
||||
pub fn get(&self, i: uint) -> bool {
|
||||
assert!((i < self.nbits));
|
||||
match self.rep {
|
||||
Big(ref b) => b.get(i),
|
||||
Small(ref s) => s.get(i)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,7 +318,7 @@ pub impl Bitv {
|
||||
* `i` must be less than the length of the bitvector.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn set(&mut self, i: uint, x: bool) {
|
||||
pub fn set(&mut self, i: uint, x: bool) {
|
||||
assert!((i < self.nbits));
|
||||
match self.rep {
|
||||
Big(ref mut b) => b.set(i, x),
|
||||
@ -326,7 +333,7 @@ pub impl Bitv {
|
||||
* bitvectors contain identical elements.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn equal(&self, v1: &Bitv) -> bool {
|
||||
pub fn equal(&self, v1: &Bitv) -> bool {
|
||||
if self.nbits != v1.nbits { return false; }
|
||||
match self.rep {
|
||||
Small(ref b) => match v1.rep {
|
||||
@ -342,7 +349,7 @@ pub impl Bitv {
|
||||
|
||||
/// Set all bits to 0
|
||||
#[inline(always)]
|
||||
fn clear(&mut self) {
|
||||
pub fn clear(&mut self) {
|
||||
match self.rep {
|
||||
Small(ref mut b) => b.clear(),
|
||||
Big(ref mut s) => for s.each_storage() |w| { *w = 0u }
|
||||
@ -351,7 +358,7 @@ pub impl Bitv {
|
||||
|
||||
/// Set all bits to 1
|
||||
#[inline(always)]
|
||||
fn set_all(&mut self) {
|
||||
pub fn set_all(&mut self) {
|
||||
match self.rep {
|
||||
Small(ref mut b) => b.set_all(),
|
||||
Big(ref mut s) => for s.each_storage() |w| { *w = !0u } }
|
||||
@ -359,7 +366,7 @@ pub impl Bitv {
|
||||
|
||||
/// Invert all bits
|
||||
#[inline(always)]
|
||||
fn invert(&mut self) {
|
||||
pub fn invert(&mut self) {
|
||||
match self.rep {
|
||||
Small(ref mut b) => b.invert(),
|
||||
Big(ref mut s) => for s.each_storage() |w| { *w = !*w } }
|
||||
@ -375,11 +382,13 @@ pub impl Bitv {
|
||||
* Returns `true` if `v0` was changed.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn difference(&mut self, v: &Bitv) -> bool { self.do_op(Difference, v) }
|
||||
pub fn difference(&mut self, v: &Bitv) -> bool {
|
||||
self.do_op(Difference, v)
|
||||
}
|
||||
|
||||
/// Returns true if all bits are 1
|
||||
#[inline(always)]
|
||||
fn is_true(&self) -> bool {
|
||||
pub fn is_true(&self) -> bool {
|
||||
match self.rep {
|
||||
Small(ref b) => b.is_true(self.nbits),
|
||||
_ => {
|
||||
@ -390,7 +399,7 @@ pub impl Bitv {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn each(&self, f: &fn(bool) -> bool) -> bool {
|
||||
pub fn each(&self, f: &fn(bool) -> bool) -> bool {
|
||||
let mut i = 0;
|
||||
while i < self.nbits {
|
||||
if !f(self.get(i)) { return false; }
|
||||
@ -400,7 +409,7 @@ pub impl Bitv {
|
||||
}
|
||||
|
||||
/// Returns true if all bits are 0
|
||||
fn is_false(&self) -> bool {
|
||||
pub fn is_false(&self) -> bool {
|
||||
match self.rep {
|
||||
Small(ref b) => b.is_false(self.nbits),
|
||||
Big(_) => {
|
||||
@ -410,7 +419,7 @@ pub impl Bitv {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_to_vec(&self, i: uint) -> uint {
|
||||
pub fn init_to_vec(&self, i: uint) -> uint {
|
||||
return if self.get(i) { 1 } else { 0 };
|
||||
}
|
||||
|
||||
@ -419,7 +428,7 @@ pub impl Bitv {
|
||||
*
|
||||
* Each uint in the resulting vector has either value 0u or 1u.
|
||||
*/
|
||||
fn to_vec(&self) -> ~[uint] {
|
||||
pub fn to_vec(&self) -> ~[uint] {
|
||||
vec::from_fn(self.nbits, |x| self.init_to_vec(x))
|
||||
}
|
||||
|
||||
@ -429,8 +438,7 @@ pub impl Bitv {
|
||||
* size of the bitv is not a multiple of 8 then trailing bits
|
||||
* will be filled-in with false/0
|
||||
*/
|
||||
fn to_bytes(&self) -> ~[u8] {
|
||||
|
||||
pub fn to_bytes(&self) -> ~[u8] {
|
||||
fn bit (bitv: &Bitv, byte: uint, bit: uint) -> u8 {
|
||||
let offset = byte * 8 + bit;
|
||||
if offset >= bitv.nbits {
|
||||
@ -457,7 +465,7 @@ pub impl Bitv {
|
||||
/**
|
||||
* Transform self into a [bool] by turning each bit into a bool
|
||||
*/
|
||||
fn to_bools(&self) -> ~[bool] {
|
||||
pub fn to_bools(&self) -> ~[bool] {
|
||||
vec::from_fn(self.nbits, |i| self[i])
|
||||
}
|
||||
|
||||
@ -467,7 +475,7 @@ pub impl Bitv {
|
||||
* The resulting string has the same length as `self`, and each
|
||||
* character is either '0' or '1'.
|
||||
*/
|
||||
fn to_str(&self) -> ~str {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
let mut rs = ~"";
|
||||
for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } };
|
||||
rs
|
||||
@ -480,7 +488,7 @@ pub impl Bitv {
|
||||
* The uint vector is expected to only contain the values 0u and 1u. Both
|
||||
* the bitvector and vector must have the same length
|
||||
*/
|
||||
fn eq_vec(&self, v: ~[uint]) -> bool {
|
||||
pub fn eq_vec(&self, v: ~[uint]) -> bool {
|
||||
assert_eq!(self.nbits, v.len());
|
||||
let mut i = 0;
|
||||
while i < self.nbits {
|
||||
@ -492,7 +500,7 @@ pub impl Bitv {
|
||||
true
|
||||
}
|
||||
|
||||
fn ones(&self, f: &fn(uint) -> bool) -> bool {
|
||||
pub fn ones(&self, f: &fn(uint) -> bool) -> bool {
|
||||
uint::range(0, self.nbits, |i| !self.get(i) || f(i))
|
||||
}
|
||||
|
||||
@ -514,7 +522,6 @@ impl Clone for Bitv {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -585,14 +592,14 @@ pub struct BitvSet {
|
||||
priv bitv: BigBitv
|
||||
}
|
||||
|
||||
pub impl BitvSet {
|
||||
impl BitvSet {
|
||||
/// Creates a new bit vector set with initially no contents
|
||||
fn new() -> BitvSet {
|
||||
pub fn new() -> BitvSet {
|
||||
BitvSet{ size: 0, bitv: BigBitv::new(~[0]) }
|
||||
}
|
||||
|
||||
/// Creates a new bit vector set from the given bit vector
|
||||
fn from_bitv(bitv: Bitv) -> BitvSet {
|
||||
pub fn from_bitv(bitv: Bitv) -> BitvSet {
|
||||
let mut size = 0;
|
||||
for bitv.ones |_| {
|
||||
size += 1;
|
||||
@ -607,17 +614,17 @@ pub impl BitvSet {
|
||||
|
||||
/// Returns the capacity in bits for this bit vector. Inserting any
|
||||
/// element less than this amount will not trigger a resizing.
|
||||
fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits }
|
||||
pub fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits }
|
||||
|
||||
/// Consumes this set to return the underlying bit vector
|
||||
fn unwrap(self) -> Bitv {
|
||||
pub fn unwrap(self) -> Bitv {
|
||||
let cap = self.capacity();
|
||||
let BitvSet{bitv, _} = self;
|
||||
return Bitv{ nbits:cap, rep: Big(~bitv) };
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
priv fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
|
||||
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
|
||||
fn nbits(mut w: uint) -> uint {
|
||||
let mut bits = 0;
|
||||
for uint::bits.times {
|
||||
@ -641,22 +648,22 @@ pub impl BitvSet {
|
||||
}
|
||||
|
||||
/// Union in-place with the specified other bit vector
|
||||
fn union_with(&mut self, other: &BitvSet) {
|
||||
pub fn union_with(&mut self, other: &BitvSet) {
|
||||
self.other_op(other, |w1, w2| w1 | w2);
|
||||
}
|
||||
|
||||
/// Intersect in-place with the specified other bit vector
|
||||
fn intersect_with(&mut self, other: &BitvSet) {
|
||||
pub fn intersect_with(&mut self, other: &BitvSet) {
|
||||
self.other_op(other, |w1, w2| w1 & w2);
|
||||
}
|
||||
|
||||
/// Difference in-place with the specified other bit vector
|
||||
fn difference_with(&mut self, other: &BitvSet) {
|
||||
pub fn difference_with(&mut self, other: &BitvSet) {
|
||||
self.other_op(other, |w1, w2| w1 & !w2);
|
||||
}
|
||||
|
||||
/// Symmetric difference in-place with the specified other bit vector
|
||||
fn symmetric_difference_with(&mut self, other: &BitvSet) {
|
||||
pub fn symmetric_difference_with(&mut self, other: &BitvSet) {
|
||||
self.other_op(other, |w1, w2| w1 ^ w2);
|
||||
}
|
||||
}
|
||||
@ -810,7 +817,7 @@ impl Set<uint> for BitvSet {
|
||||
}
|
||||
}
|
||||
|
||||
priv impl BitvSet {
|
||||
impl BitvSet {
|
||||
/// Visits each of the words that the two bit vectors (self and other)
|
||||
/// both have in common. The three yielded arguments are (bit location,
|
||||
/// w1, w2) where the bit location is the number of bits offset so far,
|
||||
|
@ -14,6 +14,8 @@ Higher level communication abstractions.
|
||||
|
||||
*/
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::comm::{GenericChan, GenericSmartChan, GenericPort};
|
||||
@ -28,20 +30,20 @@ pub struct DuplexStream<T, U> {
|
||||
}
|
||||
|
||||
// Allow these methods to be used without import:
|
||||
pub impl<T:Owned,U:Owned> DuplexStream<T, U> {
|
||||
fn send(&self, x: T) {
|
||||
impl<T:Owned,U:Owned> DuplexStream<T, U> {
|
||||
pub fn send(&self, x: T) {
|
||||
self.chan.send(x)
|
||||
}
|
||||
fn try_send(&self, x: T) -> bool {
|
||||
pub fn try_send(&self, x: T) -> bool {
|
||||
self.chan.try_send(x)
|
||||
}
|
||||
fn recv(&self, ) -> U {
|
||||
pub fn recv(&self, ) -> U {
|
||||
self.port.recv()
|
||||
}
|
||||
fn try_recv(&self) -> Option<U> {
|
||||
pub fn try_recv(&self) -> Option<U> {
|
||||
self.port.try_recv()
|
||||
}
|
||||
fn peek(&self) -> bool {
|
||||
pub fn peek(&self) -> bool {
|
||||
self.port.peek()
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ impl<T> Mutable for Deque<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> Deque<T> {
|
||||
impl<T> Deque<T> {
|
||||
/// Create an empty Deque
|
||||
fn new() -> Deque<T> {
|
||||
pub fn new() -> Deque<T> {
|
||||
Deque{nelts: 0, lo: 0, hi: 0,
|
||||
elts: vec::from_fn(initial_capacity, |_| None)}
|
||||
}
|
||||
@ -54,35 +54,35 @@ pub impl<T> Deque<T> {
|
||||
/// Return a reference to the first element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn peek_front<'a>(&'a self) -> &'a T { get(self.elts, self.lo) }
|
||||
pub fn peek_front<'a>(&'a self) -> &'a T { get(self.elts, self.lo) }
|
||||
|
||||
/// Return a reference to the last element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn peek_back<'a>(&'a self) -> &'a T { get(self.elts, self.hi - 1u) }
|
||||
pub fn peek_back<'a>(&'a self) -> &'a T { get(self.elts, self.hi - 1u) }
|
||||
|
||||
/// Retrieve an element in the deque by index
|
||||
///
|
||||
/// Fails if there is no element with the given index
|
||||
fn get<'a>(&'a self, i: int) -> &'a T {
|
||||
pub fn get<'a>(&'a self, i: int) -> &'a T {
|
||||
let idx = (self.lo + (i as uint)) % self.elts.len();
|
||||
get(self.elts, idx)
|
||||
}
|
||||
|
||||
/// Iterate over the elements in the deque
|
||||
fn each(&self, f: &fn(&T) -> bool) -> bool {
|
||||
pub fn each(&self, f: &fn(&T) -> bool) -> bool {
|
||||
self.eachi(|_i, e| f(e))
|
||||
}
|
||||
|
||||
/// Iterate over the elements in the deque by index
|
||||
fn eachi(&self, f: &fn(uint, &T) -> bool) -> bool {
|
||||
pub fn eachi(&self, f: &fn(uint, &T) -> bool) -> bool {
|
||||
uint::range(0, self.nelts, |i| f(i, self.get(i as int)))
|
||||
}
|
||||
|
||||
/// Remove and return the first element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn pop_front(&mut self) -> T {
|
||||
pub fn pop_front(&mut self) -> T {
|
||||
let result = self.elts[self.lo].swap_unwrap();
|
||||
self.lo = (self.lo + 1u) % self.elts.len();
|
||||
self.nelts -= 1u;
|
||||
@ -92,7 +92,7 @@ pub impl<T> Deque<T> {
|
||||
/// Remove and return the last element in the deque
|
||||
///
|
||||
/// Fails if the deque is empty
|
||||
fn pop_back(&mut self) -> T {
|
||||
pub fn pop_back(&mut self) -> T {
|
||||
if self.hi == 0u {
|
||||
self.hi = self.elts.len() - 1u;
|
||||
} else { self.hi -= 1u; }
|
||||
@ -103,7 +103,7 @@ pub impl<T> Deque<T> {
|
||||
}
|
||||
|
||||
/// Prepend an element to the deque
|
||||
fn add_front(&mut self, t: T) {
|
||||
pub fn add_front(&mut self, t: T) {
|
||||
let oldlo = self.lo;
|
||||
if self.lo == 0u {
|
||||
self.lo = self.elts.len() - 1u;
|
||||
@ -118,7 +118,7 @@ pub impl<T> Deque<T> {
|
||||
}
|
||||
|
||||
/// Append an element to the deque
|
||||
fn add_back(&mut self, t: T) {
|
||||
pub fn add_back(&mut self, t: T) {
|
||||
if self.lo == self.hi && self.nelts != 0u {
|
||||
self.elts = grow(self.nelts, self.lo, self.elts);
|
||||
self.lo = 0u;
|
||||
@ -136,7 +136,7 @@ pub impl<T> Deque<T> {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * n - The number of elements to reserve space for
|
||||
fn reserve(&mut self, n: uint) {
|
||||
pub fn reserve(&mut self, n: uint) {
|
||||
vec::reserve(&mut self.elts, n);
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ pub impl<T> Deque<T> {
|
||||
/// # Arguments
|
||||
///
|
||||
/// * n - The number of elements to reserve space for
|
||||
fn reserve_at_least(&mut self, n: uint) {
|
||||
pub fn reserve_at_least(&mut self, n: uint) {
|
||||
vec::reserve_at_least(&mut self.elts, n);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ pub struct DList<T> {
|
||||
tl: DListLink<T>,
|
||||
}
|
||||
|
||||
priv impl<T> DListNode<T> {
|
||||
impl<T> DListNode<T> {
|
||||
fn assert_links(@mut self) {
|
||||
match self.next {
|
||||
Some(neighbour) => match neighbour.prev {
|
||||
@ -64,26 +64,26 @@ priv impl<T> DListNode<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> DListNode<T> {
|
||||
impl<T> DListNode<T> {
|
||||
/// Get the next node in the list, if there is one.
|
||||
fn next_link(@mut self) -> DListLink<T> {
|
||||
pub fn next_link(@mut self) -> DListLink<T> {
|
||||
self.assert_links();
|
||||
self.next
|
||||
}
|
||||
/// Get the next node in the list, failing if there isn't one.
|
||||
fn next_node(@mut self) -> @mut DListNode<T> {
|
||||
pub fn next_node(@mut self) -> @mut DListNode<T> {
|
||||
match self.next_link() {
|
||||
Some(nobe) => nobe,
|
||||
None => fail!("This dlist node has no next neighbour.")
|
||||
}
|
||||
}
|
||||
/// Get the previous node in the list, if there is one.
|
||||
fn prev_link(@mut self) -> DListLink<T> {
|
||||
pub fn prev_link(@mut self) -> DListLink<T> {
|
||||
self.assert_links();
|
||||
self.prev
|
||||
}
|
||||
/// Get the previous node in the list, failing if there isn't one.
|
||||
fn prev_node(@mut self) -> @mut DListNode<T> {
|
||||
pub fn prev_node(@mut self) -> @mut DListNode<T> {
|
||||
match self.prev_link() {
|
||||
Some(nobe) => nobe,
|
||||
None => fail!("This dlist node has no previous neighbour.")
|
||||
@ -126,7 +126,7 @@ pub fn concat<T>(lists: @mut DList<@mut DList<T>>) -> @mut DList<T> {
|
||||
result
|
||||
}
|
||||
|
||||
priv impl<T> DList<T> {
|
||||
impl<T> DList<T> {
|
||||
fn new_link(data: T) -> DListLink<T> {
|
||||
Some(@mut DListNode {
|
||||
data: data,
|
||||
@ -211,34 +211,34 @@ priv impl<T> DList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> DList<T> {
|
||||
impl<T> DList<T> {
|
||||
/// Get the size of the list. O(1).
|
||||
fn len(@mut self) -> uint { self.size }
|
||||
pub fn len(@mut self) -> uint { self.size }
|
||||
/// Returns true if the list is empty. O(1).
|
||||
fn is_empty(@mut self) -> bool { self.len() == 0 }
|
||||
pub fn is_empty(@mut self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Add data to the head of the list. O(1).
|
||||
fn push_head(@mut self, data: T) {
|
||||
pub fn push_head(@mut self, data: T) {
|
||||
self.add_head(DList::new_link(data));
|
||||
}
|
||||
/**
|
||||
* Add data to the head of the list, and get the new containing
|
||||
* node. O(1).
|
||||
*/
|
||||
fn push_head_n(@mut self, data: T) -> @mut DListNode<T> {
|
||||
pub fn push_head_n(@mut self, data: T) -> @mut DListNode<T> {
|
||||
let nobe = DList::new_link(data);
|
||||
self.add_head(nobe);
|
||||
nobe.get()
|
||||
}
|
||||
/// Add data to the tail of the list. O(1).
|
||||
fn push(@mut self, data: T) {
|
||||
pub fn push(@mut self, data: T) {
|
||||
self.add_tail(DList::new_link(data));
|
||||
}
|
||||
/**
|
||||
* Add data to the tail of the list, and get the new containing
|
||||
* node. O(1).
|
||||
*/
|
||||
fn push_n(@mut self, data: T) -> @mut DListNode<T> {
|
||||
pub fn push_n(@mut self, data: T) -> @mut DListNode<T> {
|
||||
let nobe = DList::new_link(data);
|
||||
self.add_tail(nobe);
|
||||
nobe.get()
|
||||
@ -247,16 +247,16 @@ pub impl<T> DList<T> {
|
||||
* Insert data into the middle of the list, left of the given node.
|
||||
* O(1).
|
||||
*/
|
||||
fn insert_before(@mut self, data: T, neighbour: @mut DListNode<T>) {
|
||||
pub fn insert_before(@mut self, data: T, neighbour: @mut DListNode<T>) {
|
||||
self.insert_left(DList::new_link(data), neighbour);
|
||||
}
|
||||
/**
|
||||
* Insert an existing node in the middle of the list, left of the
|
||||
* given node. O(1).
|
||||
*/
|
||||
fn insert_n_before(@mut self,
|
||||
nobe: @mut DListNode<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
pub fn insert_n_before(@mut self,
|
||||
nobe: @mut DListNode<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
self.make_mine(nobe);
|
||||
self.insert_left(Some(nobe), neighbour);
|
||||
}
|
||||
@ -264,11 +264,10 @@ pub impl<T> DList<T> {
|
||||
* Insert data in the middle of the list, left of the given node,
|
||||
* and get its containing node. O(1).
|
||||
*/
|
||||
fn insert_before_n(
|
||||
@mut self,
|
||||
data: T,
|
||||
neighbour: @mut DListNode<T>
|
||||
) -> @mut DListNode<T> {
|
||||
pub fn insert_before_n(@mut self,
|
||||
data: T,
|
||||
neighbour: @mut DListNode<T>)
|
||||
-> @mut DListNode<T> {
|
||||
let nobe = DList::new_link(data);
|
||||
self.insert_left(nobe, neighbour);
|
||||
nobe.get()
|
||||
@ -277,16 +276,16 @@ pub impl<T> DList<T> {
|
||||
* Insert data into the middle of the list, right of the given node.
|
||||
* O(1).
|
||||
*/
|
||||
fn insert_after(@mut self, data: T, neighbour: @mut DListNode<T>) {
|
||||
pub fn insert_after(@mut self, data: T, neighbour: @mut DListNode<T>) {
|
||||
self.insert_right(neighbour, DList::new_link(data));
|
||||
}
|
||||
/**
|
||||
* Insert an existing node in the middle of the list, right of the
|
||||
* given node. O(1).
|
||||
*/
|
||||
fn insert_n_after(@mut self,
|
||||
nobe: @mut DListNode<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
pub fn insert_n_after(@mut self,
|
||||
nobe: @mut DListNode<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
self.make_mine(nobe);
|
||||
self.insert_right(neighbour, Some(nobe));
|
||||
}
|
||||
@ -294,42 +293,41 @@ pub impl<T> DList<T> {
|
||||
* Insert data in the middle of the list, right of the given node,
|
||||
* and get its containing node. O(1).
|
||||
*/
|
||||
fn insert_after_n(
|
||||
@mut self,
|
||||
data: T,
|
||||
neighbour: @mut DListNode<T>
|
||||
) -> @mut DListNode<T> {
|
||||
pub fn insert_after_n(@mut self,
|
||||
data: T,
|
||||
neighbour: @mut DListNode<T>)
|
||||
-> @mut DListNode<T> {
|
||||
let nobe = DList::new_link(data);
|
||||
self.insert_right(neighbour, nobe);
|
||||
nobe.get()
|
||||
}
|
||||
|
||||
/// Remove a node from the head of the list. O(1).
|
||||
fn pop_n(@mut self) -> DListLink<T> {
|
||||
pub fn pop_n(@mut self) -> DListLink<T> {
|
||||
let hd = self.peek_n();
|
||||
hd.map(|nobe| self.unlink(*nobe));
|
||||
hd
|
||||
}
|
||||
/// Remove a node from the tail of the list. O(1).
|
||||
fn pop_tail_n(@mut self) -> DListLink<T> {
|
||||
pub fn pop_tail_n(@mut self) -> DListLink<T> {
|
||||
let tl = self.peek_tail_n();
|
||||
tl.map(|nobe| self.unlink(*nobe));
|
||||
tl
|
||||
}
|
||||
/// Get the node at the list's head. O(1).
|
||||
fn peek_n(@mut self) -> DListLink<T> { self.hd }
|
||||
pub fn peek_n(@mut self) -> DListLink<T> { self.hd }
|
||||
/// Get the node at the list's tail. O(1).
|
||||
fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
|
||||
pub fn peek_tail_n(@mut self) -> DListLink<T> { self.tl }
|
||||
|
||||
/// Get the node at the list's head, failing if empty. O(1).
|
||||
fn head_n(@mut self) -> @mut DListNode<T> {
|
||||
pub fn head_n(@mut self) -> @mut DListNode<T> {
|
||||
match self.hd {
|
||||
Some(nobe) => nobe,
|
||||
None => fail!("Attempted to get the head of an empty dlist.")
|
||||
}
|
||||
}
|
||||
/// Get the node at the list's tail, failing if empty. O(1).
|
||||
fn tail_n(@mut self) -> @mut DListNode<T> {
|
||||
pub fn tail_n(@mut self) -> @mut DListNode<T> {
|
||||
match self.tl {
|
||||
Some(nobe) => nobe,
|
||||
None => fail!("Attempted to get the tail of an empty dlist.")
|
||||
@ -337,13 +335,13 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
|
||||
/// Remove a node from anywhere in the list. O(1).
|
||||
fn remove(@mut self, nobe: @mut DListNode<T>) { self.unlink(nobe); }
|
||||
pub fn remove(@mut self, nobe: @mut DListNode<T>) { self.unlink(nobe); }
|
||||
|
||||
/**
|
||||
* Empty another list onto the end of this list, joining this list's tail
|
||||
* to the other list's head. O(1).
|
||||
*/
|
||||
fn append(@mut self, them: @mut DList<T>) {
|
||||
pub fn append(@mut self, them: @mut DList<T>) {
|
||||
if managed::mut_ptr_eq(self, them) {
|
||||
fail!("Cannot append a dlist to itself!")
|
||||
}
|
||||
@ -360,7 +358,7 @@ pub impl<T> DList<T> {
|
||||
* Empty another list onto the start of this list, joining the other
|
||||
* list's tail to this list's head. O(1).
|
||||
*/
|
||||
fn prepend(@mut self, them: @mut DList<T>) {
|
||||
pub fn prepend(@mut self, them: @mut DList<T>) {
|
||||
if managed::mut_ptr_eq(self, them) {
|
||||
fail!("Cannot prepend a dlist to itself!")
|
||||
}
|
||||
@ -375,7 +373,7 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
|
||||
/// Reverse the list's elements in place. O(n).
|
||||
fn reverse(@mut self) {
|
||||
pub fn reverse(@mut self) {
|
||||
do self.hd.while_some |nobe| {
|
||||
let next_nobe = nobe.next;
|
||||
self.remove(nobe);
|
||||
@ -389,7 +387,7 @@ pub impl<T> DList<T> {
|
||||
* Remove everything from the list. This is important because the cyclic
|
||||
* links won't otherwise be automatically refcounted-collected. O(n).
|
||||
*/
|
||||
fn clear(@mut self) {
|
||||
pub fn clear(@mut self) {
|
||||
// Cute as it would be to simply detach the list and proclaim "O(1)!",
|
||||
// the GC would still be a hidden O(n). Better to be honest about it.
|
||||
while !self.is_empty() {
|
||||
@ -398,7 +396,7 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
|
||||
/// Iterate over nodes.
|
||||
fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) -> bool {
|
||||
pub fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) -> bool {
|
||||
let mut link = self.peek_n();
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
@ -409,7 +407,7 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
|
||||
/// Check data structure integrity. O(n).
|
||||
fn assert_consistent(@mut self) {
|
||||
pub fn assert_consistent(@mut self) {
|
||||
if self.hd.is_none() || self.tl.is_none() {
|
||||
assert!(self.hd.is_none() && self.tl.is_none());
|
||||
}
|
||||
@ -459,35 +457,35 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> DList<T> {
|
||||
impl<T:Copy> DList<T> {
|
||||
/// Remove data from the head of the list. O(1).
|
||||
fn pop(@mut self) -> Option<T> {
|
||||
pub fn pop(@mut self) -> Option<T> {
|
||||
self.pop_n().map(|nobe| nobe.data)
|
||||
}
|
||||
|
||||
/// Remove data from the tail of the list. O(1).
|
||||
fn pop_tail(@mut self) -> Option<T> {
|
||||
pub fn pop_tail(@mut self) -> Option<T> {
|
||||
self.pop_tail_n().map(|nobe| nobe.data)
|
||||
}
|
||||
|
||||
/// Get data at the list's head. O(1).
|
||||
fn peek(@mut self) -> Option<T> {
|
||||
pub fn peek(@mut self) -> Option<T> {
|
||||
self.peek_n().map(|nobe| nobe.data)
|
||||
}
|
||||
|
||||
/// Get data at the list's tail. O(1).
|
||||
fn peek_tail(@mut self) -> Option<T> {
|
||||
pub fn peek_tail(@mut self) -> Option<T> {
|
||||
self.peek_tail_n().map (|nobe| nobe.data)
|
||||
}
|
||||
|
||||
/// Get data at the list's head, failing if empty. O(1).
|
||||
fn head(@mut self) -> T { self.head_n().data }
|
||||
pub fn head(@mut self) -> T { self.head_n().data }
|
||||
|
||||
/// Get data at the list's tail, failing if empty. O(1).
|
||||
fn tail(@mut self) -> T { self.tail_n().data }
|
||||
pub fn tail(@mut self) -> T { self.tail_n().data }
|
||||
|
||||
/// Get the elements of the list as a vector. O(n).
|
||||
fn to_vec(@mut self) -> ~[T] {
|
||||
pub fn to_vec(@mut self) -> ~[T] {
|
||||
let mut v = vec::with_capacity(self.size);
|
||||
for old_iter::eachi(&self) |index,data| {
|
||||
v[index] = *data;
|
||||
|
@ -89,8 +89,8 @@ pub mod reader {
|
||||
|
||||
// ebml reading
|
||||
|
||||
pub impl Doc {
|
||||
fn get(&self, tag: uint) -> Doc {
|
||||
impl Doc {
|
||||
pub fn get(&self, tag: uint) -> Doc {
|
||||
get_doc(*self, tag)
|
||||
}
|
||||
}
|
||||
@ -286,7 +286,7 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
priv impl Decoder {
|
||||
impl Decoder {
|
||||
fn _check_label(&mut self, lbl: &str) {
|
||||
if self.pos < self.parent.end {
|
||||
let TaggedDoc { tag: r_tag, doc: r_doc } =
|
||||
@ -343,8 +343,9 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Decoder {
|
||||
fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R) -> R {
|
||||
impl Decoder {
|
||||
pub fn read_opaque<R>(&mut self, op: &fn(&mut Decoder, Doc) -> R)
|
||||
-> R {
|
||||
let doc = self.next_doc(EsOpaque);
|
||||
|
||||
let (old_parent, old_pos) = (self.parent, self.pos);
|
||||
@ -638,8 +639,8 @@ pub mod writer {
|
||||
}
|
||||
|
||||
// FIXME (#2741): Provide a function to write the standard ebml header.
|
||||
pub impl Encoder {
|
||||
fn start_tag(&mut self, tag_id: uint) {
|
||||
impl Encoder {
|
||||
pub fn start_tag(&mut self, tag_id: uint) {
|
||||
debug!("Start tag %u", tag_id);
|
||||
|
||||
// Write the enum ID:
|
||||
@ -651,7 +652,7 @@ pub mod writer {
|
||||
self.writer.write(zeroes);
|
||||
}
|
||||
|
||||
fn end_tag(&mut self) {
|
||||
pub fn end_tag(&mut self) {
|
||||
let last_size_pos = self.size_positions.pop();
|
||||
let cur_pos = self.writer.tell();
|
||||
self.writer.seek(last_size_pos as int, io::SeekSet);
|
||||
@ -662,72 +663,72 @@ pub mod writer {
|
||||
debug!("End tag (size = %u)", size);
|
||||
}
|
||||
|
||||
fn wr_tag(&mut self, tag_id: uint, blk: &fn()) {
|
||||
pub fn wr_tag(&mut self, tag_id: uint, blk: &fn()) {
|
||||
self.start_tag(tag_id);
|
||||
blk();
|
||||
self.end_tag();
|
||||
}
|
||||
|
||||
fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) {
|
||||
pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) {
|
||||
write_vuint(self.writer, tag_id);
|
||||
write_vuint(self.writer, b.len());
|
||||
self.writer.write(b);
|
||||
}
|
||||
|
||||
fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) {
|
||||
pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) {
|
||||
do io::u64_to_be_bytes(v, 8u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) {
|
||||
pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) {
|
||||
do io::u64_to_be_bytes(v as u64, 4u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) {
|
||||
pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) {
|
||||
do io::u64_to_be_bytes(v as u64, 2u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) {
|
||||
pub fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) {
|
||||
self.wr_tagged_bytes(tag_id, &[v]);
|
||||
}
|
||||
|
||||
fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) {
|
||||
pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) {
|
||||
do io::u64_to_be_bytes(v as u64, 8u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) {
|
||||
pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) {
|
||||
do io::u64_to_be_bytes(v as u64, 4u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) {
|
||||
pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) {
|
||||
do io::u64_to_be_bytes(v as u64, 2u) |v| {
|
||||
self.wr_tagged_bytes(tag_id, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) {
|
||||
pub fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) {
|
||||
self.wr_tagged_bytes(tag_id, &[v as u8]);
|
||||
}
|
||||
|
||||
fn wr_tagged_str(&mut self, tag_id: uint, v: &str) {
|
||||
pub fn wr_tagged_str(&mut self, tag_id: uint, v: &str) {
|
||||
str::byte_slice(v, |b| self.wr_tagged_bytes(tag_id, b));
|
||||
}
|
||||
|
||||
fn wr_bytes(&mut self, b: &[u8]) {
|
||||
pub fn wr_bytes(&mut self, b: &[u8]) {
|
||||
debug!("Write %u bytes", b.len());
|
||||
self.writer.write(b);
|
||||
}
|
||||
|
||||
fn wr_str(&mut self, s: &str) {
|
||||
pub fn wr_str(&mut self, s: &str) {
|
||||
debug!("Write str: %?", s);
|
||||
self.writer.write(str::to_bytes(s));
|
||||
}
|
||||
@ -740,7 +741,7 @@ pub mod writer {
|
||||
// Totally lame approach.
|
||||
static debug: bool = true;
|
||||
|
||||
priv impl Encoder {
|
||||
impl Encoder {
|
||||
// used internally to emit things like the vector length and so on
|
||||
fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) {
|
||||
assert!(v <= 0xFFFF_FFFF_u);
|
||||
@ -758,8 +759,8 @@ pub mod writer {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Encoder {
|
||||
fn emit_opaque(&mut self, f: &fn(&mut Encoder)) {
|
||||
impl Encoder {
|
||||
pub fn emit_opaque(&mut self, f: &fn(&mut Encoder)) {
|
||||
self.start_tag(EsOpaque as uint);
|
||||
f(self);
|
||||
self.end_tag();
|
||||
|
@ -317,8 +317,8 @@ impl<T,F:Flattener<T>,C:ByteChan> GenericChan<T> for FlatChan<T, F, C> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
||||
fn new(u: U, p: P) -> FlatPort<T, U, P> {
|
||||
impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
||||
pub fn new(u: U, p: P) -> FlatPort<T, U, P> {
|
||||
FlatPort {
|
||||
unflattener: u,
|
||||
byte_port: p
|
||||
@ -326,8 +326,8 @@ pub impl<T,U:Unflattener<T>,P:BytePort> FlatPort<T, U, P> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T,F:Flattener<T>,C:ByteChan> FlatChan<T, F, C> {
|
||||
fn new(f: F, c: C) -> FlatChan<T, F, C> {
|
||||
impl<T,F:Flattener<T>,C:ByteChan> FlatChan<T, F, C> {
|
||||
pub fn new(f: F, c: C) -> FlatChan<T, F, C> {
|
||||
FlatChan {
|
||||
flattener: f,
|
||||
byte_chan: c
|
||||
@ -380,16 +380,16 @@ pub mod flatteners {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy + Owned> PodUnflattener<T> {
|
||||
fn new() -> PodUnflattener<T> {
|
||||
impl<T:Copy + Owned> PodUnflattener<T> {
|
||||
pub fn new() -> PodUnflattener<T> {
|
||||
PodUnflattener {
|
||||
bogus: ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy + Owned> PodFlattener<T> {
|
||||
fn new() -> PodFlattener<T> {
|
||||
impl<T:Copy + Owned> PodFlattener<T> {
|
||||
pub fn new() -> PodFlattener<T> {
|
||||
PodFlattener {
|
||||
bogus: ()
|
||||
}
|
||||
@ -423,8 +423,8 @@ pub mod flatteners {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<D:Decoder,T:Decodable<D>> DeserializingUnflattener<D, T> {
|
||||
fn new(deserialize_buffer: DeserializeBuffer<T>)
|
||||
impl<D:Decoder,T:Decodable<D>> DeserializingUnflattener<D, T> {
|
||||
pub fn new(deserialize_buffer: DeserializeBuffer<T>)
|
||||
-> DeserializingUnflattener<D, T> {
|
||||
DeserializingUnflattener {
|
||||
deserialize_buffer: deserialize_buffer
|
||||
@ -432,8 +432,8 @@ pub mod flatteners {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<S:Encoder,T:Encodable<S>> SerializingFlattener<S, T> {
|
||||
fn new(serialize_value: SerializeValue<T>)
|
||||
impl<S:Encoder,T:Encodable<S>> SerializingFlattener<S, T> {
|
||||
pub fn new(serialize_value: SerializeValue<T>)
|
||||
-> SerializingFlattener<S, T> {
|
||||
SerializingFlattener {
|
||||
serialize_value: serialize_value
|
||||
@ -554,16 +554,16 @@ pub mod bytepipes {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<R:Reader> ReaderBytePort<R> {
|
||||
fn new(r: R) -> ReaderBytePort<R> {
|
||||
impl<R:Reader> ReaderBytePort<R> {
|
||||
pub fn new(r: R) -> ReaderBytePort<R> {
|
||||
ReaderBytePort {
|
||||
reader: r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<W:Writer> WriterByteChan<W> {
|
||||
fn new(w: W) -> WriterByteChan<W> {
|
||||
impl<W:Writer> WriterByteChan<W> {
|
||||
pub fn new(w: W) -> WriterByteChan<W> {
|
||||
WriterByteChan {
|
||||
writer: w
|
||||
}
|
||||
@ -619,8 +619,8 @@ pub mod bytepipes {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl PipeBytePort {
|
||||
fn new(p: Port<~[u8]>) -> PipeBytePort {
|
||||
impl PipeBytePort {
|
||||
pub fn new(p: Port<~[u8]>) -> PipeBytePort {
|
||||
PipeBytePort {
|
||||
port: p,
|
||||
buf: @mut ~[]
|
||||
@ -628,8 +628,8 @@ pub mod bytepipes {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl PipeByteChan {
|
||||
fn new(c: Chan<~[u8]>) -> PipeByteChan {
|
||||
impl PipeByteChan {
|
||||
pub fn new(c: Chan<~[u8]>) -> PipeByteChan {
|
||||
PipeByteChan {
|
||||
chan: c
|
||||
}
|
||||
|
@ -54,15 +54,15 @@ priv enum FutureState<A> {
|
||||
}
|
||||
|
||||
/// Methods on the `future` type
|
||||
pub impl<A:Copy> Future<A> {
|
||||
fn get(&mut self) -> A {
|
||||
impl<A:Copy> Future<A> {
|
||||
pub fn get(&mut self) -> A {
|
||||
//! Get the value of the future.
|
||||
*(self.get_ref())
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<A> Future<A> {
|
||||
fn get_ref<'a>(&'a mut self) -> &'a A {
|
||||
impl<A> Future<A> {
|
||||
pub fn get_ref<'a>(&'a mut self) -> &'a A {
|
||||
/*!
|
||||
* Executes the future's closure and then returns a borrowed
|
||||
* pointer to the result. The borrowed pointer lasts as long as
|
||||
|
@ -10,7 +10,9 @@
|
||||
|
||||
// Rust JSON serialization library
|
||||
// Copyright (c) 2011 Google Inc.
|
||||
|
||||
#[forbid(non_camel_case_types)];
|
||||
#[allow(missing_doc)];
|
||||
|
||||
//! json serialization
|
||||
|
||||
@ -497,8 +499,8 @@ pub fn Parser(rdr: @io::Reader) -> Parser {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Parser {
|
||||
fn parse(&mut self) -> Result<Json, Error> {
|
||||
impl Parser {
|
||||
pub fn parse(&mut self) -> Result<Json, Error> {
|
||||
match self.parse_value() {
|
||||
Ok(value) => {
|
||||
// Skip trailing whitespaces.
|
||||
@ -515,7 +517,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
priv impl Parser {
|
||||
impl Parser {
|
||||
fn eof(&self) -> bool { self.ch == -1 as char }
|
||||
|
||||
fn bump(&mut self) {
|
||||
|
@ -826,7 +826,7 @@ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
|
||||
}
|
||||
|
||||
/// Convenience methods extending `net::tcp::TcpSocket`
|
||||
pub impl TcpSocket {
|
||||
impl TcpSocket {
|
||||
pub fn read_start(&self) -> result::Result<@Port<
|
||||
result::Result<~[u8], TcpErrData>>, TcpErrData> {
|
||||
read_start(self)
|
||||
@ -835,11 +835,11 @@ pub impl TcpSocket {
|
||||
result::Result<(), TcpErrData> {
|
||||
read_stop(self)
|
||||
}
|
||||
fn read(&self, timeout_msecs: uint) ->
|
||||
pub fn read(&self, timeout_msecs: uint) ->
|
||||
result::Result<~[u8], TcpErrData> {
|
||||
read(self, timeout_msecs)
|
||||
}
|
||||
fn read_future(&self, timeout_msecs: uint) ->
|
||||
pub fn read_future(&self, timeout_msecs: uint) ->
|
||||
future::Future<result::Result<~[u8], TcpErrData>> {
|
||||
read_future(self, timeout_msecs)
|
||||
}
|
||||
|
@ -41,16 +41,15 @@ struct UserInfo {
|
||||
|
||||
pub type Query = ~[(~str, ~str)];
|
||||
|
||||
pub impl Url {
|
||||
fn new(
|
||||
scheme: ~str,
|
||||
user: Option<UserInfo>,
|
||||
host: ~str,
|
||||
port: Option<~str>,
|
||||
path: ~str,
|
||||
query: Query,
|
||||
fragment: Option<~str>
|
||||
) -> Url {
|
||||
impl Url {
|
||||
pub fn new(scheme: ~str,
|
||||
user: Option<UserInfo>,
|
||||
host: ~str,
|
||||
port: Option<~str>,
|
||||
path: ~str,
|
||||
query: Query,
|
||||
fragment: Option<~str>)
|
||||
-> Url {
|
||||
Url {
|
||||
scheme: scheme,
|
||||
user: user,
|
||||
@ -63,8 +62,8 @@ pub impl Url {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl UserInfo {
|
||||
fn new(user: ~str, pass: Option<~str>) -> UserInfo {
|
||||
impl UserInfo {
|
||||
pub fn new(user: ~str, pass: Option<~str>) -> UserInfo {
|
||||
UserInfo { user: user, pass: pass }
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ A BigUint is represented as an array of BigDigits.
|
||||
A BigInt is a combination of BigUint and Sign.
|
||||
*/
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
@ -1095,9 +1097,8 @@ impl FromStrRadix for BigInt {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl BigInt {
|
||||
impl BigInt {
|
||||
/// Creates and initializes an BigInt.
|
||||
|
||||
pub fn new(sign: Sign, v: ~[BigDigit]) -> BigInt {
|
||||
BigInt::from_biguint(sign, BigUint::new(v))
|
||||
}
|
||||
@ -1139,8 +1140,7 @@ pub impl BigInt {
|
||||
.map_consume(|bu| BigInt::from_biguint(sign, bu));
|
||||
}
|
||||
|
||||
|
||||
fn to_uint(&self) -> uint {
|
||||
pub fn to_uint(&self) -> uint {
|
||||
match self.sign {
|
||||
Plus => self.data.to_uint(),
|
||||
Zero => 0,
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
//! A priority queue implemented with a binary heap
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::old_iter::BaseIter;
|
||||
@ -44,26 +46,26 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
|
||||
fn clear(&mut self) { self.data.truncate(0) }
|
||||
}
|
||||
|
||||
pub impl <T:Ord> PriorityQueue<T> {
|
||||
impl<T:Ord> PriorityQueue<T> {
|
||||
/// Returns the greatest item in the queue - fails if empty
|
||||
fn top<'a>(&'a self) -> &'a T { &self.data[0] }
|
||||
pub fn top<'a>(&'a self) -> &'a T { &self.data[0] }
|
||||
|
||||
/// Returns the greatest item in the queue - None if empty
|
||||
fn maybe_top<'a>(&'a self) -> Option<&'a T> {
|
||||
pub fn maybe_top<'a>(&'a self) -> Option<&'a T> {
|
||||
if self.is_empty() { None } else { Some(self.top()) }
|
||||
}
|
||||
|
||||
/// Returns the number of elements the queue can hold without reallocating
|
||||
fn capacity(&self) -> uint { vec::capacity(&self.data) }
|
||||
pub fn capacity(&self) -> uint { vec::capacity(&self.data) }
|
||||
|
||||
fn reserve(&mut self, n: uint) { vec::reserve(&mut self.data, n) }
|
||||
pub fn reserve(&mut self, n: uint) { vec::reserve(&mut self.data, n) }
|
||||
|
||||
fn reserve_at_least(&mut self, n: uint) {
|
||||
pub fn reserve_at_least(&mut self, n: uint) {
|
||||
vec::reserve_at_least(&mut self.data, n)
|
||||
}
|
||||
|
||||
/// Pop the greatest item from the queue - fails if empty
|
||||
fn pop(&mut self) -> T {
|
||||
pub fn pop(&mut self) -> T {
|
||||
let mut item = self.data.pop();
|
||||
if !self.is_empty() {
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
@ -73,19 +75,19 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
}
|
||||
|
||||
/// Pop the greatest item from the queue - None if empty
|
||||
fn maybe_pop(&mut self) -> Option<T> {
|
||||
pub fn maybe_pop(&mut self) -> Option<T> {
|
||||
if self.is_empty() { None } else { Some(self.pop()) }
|
||||
}
|
||||
|
||||
/// Push an item onto the queue
|
||||
fn push(&mut self, item: T) {
|
||||
pub fn push(&mut self, item: T) {
|
||||
self.data.push(item);
|
||||
let new_len = self.len() - 1;
|
||||
self.siftup(0, new_len);
|
||||
}
|
||||
|
||||
/// Optimized version of a push followed by a pop
|
||||
fn push_pop(&mut self, mut item: T) -> T {
|
||||
pub fn push_pop(&mut self, mut item: T) -> T {
|
||||
if !self.is_empty() && self.data[0] > item {
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.siftdown(0);
|
||||
@ -94,18 +96,18 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
}
|
||||
|
||||
/// Optimized version of a pop followed by a push - fails if empty
|
||||
fn replace(&mut self, mut item: T) -> T {
|
||||
pub fn replace(&mut self, mut item: T) -> T {
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.siftdown(0);
|
||||
item
|
||||
}
|
||||
|
||||
/// Consume the PriorityQueue and return the underlying vector
|
||||
fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v }
|
||||
pub fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v }
|
||||
|
||||
/// Consume the PriorityQueue and return a vector in sorted
|
||||
/// (ascending) order
|
||||
fn to_sorted_vec(self) -> ~[T] {
|
||||
pub fn to_sorted_vec(self) -> ~[T] {
|
||||
let mut q = self;
|
||||
let mut end = q.len();
|
||||
while end > 1 {
|
||||
@ -117,10 +119,10 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
}
|
||||
|
||||
/// Create an empty PriorityQueue
|
||||
fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
|
||||
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }
|
||||
|
||||
/// Create a PriorityQueue from a vector (heapify)
|
||||
fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
|
||||
pub fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
|
||||
let mut q = PriorityQueue{data: xs,};
|
||||
let mut n = q.len() / 2;
|
||||
while n > 0 {
|
||||
@ -135,8 +137,7 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
// zeroed element), shift along the others and move it back into the
|
||||
// vector over the junk element. This reduces the constant factor
|
||||
// compared to using swaps, which involves twice as many moves.
|
||||
|
||||
priv fn siftup(&mut self, start: uint, mut pos: uint) {
|
||||
fn siftup(&mut self, start: uint, mut pos: uint) {
|
||||
unsafe {
|
||||
let new = replace(&mut self.data[pos], init());
|
||||
|
||||
@ -154,7 +155,7 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
|
||||
fn siftdown_range(&mut self, mut pos: uint, end: uint) {
|
||||
unsafe {
|
||||
let start = pos;
|
||||
let new = replace(&mut self.data[pos], init());
|
||||
@ -176,7 +177,7 @@ pub impl <T:Ord> PriorityQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn siftdown(&mut self, pos: uint) {
|
||||
fn siftdown(&mut self, pos: uint) {
|
||||
let len = self.len();
|
||||
self.siftdown_range(pos, len);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ pub struct Rc<T> {
|
||||
priv ptr: *mut RcBox<T>,
|
||||
}
|
||||
|
||||
priv impl<T> Rc<T> {
|
||||
impl<T> Rc<T> {
|
||||
unsafe fn new(value: T) -> Rc<T> {
|
||||
let ptr = malloc(sys::size_of::<RcBox<T>>() as size_t) as *mut RcBox<T>;
|
||||
assert!(!ptr::is_null(ptr));
|
||||
@ -59,9 +59,9 @@ pub fn rc_from_const<T: Const>(value: T) -> Rc<T> {
|
||||
unsafe { Rc::new(value) }
|
||||
}
|
||||
|
||||
pub impl<T> Rc<T> {
|
||||
impl<T> Rc<T> {
|
||||
#[inline(always)]
|
||||
fn borrow<'r>(&'r self) -> &'r T {
|
||||
pub fn borrow<'r>(&'r self) -> &'r T {
|
||||
unsafe { cast::copy_lifetime(self, &(*self.ptr).value) }
|
||||
}
|
||||
}
|
||||
@ -170,7 +170,7 @@ pub struct RcMut<T> {
|
||||
priv ptr: *mut RcMutBox<T>,
|
||||
}
|
||||
|
||||
priv impl<T> RcMut<T> {
|
||||
impl<T> RcMut<T> {
|
||||
unsafe fn new(value: T) -> RcMut<T> {
|
||||
let ptr = malloc(sys::size_of::<RcMutBox<T>>() as size_t) as *mut RcMutBox<T>;
|
||||
assert!(!ptr::is_null(ptr));
|
||||
@ -189,10 +189,10 @@ pub fn rc_mut_from_const<T: Const>(value: T) -> RcMut<T> {
|
||||
unsafe { RcMut::new(value) }
|
||||
}
|
||||
|
||||
pub impl<T> RcMut<T> {
|
||||
impl<T> RcMut<T> {
|
||||
/// Fails if there is already a mutable borrow of the box
|
||||
#[inline]
|
||||
fn with_borrow<U>(&self, f: &fn(&T) -> U) -> U {
|
||||
pub fn with_borrow<U>(&self, f: &fn(&T) -> U) -> U {
|
||||
unsafe {
|
||||
assert!((*self.ptr).borrow != Mutable);
|
||||
let previous = (*self.ptr).borrow;
|
||||
@ -205,7 +205,7 @@ pub impl<T> RcMut<T> {
|
||||
|
||||
/// Fails if there is already a mutable or immutable borrow of the box
|
||||
#[inline]
|
||||
fn with_mut_borrow<U>(&self, f: &fn(&mut T) -> U) -> U {
|
||||
pub fn with_mut_borrow<U>(&self, f: &fn(&mut T) -> U) -> U {
|
||||
unsafe {
|
||||
assert_eq!((*self.ptr).borrow, Nothing);
|
||||
(*self.ptr).borrow = Mutable;
|
||||
|
@ -13,6 +13,8 @@
|
||||
* are O(highest integer key).
|
||||
*/
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::cmp;
|
||||
@ -152,12 +154,12 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<V> SmallIntMap<V> {
|
||||
impl<V> SmallIntMap<V> {
|
||||
/// Create an empty SmallIntMap
|
||||
fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
|
||||
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
|
||||
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
|
||||
for uint::range_rev(self.v.len(), 0) |i| {
|
||||
match self.v[i - 1] {
|
||||
Some(ref elt) => if !it(i - 1, elt) { return false; },
|
||||
@ -167,14 +169,14 @@ pub impl<V> SmallIntMap<V> {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn get<'a>(&'a self, key: &uint) -> &'a V {
|
||||
pub fn get<'a>(&'a self, key: &uint) -> &'a V {
|
||||
self.find(key).expect("key not present")
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<V:Copy> SmallIntMap<V> {
|
||||
fn update_with_key(&mut self, key: uint, val: V,
|
||||
ff: &fn(uint, V, V) -> V) -> bool {
|
||||
impl<V:Copy> SmallIntMap<V> {
|
||||
pub fn update_with_key(&mut self, key: uint, val: V,
|
||||
ff: &fn(uint, V, V) -> V) -> bool {
|
||||
let new_val = match self.find(&key) {
|
||||
None => val,
|
||||
Some(orig) => ff(key, *orig, val)
|
||||
@ -182,7 +184,8 @@ pub impl<V:Copy> SmallIntMap<V> {
|
||||
self.insert(key, new_val)
|
||||
}
|
||||
|
||||
fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) -> bool {
|
||||
pub fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V)
|
||||
-> bool {
|
||||
self.update_with_key(key, newval, |_k, v, v1| ff(v,v1))
|
||||
}
|
||||
}
|
||||
@ -280,9 +283,9 @@ impl Set<uint> for SmallIntSet {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl SmallIntSet {
|
||||
impl SmallIntSet {
|
||||
/// Create an empty SmallIntSet
|
||||
fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} }
|
||||
pub fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -99,8 +99,8 @@ fn new_sem_and_signal(count: int, num_condvars: uint)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub impl<Q:Owned> Sem<Q> {
|
||||
fn acquire(&self) {
|
||||
impl<Q:Owned> Sem<Q> {
|
||||
pub fn acquire(&self) {
|
||||
unsafe {
|
||||
let mut waiter_nobe = None;
|
||||
do (**self).with |state| {
|
||||
@ -122,7 +122,8 @@ pub impl<Q:Owned> Sem<Q> {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn release(&self) {
|
||||
|
||||
pub fn release(&self) {
|
||||
unsafe {
|
||||
do (**self).with |state| {
|
||||
state.count += 1;
|
||||
@ -135,8 +136,8 @@ pub impl<Q:Owned> Sem<Q> {
|
||||
}
|
||||
// FIXME(#3154) move both copies of this into Sem<Q>, and unify the 2 structs
|
||||
#[doc(hidden)]
|
||||
pub impl Sem<()> {
|
||||
fn access<U>(&self, blk: &fn() -> U) -> U {
|
||||
impl Sem<()> {
|
||||
pub fn access<U>(&self, blk: &fn() -> U) -> U {
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
@ -147,9 +148,10 @@ pub impl Sem<()> {
|
||||
blk()
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub impl Sem<~[Waitqueue]> {
|
||||
fn access<U>(&self, blk: &fn() -> U) -> U {
|
||||
impl Sem<~[Waitqueue]> {
|
||||
pub fn access<U>(&self, blk: &fn() -> U) -> U {
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
@ -193,7 +195,7 @@ pub struct Condvar<'self> { priv sem: &'self Sem<~[Waitqueue]> }
|
||||
#[unsafe_destructor]
|
||||
impl<'self> Drop for Condvar<'self> { fn finalize(&self) {} }
|
||||
|
||||
pub impl<'self> Condvar<'self> {
|
||||
impl<'self> Condvar<'self> {
|
||||
/**
|
||||
* Atomically drop the associated lock, and block until a signal is sent.
|
||||
*
|
||||
@ -202,7 +204,7 @@ pub impl<'self> Condvar<'self> {
|
||||
* while waiting on a condition variable will wake up, fail, and unlock
|
||||
* the associated lock as it unwinds.
|
||||
*/
|
||||
fn wait(&self) { self.wait_on(0) }
|
||||
pub fn wait(&self) { self.wait_on(0) }
|
||||
|
||||
/**
|
||||
* As wait(), but can specify which of multiple condition variables to
|
||||
@ -215,7 +217,7 @@ pub impl<'self> Condvar<'self> {
|
||||
*
|
||||
* wait() is equivalent to wait_on(0).
|
||||
*/
|
||||
fn wait_on(&self, condvar_id: uint) {
|
||||
pub fn wait_on(&self, condvar_id: uint) {
|
||||
// Create waiter nobe.
|
||||
let (WaitEnd, SignalEnd) = comm::oneshot();
|
||||
let mut WaitEnd = Some(WaitEnd);
|
||||
@ -284,10 +286,10 @@ pub impl<'self> Condvar<'self> {
|
||||
}
|
||||
|
||||
/// Wake up a blocked task. Returns false if there was no blocked task.
|
||||
fn signal(&self) -> bool { self.signal_on(0) }
|
||||
pub fn signal(&self) -> bool { self.signal_on(0) }
|
||||
|
||||
/// As signal, but with a specified condvar_id. See wait_on.
|
||||
fn signal_on(&self, condvar_id: uint) -> bool {
|
||||
pub fn signal_on(&self, condvar_id: uint) -> bool {
|
||||
unsafe {
|
||||
let mut out_of_bounds = None;
|
||||
let mut result = false;
|
||||
@ -305,10 +307,10 @@ pub impl<'self> Condvar<'self> {
|
||||
}
|
||||
|
||||
/// Wake up all blocked tasks. Returns the number of tasks woken.
|
||||
fn broadcast(&self) -> uint { self.broadcast_on(0) }
|
||||
pub fn broadcast(&self) -> uint { self.broadcast_on(0) }
|
||||
|
||||
/// As broadcast, but with a specified condvar_id. See wait_on.
|
||||
fn broadcast_on(&self, condvar_id: uint) -> uint {
|
||||
pub fn broadcast_on(&self, condvar_id: uint) -> uint {
|
||||
let mut out_of_bounds = None;
|
||||
let mut queue = None;
|
||||
unsafe {
|
||||
@ -347,9 +349,9 @@ fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str,
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub impl Sem<~[Waitqueue]> {
|
||||
impl Sem<~[Waitqueue]> {
|
||||
// The only other place that condvars get built is rwlock_write_mode.
|
||||
fn access_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn access_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
do self.access { blk(&Condvar { sem: self }) }
|
||||
}
|
||||
}
|
||||
@ -373,21 +375,21 @@ impl Clone for Semaphore {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Semaphore {
|
||||
impl Semaphore {
|
||||
/**
|
||||
* Acquire a resource represented by the semaphore. Blocks if necessary
|
||||
* until resource(s) become available.
|
||||
*/
|
||||
fn acquire(&self) { (&self.sem).acquire() }
|
||||
pub fn acquire(&self) { (&self.sem).acquire() }
|
||||
|
||||
/**
|
||||
* Release a held resource represented by the semaphore. Wakes a blocked
|
||||
* contending task, if any exist. Won't block the caller.
|
||||
*/
|
||||
fn release(&self) { (&self.sem).release() }
|
||||
pub fn release(&self) { (&self.sem).release() }
|
||||
|
||||
/// Run a function with ownership of one of the semaphore's resources.
|
||||
fn access<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
|
||||
pub fn access<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -421,12 +423,12 @@ impl Clone for Mutex {
|
||||
fn clone(&self) -> Mutex { Mutex { sem: Sem((*self.sem).clone()) } }
|
||||
}
|
||||
|
||||
pub impl Mutex {
|
||||
impl Mutex {
|
||||
/// Run a function with ownership of the mutex.
|
||||
fn lock<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
|
||||
pub fn lock<U>(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) }
|
||||
|
||||
/// Run a function with ownership of the mutex and a handle to a condvar.
|
||||
fn lock_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn lock_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
(&self.sem).access_cond(blk)
|
||||
}
|
||||
}
|
||||
@ -470,9 +472,9 @@ pub fn rwlock_with_condvars(num_condvars: uint) -> RWlock {
|
||||
read_count: 0 }) }
|
||||
}
|
||||
|
||||
pub impl RWlock {
|
||||
impl RWlock {
|
||||
/// Create a new handle to the rwlock.
|
||||
fn clone(&self) -> RWlock {
|
||||
pub fn clone(&self) -> RWlock {
|
||||
RWlock { order_lock: (&(self.order_lock)).clone(),
|
||||
access_lock: Sem((*self.access_lock).clone()),
|
||||
state: self.state.clone() }
|
||||
@ -482,7 +484,7 @@ pub impl RWlock {
|
||||
* Run a function with the rwlock in read mode. Calls to 'read' from other
|
||||
* tasks may run concurrently with this one.
|
||||
*/
|
||||
fn read<U>(&self, blk: &fn() -> U) -> U {
|
||||
pub fn read<U>(&self, blk: &fn() -> U) -> U {
|
||||
let mut release = None;
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
@ -513,7 +515,7 @@ pub impl RWlock {
|
||||
* Run a function with the rwlock in write mode. No calls to 'read' or
|
||||
* 'write' from other tasks will run concurrently with this one.
|
||||
*/
|
||||
fn write<U>(&self, blk: &fn() -> U) -> U {
|
||||
pub fn write<U>(&self, blk: &fn() -> U) -> U {
|
||||
unsafe {
|
||||
do task::unkillable {
|
||||
(&self.order_lock).acquire();
|
||||
@ -531,7 +533,7 @@ pub impl RWlock {
|
||||
* the waiting task is signalled. (Note: a writer that waited and then
|
||||
* was signalled might reacquire the lock before other waiting writers.)
|
||||
*/
|
||||
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
// NB: You might think I should thread the order_lock into the cond
|
||||
// wait call, so that it gets waited on before access_lock gets
|
||||
// reacquired upon being woken up. However, (a) this would be not
|
||||
@ -569,7 +571,7 @@ pub impl RWlock {
|
||||
* }
|
||||
* ~~~
|
||||
*/
|
||||
fn write_downgrade<U>(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U {
|
||||
pub fn write_downgrade<U>(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U {
|
||||
// Implementation slightly different from the slicker 'write's above.
|
||||
// The exit path is conditional on whether the caller downgrades.
|
||||
let mut _release = None;
|
||||
@ -585,9 +587,8 @@ pub impl RWlock {
|
||||
}
|
||||
|
||||
/// To be called inside of the write_downgrade block.
|
||||
fn downgrade<'a>(&self,
|
||||
token: RWlockWriteMode<'a>)
|
||||
-> RWlockReadMode<'a> {
|
||||
pub fn downgrade<'a>(&self, token: RWlockWriteMode<'a>)
|
||||
-> RWlockReadMode<'a> {
|
||||
if !ptr::ref_eq(self, token.lock) {
|
||||
fail!("Can't downgrade() with a different rwlock's write_mode!");
|
||||
}
|
||||
@ -703,18 +704,18 @@ pub struct RWlockReadMode<'self> { priv lock: &'self RWlock }
|
||||
#[unsafe_destructor]
|
||||
impl<'self> Drop for RWlockReadMode<'self> { fn finalize(&self) {} }
|
||||
|
||||
pub impl<'self> RWlockWriteMode<'self> {
|
||||
impl<'self> RWlockWriteMode<'self> {
|
||||
/// Access the pre-downgrade rwlock in write mode.
|
||||
fn write<U>(&self, blk: &fn() -> U) -> U { blk() }
|
||||
pub fn write<U>(&self, blk: &fn() -> U) -> U { blk() }
|
||||
/// Access the pre-downgrade rwlock in write mode with a condvar.
|
||||
fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
pub fn write_cond<U>(&self, blk: &fn(c: &Condvar) -> U) -> U {
|
||||
blk(&Condvar { sem: &self.lock.access_lock })
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<'self> RWlockReadMode<'self> {
|
||||
impl<'self> RWlockReadMode<'self> {
|
||||
/// Access the post-downgrade rwlock in read mode.
|
||||
fn read<U>(&self, blk: &fn() -> U) -> U { blk() }
|
||||
pub fn read<U>(&self, blk: &fn() -> U) -> U { blk() }
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -42,16 +42,16 @@ impl<T> Drop for TaskPool<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> TaskPool<T> {
|
||||
impl<T> TaskPool<T> {
|
||||
/// Spawns a new task pool with `n_tasks` tasks. If the `sched_mode`
|
||||
/// is None, the tasks run on this scheduler; otherwise, they run on a
|
||||
/// new scheduler with the given mode. The provided `init_fn_factory`
|
||||
/// returns a function which, given the index of the task, should return
|
||||
/// local data to be kept around in that task.
|
||||
fn new(n_tasks: uint,
|
||||
opt_sched_mode: Option<SchedMode>,
|
||||
init_fn_factory: ~fn() -> ~fn(uint) -> T)
|
||||
-> TaskPool<T> {
|
||||
pub fn new(n_tasks: uint,
|
||||
opt_sched_mode: Option<SchedMode>,
|
||||
init_fn_factory: ~fn() -> ~fn(uint) -> T)
|
||||
-> TaskPool<T> {
|
||||
assert!(n_tasks >= 1);
|
||||
|
||||
let channels = do vec::from_fn(n_tasks) |i| {
|
||||
@ -89,7 +89,7 @@ pub impl<T> TaskPool<T> {
|
||||
|
||||
/// Executes the function `f` on a task in the pool. The function
|
||||
/// receives a reference to the local data returned by the `init_fn`.
|
||||
fn execute(&mut self, f: ~fn(&T)) {
|
||||
pub fn execute(&mut self, f: ~fn(&T)) {
|
||||
self.channels[self.next_index].send(Execute(f));
|
||||
self.next_index += 1;
|
||||
if self.next_index == self.channels.len() { self.next_index = 0; }
|
||||
|
@ -617,8 +617,7 @@ pub mod bench {
|
||||
use test::{BenchHarness, BenchSamples};
|
||||
use time::precise_time_ns;
|
||||
|
||||
pub impl BenchHarness {
|
||||
|
||||
impl BenchHarness {
|
||||
/// Callback for benchmark functions to run in their body.
|
||||
pub fn iter(&mut self, inner:&fn()) {
|
||||
self.ns_start = precise_time_ns();
|
||||
@ -629,7 +628,7 @@ pub mod bench {
|
||||
self.ns_end = precise_time_ns();
|
||||
}
|
||||
|
||||
fn ns_elapsed(&mut self) -> u64 {
|
||||
pub fn ns_elapsed(&mut self) -> u64 {
|
||||
if self.ns_start == 0 || self.ns_end == 0 {
|
||||
0
|
||||
} else {
|
||||
@ -637,7 +636,7 @@ pub mod bench {
|
||||
}
|
||||
}
|
||||
|
||||
fn ns_per_iter(&mut self) -> u64 {
|
||||
pub fn ns_per_iter(&mut self) -> u64 {
|
||||
if self.iterations == 0 {
|
||||
0
|
||||
} else {
|
||||
@ -645,7 +644,7 @@ pub mod bench {
|
||||
}
|
||||
}
|
||||
|
||||
fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) {
|
||||
pub fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) {
|
||||
self.iterations = n;
|
||||
debug!("running benchmark for %u iterations",
|
||||
n as uint);
|
||||
|
@ -49,8 +49,8 @@ pub struct Timespec { sec: i64, nsec: i32 }
|
||||
* -1.2 seconds before the epoch is represented by `Timespec { sec: -2_i64,
|
||||
* nsec: 800_000_000_i32 }`.
|
||||
*/
|
||||
pub impl Timespec {
|
||||
fn new(sec: i64, nsec: i32) -> Timespec {
|
||||
impl Timespec {
|
||||
pub fn new(sec: i64, nsec: i32) -> Timespec {
|
||||
assert!(nsec >= 0 && nsec < NSEC_PER_SEC);
|
||||
Timespec { sec: sec, nsec: nsec }
|
||||
}
|
||||
@ -180,9 +180,9 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str {
|
||||
do_strftime(format, tm)
|
||||
}
|
||||
|
||||
pub impl Tm {
|
||||
impl Tm {
|
||||
/// Convert time to the seconds from January 1, 1970
|
||||
fn to_timespec(&self) -> Timespec {
|
||||
pub fn to_timespec(&self) -> Timespec {
|
||||
unsafe {
|
||||
let sec = match self.tm_gmtoff {
|
||||
0_i32 => rustrt::rust_timegm(self),
|
||||
@ -194,12 +194,12 @@ pub impl Tm {
|
||||
}
|
||||
|
||||
/// Convert time to the local timezone
|
||||
fn to_local(&self) -> Tm {
|
||||
pub fn to_local(&self) -> Tm {
|
||||
at(self.to_timespec())
|
||||
}
|
||||
|
||||
/// Convert time to the UTC
|
||||
fn to_utc(&self) -> Tm {
|
||||
pub fn to_utc(&self) -> Tm {
|
||||
at_utc(self.to_timespec())
|
||||
}
|
||||
|
||||
@ -207,10 +207,10 @@ pub impl Tm {
|
||||
* Return a string of the current time in the form
|
||||
* "Thu Jan 1 00:00:00 1970".
|
||||
*/
|
||||
fn ctime(&self) -> ~str { self.strftime("%c") }
|
||||
pub fn ctime(&self) -> ~str { self.strftime("%c") }
|
||||
|
||||
/// Formats the time according to the format string.
|
||||
fn strftime(&self, format: &str) -> ~str {
|
||||
pub fn strftime(&self, format: &str) -> ~str {
|
||||
strftime(format, self)
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ pub impl Tm {
|
||||
* local: "Thu, 22 Mar 2012 07:53:18 PST"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 UTC"
|
||||
*/
|
||||
fn rfc822(&self) -> ~str {
|
||||
pub fn rfc822(&self) -> ~str {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%a, %d %b %Y %T GMT")
|
||||
} else {
|
||||
@ -234,7 +234,7 @@ pub impl Tm {
|
||||
* local: "Thu, 22 Mar 2012 07:53:18 -0700"
|
||||
* utc: "Thu, 22 Mar 2012 14:53:18 -0000"
|
||||
*/
|
||||
fn rfc822z(&self) -> ~str {
|
||||
pub fn rfc822z(&self) -> ~str {
|
||||
self.strftime("%a, %d %b %Y %T %z")
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ pub impl Tm {
|
||||
* local: "2012-02-22T07:53:18-07:00"
|
||||
* utc: "2012-02-22T14:53:18Z"
|
||||
*/
|
||||
fn rfc3339(&self) -> ~str {
|
||||
pub fn rfc3339(&self) -> ~str {
|
||||
if self.tm_gmtoff == 0_i32 {
|
||||
self.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
} else {
|
||||
|
@ -181,28 +181,28 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<K: TotalOrd, V> TreeMap<K, V> {
|
||||
impl<K: TotalOrd, V> TreeMap<K, V> {
|
||||
/// Create an empty TreeMap
|
||||
fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
||||
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
|
||||
pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool {
|
||||
each_reverse(&self.root, f)
|
||||
}
|
||||
|
||||
/// Visit all keys in reverse order
|
||||
fn each_key_reverse(&self, f: &fn(&K) -> bool) -> bool {
|
||||
pub fn each_key_reverse(&self, f: &fn(&K) -> bool) -> bool {
|
||||
self.each_reverse(|k, _| f(k))
|
||||
}
|
||||
|
||||
/// Visit all values in reverse order
|
||||
fn each_value_reverse(&self, f: &fn(&V) -> bool) -> bool {
|
||||
pub fn each_value_reverse(&self, f: &fn(&V) -> bool) -> bool {
|
||||
self.each_reverse(|_, v| f(v))
|
||||
}
|
||||
|
||||
/// Get a lazy iterator over the key-value pairs in the map.
|
||||
/// Requires that it be frozen (immutable).
|
||||
fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> {
|
||||
pub fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> {
|
||||
TreeMapIterator{stack: ~[], node: &self.root}
|
||||
}
|
||||
}
|
||||
@ -489,15 +489,15 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl <T: TotalOrd> TreeSet<T> {
|
||||
impl<T: TotalOrd> TreeSet<T> {
|
||||
/// Create an empty TreeSet
|
||||
#[inline(always)]
|
||||
fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
||||
pub fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
||||
|
||||
/// Get a lazy iterator over the values in the set.
|
||||
/// Requires that it be frozen (immutable).
|
||||
#[inline(always)]
|
||||
fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> {
|
||||
pub fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> {
|
||||
TreeSetIterator{iter: self.map.iter()}
|
||||
}
|
||||
}
|
||||
@ -517,9 +517,10 @@ struct TreeNode<K, V> {
|
||||
level: uint
|
||||
}
|
||||
|
||||
pub impl<K: TotalOrd, V> TreeNode<K, V> {
|
||||
impl<K: TotalOrd, V> TreeNode<K, V> {
|
||||
/// Creates a new tree node.
|
||||
#[inline(always)]
|
||||
fn new(key: K, value: V) -> TreeNode<K, V> {
|
||||
pub fn new(key: K, value: V) -> TreeNode<K, V> {
|
||||
TreeNode{key: key, value: value, left: None, right: None, level: 1}
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +127,12 @@ impl cmp::Ord for WorkKey {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl WorkKey {
|
||||
fn new(kind: &str, name: &str) -> WorkKey {
|
||||
WorkKey { kind: kind.to_owned(), name: name.to_owned() }
|
||||
impl WorkKey {
|
||||
pub fn new(kind: &str, name: &str) -> WorkKey {
|
||||
WorkKey {
|
||||
kind: kind.to_owned(),
|
||||
name: name.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,11 +170,11 @@ struct Database {
|
||||
db_dirty: bool
|
||||
}
|
||||
|
||||
pub impl Database {
|
||||
fn prepare(&mut self,
|
||||
fn_name: &str,
|
||||
declared_inputs: &WorkMap)
|
||||
-> Option<(WorkMap, WorkMap, ~str)> {
|
||||
impl Database {
|
||||
pub fn prepare(&mut self,
|
||||
fn_name: &str,
|
||||
declared_inputs: &WorkMap)
|
||||
-> Option<(WorkMap, WorkMap, ~str)> {
|
||||
let k = json_encode(&(fn_name, declared_inputs));
|
||||
match self.db_cache.find(&k) {
|
||||
None => None,
|
||||
@ -179,12 +182,12 @@ pub impl Database {
|
||||
}
|
||||
}
|
||||
|
||||
fn cache(&mut self,
|
||||
fn_name: &str,
|
||||
declared_inputs: &WorkMap,
|
||||
discovered_inputs: &WorkMap,
|
||||
discovered_outputs: &WorkMap,
|
||||
result: &str) {
|
||||
pub fn cache(&mut self,
|
||||
fn_name: &str,
|
||||
declared_inputs: &WorkMap,
|
||||
discovered_inputs: &WorkMap,
|
||||
discovered_outputs: &WorkMap,
|
||||
result: &str) {
|
||||
let k = json_encode(&(fn_name, declared_inputs));
|
||||
let v = json_encode(&(discovered_inputs,
|
||||
discovered_outputs,
|
||||
@ -199,8 +202,8 @@ struct Logger {
|
||||
a: ()
|
||||
}
|
||||
|
||||
pub impl Logger {
|
||||
fn info(&self, i: &str) {
|
||||
impl Logger {
|
||||
pub fn info(&self, i: &str) {
|
||||
io::println(~"workcache: " + i);
|
||||
}
|
||||
}
|
||||
@ -257,11 +260,9 @@ fn digest_file(path: &Path) -> ~str {
|
||||
sha.result_str()
|
||||
}
|
||||
|
||||
pub impl Context {
|
||||
|
||||
fn new(db: @mut Database,
|
||||
lg: @mut Logger,
|
||||
cfg: @json::Object) -> Context {
|
||||
impl Context {
|
||||
pub fn new(db: @mut Database, lg: @mut Logger, cfg: @json::Object)
|
||||
-> Context {
|
||||
Context {
|
||||
db: db,
|
||||
logger: lg,
|
||||
@ -270,12 +271,12 @@ pub impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn prep<T:Owned +
|
||||
Encodable<json::Encoder> +
|
||||
Decodable<json::Decoder>>( // FIXME(#5121)
|
||||
@self,
|
||||
fn_name:&str,
|
||||
blk: &fn(@mut Prep)->Work<T>) -> Work<T> {
|
||||
pub fn prep<T:Owned +
|
||||
Encodable<json::Encoder> +
|
||||
Decodable<json::Decoder>>(@self, // FIXME(#5121)
|
||||
fn_name:&str,
|
||||
blk: &fn(@mut Prep)->Work<T>)
|
||||
-> Work<T> {
|
||||
let p = @mut Prep {
|
||||
ctxt: self,
|
||||
fn_name: fn_name.to_owned(),
|
||||
@ -363,10 +364,10 @@ impl TPrep for Prep {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Owned +
|
||||
Encodable<json::Encoder> +
|
||||
Decodable<json::Decoder>> Work<T> { // FIXME(#5121)
|
||||
fn new(p: @mut Prep, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
|
||||
impl<T:Owned +
|
||||
Encodable<json::Encoder> +
|
||||
Decodable<json::Decoder>> Work<T> { // FIXME(#5121)
|
||||
pub fn new(p: @mut Prep, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> {
|
||||
Work { prep: p, res: Some(e) }
|
||||
}
|
||||
}
|
||||
|
@ -188,112 +188,116 @@ pub struct Session_ {
|
||||
|
||||
pub type Session = @Session_;
|
||||
|
||||
pub impl Session_ {
|
||||
fn span_fatal(@self, sp: span, msg: &str) -> ! {
|
||||
impl Session_ {
|
||||
pub fn span_fatal(@self, sp: span, msg: &str) -> ! {
|
||||
self.span_diagnostic.span_fatal(sp, msg)
|
||||
}
|
||||
fn fatal(@self, msg: &str) -> ! {
|
||||
pub fn fatal(@self, msg: &str) -> ! {
|
||||
self.span_diagnostic.handler().fatal(msg)
|
||||
}
|
||||
fn span_err(@self, sp: span, msg: &str) {
|
||||
pub fn span_err(@self, sp: span, msg: &str) {
|
||||
self.span_diagnostic.span_err(sp, msg)
|
||||
}
|
||||
fn err(@self, msg: &str) {
|
||||
pub fn err(@self, msg: &str) {
|
||||
self.span_diagnostic.handler().err(msg)
|
||||
}
|
||||
fn err_count(@self) -> uint {
|
||||
pub fn err_count(@self) -> uint {
|
||||
self.span_diagnostic.handler().err_count()
|
||||
}
|
||||
fn has_errors(@self) -> bool {
|
||||
pub fn has_errors(@self) -> bool {
|
||||
self.span_diagnostic.handler().has_errors()
|
||||
}
|
||||
fn abort_if_errors(@self) {
|
||||
pub fn abort_if_errors(@self) {
|
||||
self.span_diagnostic.handler().abort_if_errors()
|
||||
}
|
||||
fn span_warn(@self, sp: span, msg: &str) {
|
||||
pub fn span_warn(@self, sp: span, msg: &str) {
|
||||
self.span_diagnostic.span_warn(sp, msg)
|
||||
}
|
||||
fn warn(@self, msg: &str) {
|
||||
pub fn warn(@self, msg: &str) {
|
||||
self.span_diagnostic.handler().warn(msg)
|
||||
}
|
||||
fn span_note(@self, sp: span, msg: &str) {
|
||||
pub fn span_note(@self, sp: span, msg: &str) {
|
||||
self.span_diagnostic.span_note(sp, msg)
|
||||
}
|
||||
fn note(@self, msg: &str) {
|
||||
pub fn note(@self, msg: &str) {
|
||||
self.span_diagnostic.handler().note(msg)
|
||||
}
|
||||
fn span_bug(@self, sp: span, msg: &str) -> ! {
|
||||
pub fn span_bug(@self, sp: span, msg: &str) -> ! {
|
||||
self.span_diagnostic.span_bug(sp, msg)
|
||||
}
|
||||
fn bug(@self, msg: &str) -> ! {
|
||||
pub fn bug(@self, msg: &str) -> ! {
|
||||
self.span_diagnostic.handler().bug(msg)
|
||||
}
|
||||
fn span_unimpl(@self, sp: span, msg: &str) -> ! {
|
||||
pub fn span_unimpl(@self, sp: span, msg: &str) -> ! {
|
||||
self.span_diagnostic.span_unimpl(sp, msg)
|
||||
}
|
||||
fn unimpl(@self, msg: &str) -> ! {
|
||||
pub fn unimpl(@self, msg: &str) -> ! {
|
||||
self.span_diagnostic.handler().unimpl(msg)
|
||||
}
|
||||
fn add_lint(@self, lint: lint::lint, id: ast::node_id, sp: span, msg: ~str) {
|
||||
pub fn add_lint(@self,
|
||||
lint: lint::lint,
|
||||
id: ast::node_id,
|
||||
sp: span,
|
||||
msg: ~str) {
|
||||
match self.lints.find_mut(&id) {
|
||||
Some(arr) => { arr.push((lint, sp, msg)); return; }
|
||||
None => {}
|
||||
}
|
||||
self.lints.insert(id, ~[(lint, sp, msg)]);
|
||||
}
|
||||
fn next_node_id(@self) -> ast::node_id {
|
||||
pub fn next_node_id(@self) -> ast::node_id {
|
||||
return syntax::parse::next_node_id(self.parse_sess);
|
||||
}
|
||||
fn diagnostic(@self) -> @diagnostic::span_handler {
|
||||
pub fn diagnostic(@self) -> @diagnostic::span_handler {
|
||||
self.span_diagnostic
|
||||
}
|
||||
fn debugging_opt(@self, opt: uint) -> bool {
|
||||
pub fn debugging_opt(@self, opt: uint) -> bool {
|
||||
(self.opts.debugging_opts & opt) != 0u
|
||||
}
|
||||
// This exists to help with refactoring to eliminate impossible
|
||||
// cases later on
|
||||
fn impossible_case(@self, sp: span, msg: &str) -> ! {
|
||||
pub fn impossible_case(@self, sp: span, msg: &str) -> ! {
|
||||
self.span_bug(sp, fmt!("Impossible case reached: %s", msg));
|
||||
}
|
||||
fn verbose(@self) -> bool { self.debugging_opt(verbose) }
|
||||
fn time_passes(@self) -> bool { self.debugging_opt(time_passes) }
|
||||
fn count_llvm_insns(@self) -> bool {
|
||||
pub fn verbose(@self) -> bool { self.debugging_opt(verbose) }
|
||||
pub fn time_passes(@self) -> bool { self.debugging_opt(time_passes) }
|
||||
pub fn count_llvm_insns(@self) -> bool {
|
||||
self.debugging_opt(count_llvm_insns)
|
||||
}
|
||||
fn count_type_sizes(@self) -> bool {
|
||||
pub fn count_type_sizes(@self) -> bool {
|
||||
self.debugging_opt(count_type_sizes)
|
||||
}
|
||||
fn time_llvm_passes(@self) -> bool {
|
||||
pub fn time_llvm_passes(@self) -> bool {
|
||||
self.debugging_opt(time_llvm_passes)
|
||||
}
|
||||
fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) }
|
||||
fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) }
|
||||
fn asm_comments(@self) -> bool { self.debugging_opt(asm_comments) }
|
||||
fn no_verify(@self) -> bool { self.debugging_opt(no_verify) }
|
||||
fn lint_llvm(@self) -> bool { self.debugging_opt(lint_llvm) }
|
||||
fn trace(@self) -> bool { self.debugging_opt(trace) }
|
||||
fn coherence(@self) -> bool { self.debugging_opt(coherence) }
|
||||
fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) }
|
||||
fn borrowck_note_pure(@self) -> bool {
|
||||
pub fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) }
|
||||
pub fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) }
|
||||
pub fn asm_comments(@self) -> bool { self.debugging_opt(asm_comments) }
|
||||
pub fn no_verify(@self) -> bool { self.debugging_opt(no_verify) }
|
||||
pub fn lint_llvm(@self) -> bool { self.debugging_opt(lint_llvm) }
|
||||
pub fn trace(@self) -> bool { self.debugging_opt(trace) }
|
||||
pub fn coherence(@self) -> bool { self.debugging_opt(coherence) }
|
||||
pub fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) }
|
||||
pub fn borrowck_note_pure(@self) -> bool {
|
||||
self.debugging_opt(borrowck_note_pure)
|
||||
}
|
||||
fn borrowck_note_loan(@self) -> bool {
|
||||
pub fn borrowck_note_loan(@self) -> bool {
|
||||
self.debugging_opt(borrowck_note_loan)
|
||||
}
|
||||
fn no_monomorphic_collapse(@self) -> bool {
|
||||
pub fn no_monomorphic_collapse(@self) -> bool {
|
||||
self.debugging_opt(no_monomorphic_collapse)
|
||||
}
|
||||
fn debug_borrows(@self) -> bool {
|
||||
pub fn debug_borrows(@self) -> bool {
|
||||
self.opts.optimize == No && !self.debugging_opt(no_debug_borrows)
|
||||
}
|
||||
|
||||
fn str_of(@self, id: ast::ident) -> @~str {
|
||||
pub fn str_of(@self, id: ast::ident) -> @~str {
|
||||
self.parse_sess.interner.get(id)
|
||||
}
|
||||
fn ident_of(@self, st: &str) -> ast::ident {
|
||||
pub fn ident_of(@self, st: &str) -> ast::ident {
|
||||
self.parse_sess.interner.intern(st)
|
||||
}
|
||||
fn intr(@self) -> @syntax::parse::token::ident_interner {
|
||||
pub fn intr(@self) -> @syntax::parse::token::ident_interner {
|
||||
self.parse_sess.interner
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ fn reserve_id_range(sess: Session,
|
||||
ast_util::id_range { min: to_id_min, max: to_id_min }
|
||||
}
|
||||
|
||||
pub impl ExtendedDecodeContext {
|
||||
fn tr_id(&self, id: ast::node_id) -> ast::node_id {
|
||||
impl ExtendedDecodeContext {
|
||||
pub fn tr_id(&self, id: ast::node_id) -> ast::node_id {
|
||||
/*!
|
||||
* Translates an internal id, meaning a node id that is known
|
||||
* to refer to some part of the item currently being inlined,
|
||||
@ -179,7 +179,7 @@ pub impl ExtendedDecodeContext {
|
||||
assert!(!self.from_id_range.empty());
|
||||
(id - self.from_id_range.min + self.to_id_range.min)
|
||||
}
|
||||
fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
|
||||
pub fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
|
||||
/*!
|
||||
* Translates an EXTERNAL def-id, converting the crate number
|
||||
* from the one used in the encoded data to the current crate
|
||||
@ -203,7 +203,7 @@ pub impl ExtendedDecodeContext {
|
||||
|
||||
decoder::translate_def_id(self.dcx.cdata, did)
|
||||
}
|
||||
fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id {
|
||||
pub fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id {
|
||||
/*!
|
||||
* Translates an INTERNAL def-id, meaning a def-id that is
|
||||
* known to refer to some part of the item currently being
|
||||
@ -214,7 +214,7 @@ pub impl ExtendedDecodeContext {
|
||||
assert_eq!(did.crate, ast::local_crate);
|
||||
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
|
||||
}
|
||||
fn tr_span(&self, _span: span) -> span {
|
||||
pub fn tr_span(&self, _span: span) -> span {
|
||||
codemap::dummy_sp() // FIXME (#1972): handle span properly
|
||||
}
|
||||
}
|
||||
|
@ -69,13 +69,13 @@ enum MoveError {
|
||||
MoveWhileBorrowed(/*move*/@LoanPath, /*loan*/@LoanPath, /*loan*/span)
|
||||
}
|
||||
|
||||
pub impl<'self> CheckLoanCtxt<'self> {
|
||||
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
impl<'self> CheckLoanCtxt<'self> {
|
||||
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn each_issued_loan(&self,
|
||||
scope_id: ast::node_id,
|
||||
op: &fn(&Loan) -> bool) -> bool
|
||||
{
|
||||
pub fn each_issued_loan(&self,
|
||||
scope_id: ast::node_id,
|
||||
op: &fn(&Loan) -> bool)
|
||||
-> bool {
|
||||
//! Iterates over each loan that that has been issued
|
||||
//! on entrance to `scope_id`, regardless of whether it is
|
||||
//! actually *in scope* at that point. Sometimes loans
|
||||
@ -91,10 +91,10 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn each_in_scope_loan(&self,
|
||||
scope_id: ast::node_id,
|
||||
op: &fn(&Loan) -> bool) -> bool
|
||||
{
|
||||
pub fn each_in_scope_loan(&self,
|
||||
scope_id: ast::node_id,
|
||||
op: &fn(&Loan) -> bool)
|
||||
-> bool {
|
||||
//! Like `each_issued_loan()`, but only considers loans that are
|
||||
//! currently in scope.
|
||||
|
||||
@ -109,11 +109,11 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn each_in_scope_restriction(&self,
|
||||
scope_id: ast::node_id,
|
||||
loan_path: @LoanPath,
|
||||
op: &fn(&Loan, &Restriction) -> bool) -> bool
|
||||
{
|
||||
pub fn each_in_scope_restriction(&self,
|
||||
scope_id: ast::node_id,
|
||||
loan_path: @LoanPath,
|
||||
op: &fn(&Loan, &Restriction) -> bool)
|
||||
-> bool {
|
||||
//! Iterates through all the in-scope restrictions for the
|
||||
//! given `loan_path`
|
||||
|
||||
@ -129,7 +129,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn loans_generated_by(&self, scope_id: ast::node_id) -> ~[uint] {
|
||||
pub fn loans_generated_by(&self, scope_id: ast::node_id) -> ~[uint] {
|
||||
//! Returns a vector of the loans that are generated as
|
||||
//! we encounter `scope_id`.
|
||||
|
||||
@ -140,7 +140,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) {
|
||||
pub fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) {
|
||||
//! Checks to see whether any of the loans that are issued
|
||||
//! by `scope_id` conflict with loans that have already been
|
||||
//! issued when we enter `scope_id` (for example, we do not
|
||||
@ -167,9 +167,9 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_error_if_loans_conflict(&self,
|
||||
old_loan: &Loan,
|
||||
new_loan: &Loan) {
|
||||
pub fn report_error_if_loans_conflict(&self,
|
||||
old_loan: &Loan,
|
||||
new_loan: &Loan) {
|
||||
//! Checks whether `old_loan` and `new_loan` can safely be issued
|
||||
//! simultaneously.
|
||||
|
||||
@ -188,11 +188,12 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
new_loan, old_loan, old_loan, new_loan);
|
||||
}
|
||||
|
||||
fn report_error_if_loan_conflicts_with_restriction(&self,
|
||||
loan1: &Loan,
|
||||
loan2: &Loan,
|
||||
old_loan: &Loan,
|
||||
new_loan: &Loan) -> bool {
|
||||
pub fn report_error_if_loan_conflicts_with_restriction(&self,
|
||||
loan1: &Loan,
|
||||
loan2: &Loan,
|
||||
old_loan: &Loan,
|
||||
new_loan: &Loan)
|
||||
-> bool {
|
||||
//! Checks whether the restrictions introduced by `loan1` would
|
||||
//! prohibit `loan2`. Returns false if an error is reported.
|
||||
|
||||
@ -247,18 +248,18 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_local_variable(&self, cmt: mc::cmt) -> bool {
|
||||
pub fn is_local_variable(&self, cmt: mc::cmt) -> bool {
|
||||
match cmt.cat {
|
||||
mc::cat_local(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn check_if_path_is_moved(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
use_kind: MovedValueUseKind,
|
||||
lp: @LoanPath) {
|
||||
pub fn check_if_path_is_moved(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
use_kind: MovedValueUseKind,
|
||||
lp: @LoanPath) {
|
||||
/*!
|
||||
* Reports an error if `expr` (which should be a path)
|
||||
* is using a moved/uninitialized value
|
||||
@ -277,7 +278,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_assignment(&self, expr: @ast::expr) {
|
||||
pub fn check_assignment(&self, expr: @ast::expr) {
|
||||
// We don't use cat_expr() here because we don't want to treat
|
||||
// auto-ref'd parameters in overloaded operators as rvalues.
|
||||
let cmt = match self.bccx.tcx.adjustments.find(&expr.id) {
|
||||
@ -533,10 +534,10 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_illegal_mutation(&self,
|
||||
expr: @ast::expr,
|
||||
loan_path: &LoanPath,
|
||||
loan: &Loan) {
|
||||
pub fn report_illegal_mutation(&self,
|
||||
expr: @ast::expr,
|
||||
loan_path: &LoanPath,
|
||||
loan: &Loan) {
|
||||
self.bccx.span_err(
|
||||
expr.span,
|
||||
fmt!("cannot assign to `%s` because it is borrowed",
|
||||
@ -547,7 +548,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
self.bccx.loan_path_to_str(loan_path)));
|
||||
}
|
||||
|
||||
fn check_move_out_from_expr(&self, ex: @ast::expr) {
|
||||
pub fn check_move_out_from_expr(&self, ex: @ast::expr) {
|
||||
match ex.node {
|
||||
ast::expr_paren(*) => {
|
||||
/* In the case of an expr_paren(), the expression inside
|
||||
@ -574,7 +575,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn analyze_move_out_from_cmt(&self, cmt: mc::cmt) -> MoveError {
|
||||
pub fn analyze_move_out_from_cmt(&self, cmt: mc::cmt) -> MoveError {
|
||||
debug!("analyze_move_out_from_cmt(cmt=%s)", cmt.repr(self.tcx()));
|
||||
|
||||
// FIXME(#4384) inadequare if/when we permit `move a.b`
|
||||
@ -590,13 +591,12 @@ pub impl<'self> CheckLoanCtxt<'self> {
|
||||
return MoveOk;
|
||||
}
|
||||
|
||||
fn check_call(&mut self,
|
||||
_expr: @ast::expr,
|
||||
_callee: Option<@ast::expr>,
|
||||
_callee_id: ast::node_id,
|
||||
_callee_span: span,
|
||||
_args: &[@ast::expr])
|
||||
{
|
||||
pub fn check_call(&mut self,
|
||||
_expr: @ast::expr,
|
||||
_callee: Option<@ast::expr>,
|
||||
_callee_id: ast::node_id,
|
||||
_callee_span: span,
|
||||
_args: &[@ast::expr]) {
|
||||
// NB: This call to check for conflicting loans is not truly
|
||||
// necessary, because the callee_id never issues new loans.
|
||||
// However, I added it for consistency and lest the system
|
||||
|
@ -273,21 +273,21 @@ fn gather_loans_in_expr(ex: @ast::expr,
|
||||
}
|
||||
}
|
||||
|
||||
pub impl GatherLoanCtxt {
|
||||
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
impl GatherLoanCtxt {
|
||||
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
|
||||
|
||||
fn push_repeating_id(&mut self, id: ast::node_id) {
|
||||
pub fn push_repeating_id(&mut self, id: ast::node_id) {
|
||||
self.repeating_ids.push(id);
|
||||
}
|
||||
|
||||
fn pop_repeating_id(&mut self, id: ast::node_id) {
|
||||
pub fn pop_repeating_id(&mut self, id: ast::node_id) {
|
||||
let popped = self.repeating_ids.pop();
|
||||
assert_eq!(id, popped);
|
||||
}
|
||||
|
||||
fn guarantee_adjustments(&mut self,
|
||||
expr: @ast::expr,
|
||||
adjustment: &ty::AutoAdjustment) {
|
||||
pub fn guarantee_adjustments(&mut self,
|
||||
expr: @ast::expr,
|
||||
adjustment: &ty::AutoAdjustment) {
|
||||
debug!("guarantee_adjustments(expr=%s, adjustment=%?)",
|
||||
expr.repr(self.tcx()), adjustment);
|
||||
let _i = indenter();
|
||||
@ -350,13 +350,12 @@ pub impl GatherLoanCtxt {
|
||||
// out loans, which will be added to the `req_loan_map`. This can
|
||||
// also entail "rooting" GC'd pointers, which means ensuring
|
||||
// dynamically that they are not freed.
|
||||
fn guarantee_valid(&mut self,
|
||||
borrow_id: ast::node_id,
|
||||
borrow_span: span,
|
||||
cmt: mc::cmt,
|
||||
req_mutbl: ast::mutability,
|
||||
loan_region: ty::Region)
|
||||
{
|
||||
pub fn guarantee_valid(&mut self,
|
||||
borrow_id: ast::node_id,
|
||||
borrow_span: span,
|
||||
cmt: mc::cmt,
|
||||
req_mutbl: ast::mutability,
|
||||
loan_region: ty::Region) {
|
||||
debug!("guarantee_valid(borrow_id=%?, cmt=%s, \
|
||||
req_mutbl=%?, loan_region=%?)",
|
||||
borrow_id,
|
||||
@ -514,7 +513,8 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn restriction_set(&self, req_mutbl: ast::mutability) -> RestrictionSet {
|
||||
pub fn restriction_set(&self, req_mutbl: ast::mutability)
|
||||
-> RestrictionSet {
|
||||
match req_mutbl {
|
||||
m_const => RESTR_EMPTY,
|
||||
m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM,
|
||||
@ -522,7 +522,7 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_loan_path_as_mutated(&self, loan_path: @LoanPath) {
|
||||
pub fn mark_loan_path_as_mutated(&self, loan_path: @LoanPath) {
|
||||
//! For mutable loans of content whose mutability derives
|
||||
//! from a local variable, mark the mutability decl as necessary.
|
||||
|
||||
@ -540,9 +540,10 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_gen_scope(&self,
|
||||
borrow_id: ast::node_id,
|
||||
loan_scope: ast::node_id) -> ast::node_id {
|
||||
pub fn compute_gen_scope(&self,
|
||||
borrow_id: ast::node_id,
|
||||
loan_scope: ast::node_id)
|
||||
-> ast::node_id {
|
||||
//! Determine when to introduce the loan. Typically the loan
|
||||
//! is introduced at the point of the borrow, but in some cases,
|
||||
//! notably method arguments, the loan may be introduced only
|
||||
@ -556,9 +557,8 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_kill_scope(&self,
|
||||
loan_scope: ast::node_id,
|
||||
lp: @LoanPath) -> ast::node_id {
|
||||
pub fn compute_kill_scope(&self, loan_scope: ast::node_id, lp: @LoanPath)
|
||||
-> ast::node_id {
|
||||
//! Determine when the loan restrictions go out of scope.
|
||||
//! This is either when the lifetime expires or when the
|
||||
//! local variable which roots the loan-path goes out of scope,
|
||||
@ -588,11 +588,11 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn gather_pat(&mut self,
|
||||
discr_cmt: mc::cmt,
|
||||
root_pat: @ast::pat,
|
||||
arm_body_id: ast::node_id,
|
||||
match_id: ast::node_id) {
|
||||
pub fn gather_pat(&mut self,
|
||||
discr_cmt: mc::cmt,
|
||||
root_pat: @ast::pat,
|
||||
arm_body_id: ast::node_id,
|
||||
match_id: ast::node_id) {
|
||||
do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| {
|
||||
match pat.node {
|
||||
ast::pat_ident(bm, _, _) if self.pat_is_binding(pat) => {
|
||||
@ -653,9 +653,8 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn vec_slice_info(&self,
|
||||
pat: @ast::pat,
|
||||
slice_ty: ty::t) -> (ast::mutability, ty::Region) {
|
||||
pub fn vec_slice_info(&self, pat: @ast::pat, slice_ty: ty::t)
|
||||
-> (ast::mutability, ty::Region) {
|
||||
/*!
|
||||
*
|
||||
* In a pattern like [a, b, ..c], normally `c` has slice type,
|
||||
@ -681,11 +680,11 @@ pub impl GatherLoanCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn pat_is_variant_or_struct(&self, pat: @ast::pat) -> bool {
|
||||
pub fn pat_is_variant_or_struct(&self, pat: @ast::pat) -> bool {
|
||||
pat_util::pat_is_variant_or_struct(self.bccx.tcx.def_map, pat)
|
||||
}
|
||||
|
||||
fn pat_is_binding(&self, pat: @ast::pat) -> bool {
|
||||
pub fn pat_is_binding(&self, pat: @ast::pat) -> bool {
|
||||
pat_util::pat_is_binding(self.bccx.tcx.def_map, pat)
|
||||
}
|
||||
}
|
||||
|
@ -248,8 +248,8 @@ pub enum LoanPathElem {
|
||||
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs
|
||||
}
|
||||
|
||||
pub impl LoanPath {
|
||||
fn node_id(&self) -> ast::node_id {
|
||||
impl LoanPath {
|
||||
pub fn node_id(&self) -> ast::node_id {
|
||||
match *self {
|
||||
LpVar(local_id) => local_id,
|
||||
LpExtend(base, _, _) => base.node_id()
|
||||
@ -327,12 +327,12 @@ pub static RESTR_CLAIM: RestrictionSet = RestrictionSet {bits: 0b0010};
|
||||
pub static RESTR_FREEZE: RestrictionSet = RestrictionSet {bits: 0b0100};
|
||||
pub static RESTR_ALIAS: RestrictionSet = RestrictionSet {bits: 0b1000};
|
||||
|
||||
pub impl RestrictionSet {
|
||||
fn intersects(&self, restr: RestrictionSet) -> bool {
|
||||
impl RestrictionSet {
|
||||
pub fn intersects(&self, restr: RestrictionSet) -> bool {
|
||||
(self.bits & restr.bits) != 0
|
||||
}
|
||||
|
||||
fn contains_all(&self, restr: RestrictionSet) -> bool {
|
||||
pub fn contains_all(&self, restr: RestrictionSet) -> bool {
|
||||
(self.bits & restr.bits) == restr.bits
|
||||
}
|
||||
}
|
||||
@ -427,29 +427,33 @@ pub enum MovedValueUseKind {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Misc
|
||||
|
||||
pub impl BorrowckCtxt {
|
||||
fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region) -> bool {
|
||||
impl BorrowckCtxt {
|
||||
pub fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region)
|
||||
-> bool {
|
||||
self.tcx.region_maps.is_subregion_of(r_sub, r_sup)
|
||||
}
|
||||
|
||||
fn is_subscope_of(&self, r_sub: ast::node_id, r_sup: ast::node_id) -> bool {
|
||||
pub fn is_subscope_of(&self, r_sub: ast::node_id, r_sup: ast::node_id)
|
||||
-> bool {
|
||||
self.tcx.region_maps.is_subscope_of(r_sub, r_sup)
|
||||
}
|
||||
|
||||
fn is_move(&self, id: ast::node_id) -> bool {
|
||||
pub fn is_move(&self, id: ast::node_id) -> bool {
|
||||
self.moves_map.contains(&id)
|
||||
}
|
||||
|
||||
fn cat_expr(&self, expr: @ast::expr) -> mc::cmt {
|
||||
pub fn cat_expr(&self, expr: @ast::expr) -> mc::cmt {
|
||||
mc::cat_expr(self.tcx, self.method_map, expr)
|
||||
}
|
||||
|
||||
fn cat_expr_unadjusted(&self, expr: @ast::expr) -> mc::cmt {
|
||||
pub fn cat_expr_unadjusted(&self, expr: @ast::expr) -> mc::cmt {
|
||||
mc::cat_expr_unadjusted(self.tcx, self.method_map, expr)
|
||||
}
|
||||
|
||||
fn cat_expr_autoderefd(&self, expr: @ast::expr,
|
||||
adj: @ty::AutoAdjustment) -> mc::cmt {
|
||||
pub fn cat_expr_autoderefd(&self,
|
||||
expr: @ast::expr,
|
||||
adj: @ty::AutoAdjustment)
|
||||
-> mc::cmt {
|
||||
match *adj {
|
||||
ty::AutoAddEnv(*) => {
|
||||
// no autoderefs
|
||||
@ -465,46 +469,47 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_def(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
ty: ty::t,
|
||||
def: ast::def) -> mc::cmt {
|
||||
pub fn cat_def(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
ty: ty::t,
|
||||
def: ast::def)
|
||||
-> mc::cmt {
|
||||
mc::cat_def(self.tcx, self.method_map, id, span, ty, def)
|
||||
}
|
||||
|
||||
fn cat_discr(&self, cmt: mc::cmt, match_id: ast::node_id) -> mc::cmt {
|
||||
pub fn cat_discr(&self, cmt: mc::cmt, match_id: ast::node_id) -> mc::cmt {
|
||||
@mc::cmt_ {cat:mc::cat_discr(cmt, match_id),
|
||||
mutbl:cmt.mutbl.inherit(),
|
||||
..*cmt}
|
||||
}
|
||||
|
||||
fn mc_ctxt(&self) -> mc::mem_categorization_ctxt {
|
||||
pub fn mc_ctxt(&self) -> mc::mem_categorization_ctxt {
|
||||
mc::mem_categorization_ctxt {tcx: self.tcx,
|
||||
method_map: self.method_map}
|
||||
}
|
||||
|
||||
fn cat_pattern(&self,
|
||||
cmt: mc::cmt,
|
||||
pat: @ast::pat,
|
||||
op: &fn(mc::cmt, @ast::pat)) {
|
||||
pub fn cat_pattern(&self,
|
||||
cmt: mc::cmt,
|
||||
pat: @ast::pat,
|
||||
op: &fn(mc::cmt, @ast::pat)) {
|
||||
let mc = self.mc_ctxt();
|
||||
mc.cat_pattern(cmt, pat, op);
|
||||
}
|
||||
|
||||
fn report(&self, err: BckError) {
|
||||
pub fn report(&self, err: BckError) {
|
||||
self.span_err(
|
||||
err.span,
|
||||
self.bckerr_to_str(err));
|
||||
self.note_and_explain_bckerr(err);
|
||||
}
|
||||
|
||||
fn report_use_of_moved_value(&self,
|
||||
use_span: span,
|
||||
use_kind: MovedValueUseKind,
|
||||
lp: @LoanPath,
|
||||
move: &move_data::Move,
|
||||
moved_lp: @LoanPath) {
|
||||
pub fn report_use_of_moved_value(&self,
|
||||
use_span: span,
|
||||
use_kind: MovedValueUseKind,
|
||||
lp: @LoanPath,
|
||||
move: &move_data::Move,
|
||||
moved_lp: @LoanPath) {
|
||||
let verb = match use_kind {
|
||||
MovedInUse => "use",
|
||||
MovedInCapture => "capture",
|
||||
@ -563,10 +568,11 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_reassigned_immutable_variable(&self,
|
||||
span: span,
|
||||
lp: @LoanPath,
|
||||
assign: &move_data::Assignment) {
|
||||
pub fn report_reassigned_immutable_variable(&self,
|
||||
span: span,
|
||||
lp: @LoanPath,
|
||||
assign:
|
||||
&move_data::Assignment) {
|
||||
self.tcx.sess.span_err(
|
||||
span,
|
||||
fmt!("re-assignment of immutable variable `%s`",
|
||||
@ -576,15 +582,15 @@ pub impl BorrowckCtxt {
|
||||
fmt!("prior assignment occurs here"));
|
||||
}
|
||||
|
||||
fn span_err(&self, s: span, m: &str) {
|
||||
pub fn span_err(&self, s: span, m: &str) {
|
||||
self.tcx.sess.span_err(s, m);
|
||||
}
|
||||
|
||||
fn span_note(&self, s: span, m: &str) {
|
||||
pub fn span_note(&self, s: span, m: &str) {
|
||||
self.tcx.sess.span_note(s, m);
|
||||
}
|
||||
|
||||
fn bckerr_to_str(&self, err: BckError) -> ~str {
|
||||
pub fn bckerr_to_str(&self, err: BckError) -> ~str {
|
||||
match err.code {
|
||||
err_mutbl(lk) => {
|
||||
fmt!("cannot borrow %s %s as %s",
|
||||
@ -608,10 +614,10 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_aliasability_violation(&self,
|
||||
span: span,
|
||||
kind: AliasableViolationKind,
|
||||
cause: mc::AliasableReason) {
|
||||
pub fn report_aliasability_violation(&self,
|
||||
span: span,
|
||||
kind: AliasableViolationKind,
|
||||
cause: mc::AliasableReason) {
|
||||
let prefix = match kind {
|
||||
MutabilityViolation => "cannot assign to an `&mut`",
|
||||
BorrowViolation => "cannot borrow an `&mut`"
|
||||
@ -649,7 +655,7 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn note_and_explain_bckerr(&self, err: BckError) {
|
||||
pub fn note_and_explain_bckerr(&self, err: BckError) {
|
||||
let code = err.code;
|
||||
match code {
|
||||
err_mutbl(*) | err_freeze_aliasable_const(*) => {}
|
||||
@ -682,9 +688,9 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn append_loan_path_to_str_from_interior(&self,
|
||||
loan_path: &LoanPath,
|
||||
out: &mut ~str) {
|
||||
pub fn append_loan_path_to_str_from_interior(&self,
|
||||
loan_path: &LoanPath,
|
||||
out: &mut ~str) {
|
||||
match *loan_path {
|
||||
LpExtend(_, _, LpDeref) => {
|
||||
str::push_char(out, '(');
|
||||
@ -698,7 +704,9 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn append_loan_path_to_str(&self, loan_path: &LoanPath, out: &mut ~str) {
|
||||
pub fn append_loan_path_to_str(&self,
|
||||
loan_path: &LoanPath,
|
||||
out: &mut ~str) {
|
||||
match *loan_path {
|
||||
LpVar(id) => {
|
||||
match self.tcx.items.find(&id) {
|
||||
@ -739,25 +747,25 @@ pub impl BorrowckCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn loan_path_to_str(&self, loan_path: &LoanPath) -> ~str {
|
||||
pub fn loan_path_to_str(&self, loan_path: &LoanPath) -> ~str {
|
||||
let mut result = ~"";
|
||||
self.append_loan_path_to_str(loan_path, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
fn cmt_to_str(&self, cmt: mc::cmt) -> ~str {
|
||||
pub fn cmt_to_str(&self, cmt: mc::cmt) -> ~str {
|
||||
let mc = &mc::mem_categorization_ctxt {tcx: self.tcx,
|
||||
method_map: self.method_map};
|
||||
mc.cmt_to_str(cmt)
|
||||
}
|
||||
|
||||
fn mut_to_str(&self, mutbl: ast::mutability) -> ~str {
|
||||
pub fn mut_to_str(&self, mutbl: ast::mutability) -> ~str {
|
||||
let mc = &mc::mem_categorization_ctxt {tcx: self.tcx,
|
||||
method_map: self.method_map};
|
||||
mc.mut_to_str(mutbl)
|
||||
}
|
||||
|
||||
fn mut_to_keyword(&self, mutbl: ast::mutability) -> &'static str {
|
||||
pub fn mut_to_keyword(&self, mutbl: ast::mutability) -> &'static str {
|
||||
match mutbl {
|
||||
ast::m_imm => "",
|
||||
ast::m_const => "const",
|
||||
|
@ -82,14 +82,14 @@ pub struct LanguageItems {
|
||||
items: [Option<def_id>, ..38]
|
||||
}
|
||||
|
||||
pub impl LanguageItems {
|
||||
impl LanguageItems {
|
||||
pub fn new() -> LanguageItems {
|
||||
LanguageItems {
|
||||
items: [ None, ..38 ]
|
||||
}
|
||||
}
|
||||
|
||||
fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool {
|
||||
pub fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool {
|
||||
self.items.eachi(|i, &item| f(item.get(), i))
|
||||
}
|
||||
|
||||
@ -331,9 +331,10 @@ struct LanguageItemCollector {
|
||||
item_refs: HashMap<@~str, uint>,
|
||||
}
|
||||
|
||||
pub impl LanguageItemCollector {
|
||||
fn match_and_collect_meta_item(&mut self, item_def_id: def_id,
|
||||
meta_item: @meta_item) {
|
||||
impl LanguageItemCollector {
|
||||
pub fn match_and_collect_meta_item(&mut self,
|
||||
item_def_id: def_id,
|
||||
meta_item: @meta_item) {
|
||||
match meta_item.node {
|
||||
meta_name_value(key, literal) => {
|
||||
match literal.node {
|
||||
@ -347,7 +348,7 @@ pub impl LanguageItemCollector {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_item(&mut self, item_index: uint, item_def_id: def_id) {
|
||||
pub fn collect_item(&mut self, item_index: uint, item_def_id: def_id) {
|
||||
// Check for duplicates.
|
||||
match self.items.items[item_index] {
|
||||
Some(original_def_id) if original_def_id != item_def_id => {
|
||||
@ -363,8 +364,10 @@ pub impl LanguageItemCollector {
|
||||
self.items.items[item_index] = Some(item_def_id);
|
||||
}
|
||||
|
||||
fn match_and_collect_item(&mut self,
|
||||
item_def_id: def_id, key: @~str, value: @~str) {
|
||||
pub fn match_and_collect_item(&mut self,
|
||||
item_def_id: def_id,
|
||||
key: @~str,
|
||||
value: @~str) {
|
||||
if *key != ~"lang" {
|
||||
return; // Didn't match.
|
||||
}
|
||||
@ -384,7 +387,7 @@ pub impl LanguageItemCollector {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_local_language_items(&mut self) {
|
||||
pub fn collect_local_language_items(&mut self) {
|
||||
let this: *mut LanguageItemCollector = &mut *self;
|
||||
visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor {
|
||||
visit_item: |item| {
|
||||
@ -401,7 +404,7 @@ pub impl LanguageItemCollector {
|
||||
}));
|
||||
}
|
||||
|
||||
fn collect_external_language_items(&mut self) {
|
||||
pub fn collect_external_language_items(&mut self) {
|
||||
let crate_store = self.session.cstore;
|
||||
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
|
||||
for each_lang_item(crate_store, crate_number)
|
||||
@ -412,7 +415,7 @@ pub impl LanguageItemCollector {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_completeness(&self) {
|
||||
pub fn check_completeness(&self) {
|
||||
for self.item_refs.each |&key, &item_ref| {
|
||||
match self.items.items[item_ref] {
|
||||
None => {
|
||||
@ -425,7 +428,7 @@ pub impl LanguageItemCollector {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect(&mut self) {
|
||||
pub fn collect(&mut self) {
|
||||
self.collect_local_language_items();
|
||||
self.collect_external_language_items();
|
||||
self.check_completeness();
|
||||
|
@ -197,8 +197,10 @@ impl to_str::ToStr for Variable {
|
||||
// variable must not be assigned if there is some successor
|
||||
// assignment. And so forth.
|
||||
|
||||
pub impl LiveNode {
|
||||
fn is_valid(&self) -> bool { **self != uint::max_value }
|
||||
impl LiveNode {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
**self != uint::max_value
|
||||
}
|
||||
}
|
||||
|
||||
fn invalid_node() -> LiveNode { LiveNode(uint::max_value) }
|
||||
@ -260,8 +262,8 @@ fn IrMaps(tcx: ty::ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
pub impl IrMaps {
|
||||
fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode {
|
||||
impl IrMaps {
|
||||
pub fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode {
|
||||
let ln = LiveNode(self.num_live_nodes);
|
||||
self.lnks.push(lnk);
|
||||
self.num_live_nodes += 1;
|
||||
@ -272,16 +274,16 @@ pub impl IrMaps {
|
||||
ln
|
||||
}
|
||||
|
||||
fn add_live_node_for_node(&mut self,
|
||||
node_id: node_id,
|
||||
lnk: LiveNodeKind) {
|
||||
pub fn add_live_node_for_node(&mut self,
|
||||
node_id: node_id,
|
||||
lnk: LiveNodeKind) {
|
||||
let ln = self.add_live_node(lnk);
|
||||
self.live_node_map.insert(node_id, ln);
|
||||
|
||||
debug!("%s is node %d", ln.to_str(), node_id);
|
||||
}
|
||||
|
||||
fn add_variable(&mut self, vk: VarKind) -> Variable {
|
||||
pub fn add_variable(&mut self, vk: VarKind) -> Variable {
|
||||
let v = Variable(self.num_vars);
|
||||
self.var_kinds.push(vk);
|
||||
self.num_vars += 1;
|
||||
@ -298,7 +300,7 @@ pub impl IrMaps {
|
||||
v
|
||||
}
|
||||
|
||||
fn variable(&mut self, node_id: node_id, span: span) -> Variable {
|
||||
pub fn variable(&mut self, node_id: node_id, span: span) -> Variable {
|
||||
match self.variable_map.find(&node_id) {
|
||||
Some(&var) => var,
|
||||
None => {
|
||||
@ -308,7 +310,7 @@ pub impl IrMaps {
|
||||
}
|
||||
}
|
||||
|
||||
fn variable_name(&mut self, var: Variable) -> @~str {
|
||||
pub fn variable_name(&mut self, var: Variable) -> @~str {
|
||||
match self.var_kinds[*var] {
|
||||
Local(LocalInfo { ident: nm, _ }) | Arg(_, nm) => {
|
||||
self.tcx.sess.str_of(nm)
|
||||
@ -317,11 +319,11 @@ pub impl IrMaps {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_captures(&mut self, node_id: node_id, cs: ~[CaptureInfo]) {
|
||||
pub fn set_captures(&mut self, node_id: node_id, cs: ~[CaptureInfo]) {
|
||||
self.capture_info_map.insert(node_id, @cs);
|
||||
}
|
||||
|
||||
fn captures(&mut self, expr: @expr) -> @~[CaptureInfo] {
|
||||
pub fn captures(&mut self, expr: @expr) -> @~[CaptureInfo] {
|
||||
match self.capture_info_map.find(&expr.id) {
|
||||
Some(&caps) => caps,
|
||||
None => {
|
||||
@ -330,7 +332,7 @@ pub impl IrMaps {
|
||||
}
|
||||
}
|
||||
|
||||
fn lnk(&mut self, ln: LiveNode) -> LiveNodeKind {
|
||||
pub fn lnk(&mut self, ln: LiveNode) -> LiveNodeKind {
|
||||
self.lnks[*ln]
|
||||
}
|
||||
}
|
||||
@ -578,8 +580,8 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Liveness {
|
||||
fn live_node(&self, node_id: node_id, span: span) -> LiveNode {
|
||||
impl Liveness {
|
||||
pub fn live_node(&self, node_id: node_id, span: span) -> LiveNode {
|
||||
let ir: &mut IrMaps = self.ir;
|
||||
match ir.live_node_map.find(&node_id) {
|
||||
Some(&ln) => ln,
|
||||
@ -595,7 +597,7 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
|
||||
pub fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
|
||||
match expr.node {
|
||||
expr_path(_) => {
|
||||
let def = self.tcx.def_map.get_copy(&expr.id);
|
||||
@ -607,12 +609,12 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn variable(&self, node_id: node_id, span: span) -> Variable {
|
||||
pub fn variable(&self, node_id: node_id, span: span) -> Variable {
|
||||
self.ir.variable(node_id, span)
|
||||
}
|
||||
|
||||
fn variable_from_def_map(&self, node_id: node_id,
|
||||
span: span) -> Option<Variable> {
|
||||
pub fn variable_from_def_map(&self, node_id: node_id, span: span)
|
||||
-> Option<Variable> {
|
||||
match self.tcx.def_map.find(&node_id) {
|
||||
Some(&def) => {
|
||||
moves::moved_variable_node_id_from_def(def).map(
|
||||
@ -626,8 +628,9 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn pat_bindings(&self, pat: @pat,
|
||||
f: &fn(LiveNode, Variable, span, node_id)) {
|
||||
pub fn pat_bindings(&self,
|
||||
pat: @pat,
|
||||
f: &fn(LiveNode, Variable, span, node_id)) {
|
||||
let def_map = self.tcx.def_map;
|
||||
do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| {
|
||||
let ln = self.live_node(p_id, sp);
|
||||
@ -636,9 +639,9 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn arm_pats_bindings(&self,
|
||||
pats: &[@pat],
|
||||
f: &fn(LiveNode, Variable, span, node_id)) {
|
||||
pub fn arm_pats_bindings(&self,
|
||||
pats: &[@pat],
|
||||
f: &fn(LiveNode, Variable, span, node_id)) {
|
||||
// only consider the first pattern; any later patterns must have
|
||||
// the same bindings, and we also consider the first pattern to be
|
||||
// the "authoratative" set of ids
|
||||
@ -647,12 +650,13 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn define_bindings_in_pat(&self, pat: @pat, succ: LiveNode) -> LiveNode {
|
||||
pub fn define_bindings_in_pat(&self, pat: @pat, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
self.define_bindings_in_arm_pats([pat], succ)
|
||||
}
|
||||
|
||||
fn define_bindings_in_arm_pats(&self, pats: &[@pat],
|
||||
succ: LiveNode) -> LiveNode {
|
||||
pub fn define_bindings_in_arm_pats(&self, pats: &[@pat], succ: LiveNode)
|
||||
-> LiveNode {
|
||||
let mut succ = succ;
|
||||
do self.arm_pats_bindings(pats) |ln, var, _sp, _id| {
|
||||
self.init_from_succ(ln, succ);
|
||||
@ -662,13 +666,12 @@ pub impl Liveness {
|
||||
succ
|
||||
}
|
||||
|
||||
fn idx(&self, ln: LiveNode, var: Variable) -> uint {
|
||||
pub fn idx(&self, ln: LiveNode, var: Variable) -> uint {
|
||||
*ln * self.ir.num_vars + *var
|
||||
}
|
||||
|
||||
fn live_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
pub fn live_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
assert!(ln.is_valid());
|
||||
let reader = self.users[self.idx(ln, var)].reader;
|
||||
if reader.is_valid() {Some(self.ir.lnk(reader))} else {None}
|
||||
@ -677,39 +680,39 @@ pub impl Liveness {
|
||||
/*
|
||||
Is this variable live on entry to any of its successor nodes?
|
||||
*/
|
||||
fn live_on_exit(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
pub fn live_on_exit(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
self.live_on_entry(copy self.successors[*ln], var)
|
||||
}
|
||||
|
||||
fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
|
||||
pub fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
|
||||
assert!(ln.is_valid());
|
||||
self.users[self.idx(ln, var)].used
|
||||
}
|
||||
|
||||
fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
pub fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
assert!(ln.is_valid());
|
||||
let writer = self.users[self.idx(ln, var)].writer;
|
||||
if writer.is_valid() {Some(self.ir.lnk(writer))} else {None}
|
||||
}
|
||||
|
||||
fn assigned_on_exit(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
pub fn assigned_on_exit(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
self.assigned_on_entry(copy self.successors[*ln], var)
|
||||
}
|
||||
|
||||
fn indices(&self, ln: LiveNode, op: &fn(uint)) {
|
||||
pub fn indices(&self, ln: LiveNode, op: &fn(uint)) {
|
||||
let node_base_idx = self.idx(ln, Variable(0));
|
||||
for uint::range(0, self.ir.num_vars) |var_idx| {
|
||||
op(node_base_idx + var_idx)
|
||||
}
|
||||
}
|
||||
|
||||
fn indices2(&self, ln: LiveNode, succ_ln: LiveNode, op: &fn(uint, uint)) {
|
||||
pub fn indices2(&self,
|
||||
ln: LiveNode,
|
||||
succ_ln: LiveNode,
|
||||
op: &fn(uint, uint)) {
|
||||
let node_base_idx = self.idx(ln, Variable(0u));
|
||||
let succ_base_idx = self.idx(succ_ln, Variable(0u));
|
||||
for uint::range(0u, self.ir.num_vars) |var_idx| {
|
||||
@ -717,10 +720,10 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_vars(&self,
|
||||
wr: @io::Writer,
|
||||
ln: LiveNode,
|
||||
test: &fn(uint) -> LiveNode) {
|
||||
pub fn write_vars(&self,
|
||||
wr: @io::Writer,
|
||||
ln: LiveNode,
|
||||
test: &fn(uint) -> LiveNode) {
|
||||
let node_base_idx = self.idx(ln, Variable(0));
|
||||
for uint::range(0, self.ir.num_vars) |var_idx| {
|
||||
let idx = node_base_idx + var_idx;
|
||||
@ -731,8 +734,11 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_loop_scope(&self, opt_label: Option<ident>, id: node_id, sp: span)
|
||||
-> node_id {
|
||||
pub fn find_loop_scope(&self,
|
||||
opt_label: Option<ident>,
|
||||
id: node_id,
|
||||
sp: span)
|
||||
-> node_id {
|
||||
match opt_label {
|
||||
Some(_) => // Refers to a labeled loop. Use the results of resolve
|
||||
// to find with one
|
||||
@ -758,12 +764,12 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn last_loop_scope(&self) -> node_id {
|
||||
pub fn last_loop_scope(&self) -> node_id {
|
||||
let loop_scope = &mut *self.loop_scope;
|
||||
*loop_scope.last()
|
||||
}
|
||||
|
||||
fn ln_str(&self, ln: LiveNode) -> ~str {
|
||||
pub fn ln_str(&self, ln: LiveNode) -> ~str {
|
||||
do io::with_str_writer |wr| {
|
||||
wr.write_str("[ln(");
|
||||
wr.write_uint(*ln);
|
||||
@ -780,7 +786,7 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
pub fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
self.successors[*ln] = succ_ln;
|
||||
|
||||
// It is not necessary to initialize the
|
||||
@ -793,7 +799,7 @@ pub impl Liveness {
|
||||
// }
|
||||
}
|
||||
|
||||
fn init_from_succ(&self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
pub fn init_from_succ(&self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
// more efficient version of init_empty() / merge_from_succ()
|
||||
self.successors[*ln] = succ_ln;
|
||||
self.indices2(ln, succ_ln, |idx, succ_idx| {
|
||||
@ -803,8 +809,11 @@ pub impl Liveness {
|
||||
self.ln_str(ln), self.ln_str(succ_ln));
|
||||
}
|
||||
|
||||
fn merge_from_succ(&self, ln: LiveNode, succ_ln: LiveNode,
|
||||
first_merge: bool) -> bool {
|
||||
pub fn merge_from_succ(&self,
|
||||
ln: LiveNode,
|
||||
succ_ln: LiveNode,
|
||||
first_merge: bool)
|
||||
-> bool {
|
||||
if ln == succ_ln { return false; }
|
||||
|
||||
let mut changed = false;
|
||||
@ -838,7 +847,7 @@ pub impl Liveness {
|
||||
// Indicates that a local variable was *defined*; we know that no
|
||||
// uses of the variable can precede the definition (resolve checks
|
||||
// this) so we just clear out all the data.
|
||||
fn define(&self, writer: LiveNode, var: Variable) {
|
||||
pub fn define(&self, writer: LiveNode, var: Variable) {
|
||||
let idx = self.idx(writer, var);
|
||||
self.users[idx].reader = invalid_node();
|
||||
self.users[idx].writer = invalid_node();
|
||||
@ -848,7 +857,7 @@ pub impl Liveness {
|
||||
}
|
||||
|
||||
// Either read, write, or both depending on the acc bitset
|
||||
fn acc(&self, ln: LiveNode, var: Variable, acc: uint) {
|
||||
pub fn acc(&self, ln: LiveNode, var: Variable, acc: uint) {
|
||||
let idx = self.idx(ln, var);
|
||||
let users = &mut *self.users;
|
||||
let user = &mut users[idx];
|
||||
@ -874,7 +883,7 @@ pub impl Liveness {
|
||||
|
||||
// _______________________________________________________________________
|
||||
|
||||
fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode {
|
||||
pub fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode {
|
||||
// if there is a `break` or `again` at the top level, then it's
|
||||
// effectively a return---this only occurs in `for` loops,
|
||||
// where the body is really a closure.
|
||||
@ -899,8 +908,8 @@ pub impl Liveness {
|
||||
entry_ln
|
||||
}
|
||||
|
||||
fn propagate_through_fn_block(&self, _: &fn_decl, blk: &blk)
|
||||
-> LiveNode {
|
||||
pub fn propagate_through_fn_block(&self, _: &fn_decl, blk: &blk)
|
||||
-> LiveNode {
|
||||
// the fallthrough exit is only for those cases where we do not
|
||||
// explicitly return:
|
||||
self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln);
|
||||
@ -911,15 +920,16 @@ pub impl Liveness {
|
||||
self.propagate_through_block(blk, self.s.fallthrough_ln)
|
||||
}
|
||||
|
||||
fn propagate_through_block(&self, blk: &blk, succ: LiveNode) -> LiveNode {
|
||||
pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
let succ = self.propagate_through_opt_expr(blk.node.expr, succ);
|
||||
do blk.node.stmts.foldr(succ) |stmt, succ| {
|
||||
self.propagate_through_stmt(*stmt, succ)
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
pub fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
match stmt.node {
|
||||
stmt_decl(decl, _) => {
|
||||
return self.propagate_through_decl(decl, succ);
|
||||
@ -935,8 +945,8 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
match decl.node {
|
||||
decl_local(ref locals) => {
|
||||
do locals.foldr(succ) |local, succ| {
|
||||
@ -949,8 +959,8 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_local(&self, local: @local, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
pub fn propagate_through_local(&self, local: @local, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
// Note: we mark the variable as defined regardless of whether
|
||||
// there is an initializer. Initially I had thought to only mark
|
||||
// the live variable as defined if it was initialized, and then we
|
||||
@ -969,22 +979,24 @@ pub impl Liveness {
|
||||
self.define_bindings_in_pat(local.node.pat, succ)
|
||||
}
|
||||
|
||||
fn propagate_through_exprs(&self, exprs: &[@expr],
|
||||
succ: LiveNode) -> LiveNode {
|
||||
pub fn propagate_through_exprs(&self, exprs: &[@expr], succ: LiveNode)
|
||||
-> LiveNode {
|
||||
do exprs.foldr(succ) |expr, succ| {
|
||||
self.propagate_through_expr(*expr, succ)
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_opt_expr(&self, opt_expr: Option<@expr>,
|
||||
succ: LiveNode) -> LiveNode {
|
||||
pub fn propagate_through_opt_expr(&self,
|
||||
opt_expr: Option<@expr>,
|
||||
succ: LiveNode)
|
||||
-> LiveNode {
|
||||
do old_iter::foldl(&opt_expr, succ) |succ, expr| {
|
||||
self.propagate_through_expr(*expr, *succ)
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_expr(&self, expr: @expr, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
pub fn propagate_through_expr(&self, expr: @expr, succ: LiveNode)
|
||||
-> LiveNode {
|
||||
debug!("propagate_through_expr: %s",
|
||||
expr_to_str(expr, self.tcx.sess.intr()));
|
||||
|
||||
@ -1230,8 +1242,10 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_lvalue_components(&self, expr: @expr,
|
||||
succ: LiveNode) -> LiveNode {
|
||||
pub fn propagate_through_lvalue_components(&self,
|
||||
expr: @expr,
|
||||
succ: LiveNode)
|
||||
-> LiveNode {
|
||||
// # Lvalues
|
||||
//
|
||||
// In general, the full flow graph structure for an
|
||||
@ -1289,9 +1303,8 @@ pub impl Liveness {
|
||||
}
|
||||
|
||||
// see comment on propagate_through_lvalue()
|
||||
fn write_lvalue(&self, expr: @expr,
|
||||
succ: LiveNode,
|
||||
acc: uint) -> LiveNode {
|
||||
pub fn write_lvalue(&self, expr: @expr, succ: LiveNode, acc: uint)
|
||||
-> LiveNode {
|
||||
match expr.node {
|
||||
expr_path(_) => self.access_path(expr, succ, acc),
|
||||
|
||||
@ -1303,8 +1316,8 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
|
||||
-> LiveNode {
|
||||
pub fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
|
||||
-> LiveNode {
|
||||
let def = self.tcx.def_map.get_copy(&expr.id);
|
||||
match moves::moved_variable_node_id_from_def(def) {
|
||||
Some(nid) => {
|
||||
@ -1320,10 +1333,12 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn propagate_through_loop(&self, expr: @expr,
|
||||
cond: Option<@expr>,
|
||||
body: &blk,
|
||||
succ: LiveNode) -> LiveNode {
|
||||
pub fn propagate_through_loop(&self,
|
||||
expr: @expr,
|
||||
cond: Option<@expr>,
|
||||
body: &blk,
|
||||
succ: LiveNode)
|
||||
-> LiveNode {
|
||||
|
||||
/*
|
||||
|
||||
@ -1377,10 +1392,12 @@ pub impl Liveness {
|
||||
cond_ln
|
||||
}
|
||||
|
||||
fn with_loop_nodes<R>(&self, loop_node_id: node_id,
|
||||
break_ln: LiveNode,
|
||||
cont_ln: LiveNode,
|
||||
f: &fn() -> R) -> R {
|
||||
pub fn with_loop_nodes<R>(&self,
|
||||
loop_node_id: node_id,
|
||||
break_ln: LiveNode,
|
||||
cont_ln: LiveNode,
|
||||
f: &fn() -> R)
|
||||
-> R {
|
||||
debug!("with_loop_nodes: %d %u", loop_node_id, *break_ln);
|
||||
self.loop_scope.push(loop_node_id);
|
||||
self.break_ln.insert(loop_node_id, break_ln);
|
||||
@ -1491,9 +1508,12 @@ enum ReadKind {
|
||||
PartiallyMovedValue
|
||||
}
|
||||
|
||||
pub impl Liveness {
|
||||
fn check_ret(&self, id: node_id, sp: span, _fk: &visit::fn_kind,
|
||||
entry_ln: LiveNode) {
|
||||
impl Liveness {
|
||||
pub fn check_ret(&self,
|
||||
id: node_id,
|
||||
sp: span,
|
||||
_fk: &visit::fn_kind,
|
||||
entry_ln: LiveNode) {
|
||||
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
|
||||
// if no_ret_var is live, then we fall off the end of the
|
||||
// function without any kind of return expression:
|
||||
@ -1512,7 +1532,7 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) {
|
||||
pub fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) {
|
||||
match expr.node {
|
||||
expr_path(_) => {
|
||||
match self.tcx.def_map.get_copy(&expr.id) {
|
||||
@ -1546,11 +1566,11 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_illegal_read(&self,
|
||||
chk_span: span,
|
||||
lnk: LiveNodeKind,
|
||||
var: Variable,
|
||||
rk: ReadKind) {
|
||||
pub fn report_illegal_read(&self,
|
||||
chk_span: span,
|
||||
lnk: LiveNodeKind,
|
||||
var: Variable,
|
||||
rk: ReadKind) {
|
||||
let msg = match rk {
|
||||
PossiblyUninitializedVariable => "possibly uninitialized \
|
||||
variable",
|
||||
@ -1578,12 +1598,12 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn should_warn(&self, var: Variable) -> Option<@~str> {
|
||||
pub fn should_warn(&self, var: Variable) -> Option<@~str> {
|
||||
let name = self.ir.variable_name(var);
|
||||
if name[0] == ('_' as u8) { None } else { Some(name) }
|
||||
}
|
||||
|
||||
fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) {
|
||||
pub fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) {
|
||||
for decl.inputs.each |arg| {
|
||||
do pat_util::pat_bindings(self.tcx.def_map, arg.pat)
|
||||
|_bm, p_id, sp, _n| {
|
||||
@ -1593,7 +1613,7 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) {
|
||||
pub fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) {
|
||||
do self.pat_bindings(pat) |ln, var, sp, id| {
|
||||
if !self.warn_about_unused(sp, id, ln, var) {
|
||||
self.warn_about_dead_assign(sp, id, ln, var);
|
||||
@ -1601,8 +1621,12 @@ pub impl Liveness {
|
||||
}
|
||||
}
|
||||
|
||||
fn warn_about_unused(&self, sp: span, id: node_id,
|
||||
ln: LiveNode, var: Variable) -> bool {
|
||||
pub fn warn_about_unused(&self,
|
||||
sp: span,
|
||||
id: node_id,
|
||||
ln: LiveNode,
|
||||
var: Variable)
|
||||
-> bool {
|
||||
if !self.used_on_entry(ln, var) {
|
||||
for self.should_warn(var).each |name| {
|
||||
|
||||
@ -1629,8 +1653,11 @@ pub impl Liveness {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn warn_about_dead_assign(&self, sp: span, id: node_id,
|
||||
ln: LiveNode, var: Variable) {
|
||||
pub fn warn_about_dead_assign(&self,
|
||||
sp: span,
|
||||
id: node_id,
|
||||
ln: LiveNode,
|
||||
var: Variable) {
|
||||
if self.live_on_exit(ln, var).is_none() {
|
||||
for self.should_warn(var).each |name| {
|
||||
self.tcx.sess.add_lint(dead_assignment, id, sp,
|
||||
|
@ -290,8 +290,8 @@ impl ToStr for MutabilityCategory {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl MutabilityCategory {
|
||||
fn from_mutbl(m: ast::mutability) -> MutabilityCategory {
|
||||
impl MutabilityCategory {
|
||||
pub fn from_mutbl(m: ast::mutability) -> MutabilityCategory {
|
||||
match m {
|
||||
m_imm => McImmutable,
|
||||
m_const => McReadOnly,
|
||||
@ -299,7 +299,7 @@ pub impl MutabilityCategory {
|
||||
}
|
||||
}
|
||||
|
||||
fn inherit(&self) -> MutabilityCategory {
|
||||
pub fn inherit(&self) -> MutabilityCategory {
|
||||
match *self {
|
||||
McImmutable => McImmutable,
|
||||
McReadOnly => McReadOnly,
|
||||
@ -308,21 +308,21 @@ pub impl MutabilityCategory {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_mutable(&self) -> bool {
|
||||
pub fn is_mutable(&self) -> bool {
|
||||
match *self {
|
||||
McImmutable | McReadOnly => false,
|
||||
McDeclared | McInherited => true
|
||||
}
|
||||
}
|
||||
|
||||
fn is_immutable(&self) -> bool {
|
||||
pub fn is_immutable(&self) -> bool {
|
||||
match *self {
|
||||
McImmutable => true,
|
||||
McReadOnly | McDeclared | McInherited => false
|
||||
}
|
||||
}
|
||||
|
||||
fn to_user_str(&self) -> &'static str {
|
||||
pub fn to_user_str(&self) -> &'static str {
|
||||
match *self {
|
||||
McDeclared | McInherited => "mutable",
|
||||
McImmutable => "immutable",
|
||||
@ -331,16 +331,16 @@ pub impl MutabilityCategory {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl mem_categorization_ctxt {
|
||||
fn expr_ty(&self, expr: @ast::expr) -> ty::t {
|
||||
impl mem_categorization_ctxt {
|
||||
pub fn expr_ty(&self, expr: @ast::expr) -> ty::t {
|
||||
ty::expr_ty(self.tcx, expr)
|
||||
}
|
||||
|
||||
fn pat_ty(&self, pat: @ast::pat) -> ty::t {
|
||||
pub fn pat_ty(&self, pat: @ast::pat) -> ty::t {
|
||||
ty::node_id_to_type(self.tcx, pat.id)
|
||||
}
|
||||
|
||||
fn cat_expr(&self, expr: @ast::expr) -> cmt {
|
||||
pub fn cat_expr(&self, expr: @ast::expr) -> cmt {
|
||||
match self.tcx.adjustments.find(&expr.id) {
|
||||
None => {
|
||||
// No adjustments.
|
||||
@ -374,9 +374,8 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_expr_autoderefd(&self,
|
||||
expr: @ast::expr,
|
||||
autoderefs: uint) -> cmt {
|
||||
pub fn cat_expr_autoderefd(&self, expr: @ast::expr, autoderefs: uint)
|
||||
-> cmt {
|
||||
let mut cmt = self.cat_expr_unadjusted(expr);
|
||||
for uint::range(1, autoderefs+1) |deref| {
|
||||
cmt = self.cat_deref(expr, cmt, deref);
|
||||
@ -384,7 +383,7 @@ pub impl mem_categorization_ctxt {
|
||||
return cmt;
|
||||
}
|
||||
|
||||
fn cat_expr_unadjusted(&self, expr: @ast::expr) -> cmt {
|
||||
pub fn cat_expr_unadjusted(&self, expr: @ast::expr) -> cmt {
|
||||
debug!("cat_expr: id=%d expr=%s",
|
||||
expr.id, pprust::expr_to_str(expr, self.tcx.sess.intr()));
|
||||
|
||||
@ -440,11 +439,12 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_def(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
expr_ty: ty::t,
|
||||
def: ast::def) -> cmt {
|
||||
pub fn cat_def(&self,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
expr_ty: ty::t,
|
||||
def: ast::def)
|
||||
-> cmt {
|
||||
match def {
|
||||
ast::def_fn(*) | ast::def_static_method(*) | ast::def_mod(_) |
|
||||
ast::def_foreign_mod(_) | ast::def_const(_) |
|
||||
@ -557,7 +557,7 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_rvalue<N:ast_node>(&self, elt: N, expr_ty: ty::t) -> cmt {
|
||||
pub fn cat_rvalue<N:ast_node>(&self, elt: N, expr_ty: ty::t) -> cmt {
|
||||
@cmt_ {
|
||||
id:elt.id(),
|
||||
span:elt.span(),
|
||||
@ -571,10 +571,10 @@ pub impl mem_categorization_ctxt {
|
||||
/// component is inherited from the base it is a part of. For
|
||||
/// example, a record field is mutable if it is declared mutable
|
||||
/// or if the container is mutable.
|
||||
fn inherited_mutability(&self,
|
||||
base_m: MutabilityCategory,
|
||||
interior_m: ast::mutability) -> MutabilityCategory
|
||||
{
|
||||
pub fn inherited_mutability(&self,
|
||||
base_m: MutabilityCategory,
|
||||
interior_m: ast::mutability)
|
||||
-> MutabilityCategory {
|
||||
match interior_m {
|
||||
m_imm => base_m.inherit(),
|
||||
m_const => McReadOnly,
|
||||
@ -582,11 +582,12 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_field<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
f_name: ast::ident,
|
||||
f_ty: ty::t) -> cmt {
|
||||
pub fn cat_field<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
f_name: ast::ident,
|
||||
f_ty: ty::t)
|
||||
-> cmt {
|
||||
@cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
@ -596,11 +597,11 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_deref_fn<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint) -> cmt
|
||||
{
|
||||
pub fn cat_deref_fn<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint)
|
||||
-> cmt {
|
||||
// Bit of a hack: the "dereference" of a function pointer like
|
||||
// `@fn()` is a mere logical concept. We interpret it as
|
||||
// dereferencing the environment pointer; of course, we don't
|
||||
@ -612,11 +613,11 @@ pub impl mem_categorization_ctxt {
|
||||
return self.cat_deref_common(node, base_cmt, deref_cnt, mt);
|
||||
}
|
||||
|
||||
fn cat_deref<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint) -> cmt
|
||||
{
|
||||
pub fn cat_deref<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint)
|
||||
-> cmt {
|
||||
let mt = match ty::deref(self.tcx, base_cmt.ty, true) {
|
||||
Some(mt) => mt,
|
||||
None => {
|
||||
@ -630,12 +631,12 @@ pub impl mem_categorization_ctxt {
|
||||
return self.cat_deref_common(node, base_cmt, deref_cnt, mt);
|
||||
}
|
||||
|
||||
fn cat_deref_common<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint,
|
||||
mt: ty::mt) -> cmt
|
||||
{
|
||||
pub fn cat_deref_common<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
deref_cnt: uint,
|
||||
mt: ty::mt)
|
||||
-> cmt {
|
||||
match deref_kind(self.tcx, base_cmt.ty) {
|
||||
deref_ptr(ptr) => {
|
||||
// for unique ptrs, we inherit mutability from the
|
||||
@ -671,10 +672,11 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_index<N:ast_node>(&self,
|
||||
elt: N,
|
||||
base_cmt: cmt,
|
||||
derefs: uint) -> cmt {
|
||||
pub fn cat_index<N:ast_node>(&self,
|
||||
elt: N,
|
||||
base_cmt: cmt,
|
||||
derefs: uint)
|
||||
-> cmt {
|
||||
//! Creates a cmt for an indexing operation (`[]`); this
|
||||
//! indexing operation may occurs as part of an
|
||||
//! AutoBorrowVec, which when converting a `~[]` to an `&[]`
|
||||
@ -764,11 +766,12 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_imm_interior<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
interior_ty: ty::t,
|
||||
interior: InteriorKind) -> cmt {
|
||||
pub fn cat_imm_interior<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
interior_ty: ty::t,
|
||||
interior: InteriorKind)
|
||||
-> cmt {
|
||||
@cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
@ -778,10 +781,11 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_downcast<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
downcast_ty: ty::t) -> cmt {
|
||||
pub fn cat_downcast<N:ast_node>(&self,
|
||||
node: N,
|
||||
base_cmt: cmt,
|
||||
downcast_ty: ty::t)
|
||||
-> cmt {
|
||||
@cmt_ {
|
||||
id: node.id(),
|
||||
span: node.span(),
|
||||
@ -791,11 +795,10 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cat_pattern(&self,
|
||||
cmt: cmt,
|
||||
pat: @ast::pat,
|
||||
op: &fn(cmt, @ast::pat))
|
||||
{
|
||||
pub fn cat_pattern(&self,
|
||||
cmt: cmt,
|
||||
pat: @ast::pat,
|
||||
op: &fn(cmt, @ast::pat)) {
|
||||
// Here, `cmt` is the categorization for the value being
|
||||
// matched and pat is the pattern it is being matched against.
|
||||
//
|
||||
@ -961,7 +964,7 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn mut_to_str(&self, mutbl: ast::mutability) -> ~str {
|
||||
pub fn mut_to_str(&self, mutbl: ast::mutability) -> ~str {
|
||||
match mutbl {
|
||||
m_mutbl => ~"mutable",
|
||||
m_const => ~"const",
|
||||
@ -969,7 +972,7 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn cmt_to_str(&self, cmt: cmt) -> ~str {
|
||||
pub fn cmt_to_str(&self, cmt: cmt) -> ~str {
|
||||
match cmt.cat {
|
||||
cat_static_item => {
|
||||
~"static item"
|
||||
@ -1022,7 +1025,7 @@ pub impl mem_categorization_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn region_to_str(&self, r: ty::Region) -> ~str {
|
||||
pub fn region_to_str(&self, r: ty::Region) -> ~str {
|
||||
region_to_str(self.tcx, r)
|
||||
}
|
||||
}
|
||||
@ -1068,8 +1071,8 @@ pub enum AliasableReason {
|
||||
AliasableOther
|
||||
}
|
||||
|
||||
pub impl cmt_ {
|
||||
fn guarantor(@self) -> cmt {
|
||||
impl cmt_ {
|
||||
pub fn guarantor(@self) -> cmt {
|
||||
//! Returns `self` after stripping away any owned pointer derefs or
|
||||
//! interior content. The return value is basically the `cmt` which
|
||||
//! determines how long the value in `self` remains live.
|
||||
@ -1097,11 +1100,11 @@ pub impl cmt_ {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_freely_aliasable(&self) -> bool {
|
||||
pub fn is_freely_aliasable(&self) -> bool {
|
||||
self.freely_aliasable().is_some()
|
||||
}
|
||||
|
||||
fn freely_aliasable(&self) -> Option<AliasableReason> {
|
||||
pub fn freely_aliasable(&self) -> Option<AliasableReason> {
|
||||
//! True if this lvalue resides in an area that is
|
||||
//! freely aliasable, meaning that rustc cannot track
|
||||
//! the alias//es with precision.
|
||||
|
@ -230,20 +230,14 @@ fn compute_modes_for_expr(expr: @expr,
|
||||
cx.consume_expr(expr, v);
|
||||
}
|
||||
|
||||
pub impl VisitContext {
|
||||
fn consume_exprs(&self,
|
||||
exprs: &[@expr],
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
impl VisitContext {
|
||||
pub fn consume_exprs(&self, exprs: &[@expr], visitor: vt<VisitContext>) {
|
||||
for exprs.each |expr| {
|
||||
self.consume_expr(*expr, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
fn consume_expr(&self,
|
||||
expr: @expr,
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
pub fn consume_expr(&self, expr: @expr, visitor: vt<VisitContext>) {
|
||||
/*!
|
||||
* Indicates that the value of `expr` will be consumed,
|
||||
* meaning either copied or moved depending on its type.
|
||||
@ -261,10 +255,7 @@ pub impl VisitContext {
|
||||
};
|
||||
}
|
||||
|
||||
fn consume_block(&self,
|
||||
blk: &blk,
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
pub fn consume_block(&self, blk: &blk, visitor: vt<VisitContext>) {
|
||||
/*!
|
||||
* Indicates that the value of `blk` will be consumed,
|
||||
* meaning either copied or moved depending on its type.
|
||||
@ -281,11 +272,10 @@ pub impl VisitContext {
|
||||
}
|
||||
}
|
||||
|
||||
fn use_expr(&self,
|
||||
expr: @expr,
|
||||
expr_mode: UseMode,
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
pub fn use_expr(&self,
|
||||
expr: @expr,
|
||||
expr_mode: UseMode,
|
||||
visitor: vt<VisitContext>) {
|
||||
/*!
|
||||
* Indicates that `expr` is used with a given mode. This will
|
||||
* in turn trigger calls to the subcomponents of `expr`.
|
||||
@ -529,12 +519,12 @@ pub impl VisitContext {
|
||||
}
|
||||
}
|
||||
|
||||
fn use_overloaded_operator(&self,
|
||||
expr: @expr,
|
||||
receiver_expr: @expr,
|
||||
arg_exprs: &[@expr],
|
||||
visitor: vt<VisitContext>) -> bool
|
||||
{
|
||||
pub fn use_overloaded_operator(&self,
|
||||
expr: @expr,
|
||||
receiver_expr: @expr,
|
||||
arg_exprs: &[@expr],
|
||||
visitor: vt<VisitContext>)
|
||||
-> bool {
|
||||
if !self.method_map.contains_key(&expr.id) {
|
||||
return false;
|
||||
}
|
||||
@ -550,10 +540,7 @@ pub impl VisitContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn consume_arm(&self,
|
||||
arm: &arm,
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
pub fn consume_arm(&self, arm: &arm, visitor: vt<VisitContext>) {
|
||||
for arm.pats.each |pat| {
|
||||
self.use_pat(*pat);
|
||||
}
|
||||
@ -565,9 +552,7 @@ pub impl VisitContext {
|
||||
self.consume_block(&arm.body, visitor);
|
||||
}
|
||||
|
||||
fn use_pat(&self,
|
||||
pat: @pat)
|
||||
{
|
||||
pub fn use_pat(&self, pat: @pat) {
|
||||
/*!
|
||||
*
|
||||
* Decides whether each binding in a pattern moves the value
|
||||
@ -594,32 +579,31 @@ pub impl VisitContext {
|
||||
}
|
||||
}
|
||||
|
||||
fn use_receiver(&self,
|
||||
receiver_expr: @expr,
|
||||
visitor: vt<VisitContext>)
|
||||
{
|
||||
pub fn use_receiver(&self,
|
||||
receiver_expr: @expr,
|
||||
visitor: vt<VisitContext>) {
|
||||
self.use_fn_arg(receiver_expr, visitor);
|
||||
}
|
||||
|
||||
fn use_fn_args(&self,
|
||||
_: node_id,
|
||||
arg_exprs: &[@expr],
|
||||
visitor: vt<VisitContext>) {
|
||||
pub fn use_fn_args(&self,
|
||||
_: node_id,
|
||||
arg_exprs: &[@expr],
|
||||
visitor: vt<VisitContext>) {
|
||||
//! Uses the argument expressions.
|
||||
for arg_exprs.each |arg_expr| {
|
||||
self.use_fn_arg(*arg_expr, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
fn use_fn_arg(&self, arg_expr: @expr, visitor: vt<VisitContext>) {
|
||||
pub fn use_fn_arg(&self, arg_expr: @expr, visitor: vt<VisitContext>) {
|
||||
//! Uses the argument.
|
||||
self.consume_expr(arg_expr, visitor)
|
||||
}
|
||||
|
||||
fn arms_have_by_move_bindings(&self,
|
||||
moves_map: MovesMap,
|
||||
arms: &[arm]) -> Option<@pat>
|
||||
{
|
||||
pub fn arms_have_by_move_bindings(&self,
|
||||
moves_map: MovesMap,
|
||||
arms: &[arm])
|
||||
-> Option<@pat> {
|
||||
for arms.each |arm| {
|
||||
for arm.pats.each |&pat| {
|
||||
for ast_util::walk_pat(pat) |p| {
|
||||
@ -632,7 +616,7 @@ pub impl VisitContext {
|
||||
return None;
|
||||
}
|
||||
|
||||
fn compute_captures(&self, fn_expr_id: node_id) -> @[CaptureVar] {
|
||||
pub fn compute_captures(&self, fn_expr_id: node_id) -> @[CaptureVar] {
|
||||
debug!("compute_capture_vars(fn_expr_id=%?)", fn_expr_id);
|
||||
let _indenter = indenter();
|
||||
|
||||
|
@ -73,11 +73,8 @@ pub struct Context {
|
||||
parent: parent,
|
||||
}
|
||||
|
||||
pub impl RegionMaps {
|
||||
fn relate_free_regions(&mut self,
|
||||
sub: FreeRegion,
|
||||
sup: FreeRegion)
|
||||
{
|
||||
impl RegionMaps {
|
||||
pub fn relate_free_regions(&mut self, sub: FreeRegion, sup: FreeRegion) {
|
||||
match self.free_region_map.find_mut(&sub) {
|
||||
Some(sups) => {
|
||||
if !sups.contains(&sup) {
|
||||
@ -93,19 +90,14 @@ pub impl RegionMaps {
|
||||
self.free_region_map.insert(sub, ~[sup]);
|
||||
}
|
||||
|
||||
fn record_parent(&mut self,
|
||||
sub: ast::node_id,
|
||||
sup: ast::node_id)
|
||||
{
|
||||
pub fn record_parent(&mut self, sub: ast::node_id, sup: ast::node_id) {
|
||||
debug!("record_parent(sub=%?, sup=%?)", sub, sup);
|
||||
assert!(sub != sup);
|
||||
|
||||
self.scope_map.insert(sub, sup);
|
||||
}
|
||||
|
||||
pub fn record_cleanup_scope(&mut self,
|
||||
scope_id: ast::node_id)
|
||||
{
|
||||
pub fn record_cleanup_scope(&mut self, scope_id: ast::node_id) {
|
||||
//! Records that a scope is a CLEANUP SCOPE. This is invoked
|
||||
//! from within regionck. We wait until regionck because we do
|
||||
//! not know which operators are overloaded until that point,
|
||||
@ -114,17 +106,13 @@ pub impl RegionMaps {
|
||||
self.cleanup_scopes.insert(scope_id);
|
||||
}
|
||||
|
||||
fn opt_encl_scope(&self,
|
||||
id: ast::node_id) -> Option<ast::node_id>
|
||||
{
|
||||
pub fn opt_encl_scope(&self, id: ast::node_id) -> Option<ast::node_id> {
|
||||
//! Returns the narrowest scope that encloses `id`, if any.
|
||||
|
||||
self.scope_map.find(&id).map(|&x| *x)
|
||||
}
|
||||
|
||||
fn encl_scope(&self,
|
||||
id: ast::node_id) -> ast::node_id
|
||||
{
|
||||
pub fn encl_scope(&self, id: ast::node_id) -> ast::node_id {
|
||||
//! Returns the narrowest scope that encloses `id`, if any.
|
||||
|
||||
match self.scope_map.find(&id) {
|
||||
@ -133,13 +121,11 @@ pub impl RegionMaps {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_cleanup_scope(&self, scope_id: ast::node_id) -> bool {
|
||||
pub fn is_cleanup_scope(&self, scope_id: ast::node_id) -> bool {
|
||||
self.cleanup_scopes.contains(&scope_id)
|
||||
}
|
||||
|
||||
fn cleanup_scope(&self,
|
||||
expr_id: ast::node_id) -> ast::node_id
|
||||
{
|
||||
pub fn cleanup_scope(&self, expr_id: ast::node_id) -> ast::node_id {
|
||||
//! Returns the scope when temps in expr will be cleaned up
|
||||
|
||||
let mut id = self.encl_scope(expr_id);
|
||||
@ -149,25 +135,22 @@ pub impl RegionMaps {
|
||||
return id;
|
||||
}
|
||||
|
||||
fn encl_region(&self,
|
||||
id: ast::node_id) -> ty::Region
|
||||
{
|
||||
pub fn encl_region(&self, id: ast::node_id) -> ty::Region {
|
||||
//! Returns the narrowest scope region that encloses `id`, if any.
|
||||
|
||||
ty::re_scope(self.encl_scope(id))
|
||||
}
|
||||
|
||||
pub fn scopes_intersect(&self,
|
||||
scope1: ast::node_id,
|
||||
scope2: ast::node_id) -> bool
|
||||
{
|
||||
self.is_subscope_of(scope1, scope2) || self.is_subscope_of(scope2, scope1)
|
||||
pub fn scopes_intersect(&self, scope1: ast::node_id, scope2: ast::node_id)
|
||||
-> bool {
|
||||
self.is_subscope_of(scope1, scope2) ||
|
||||
self.is_subscope_of(scope2, scope1)
|
||||
}
|
||||
|
||||
fn is_subscope_of(&self,
|
||||
subscope: ast::node_id,
|
||||
superscope: ast::node_id) -> bool
|
||||
{
|
||||
pub fn is_subscope_of(&self,
|
||||
subscope: ast::node_id,
|
||||
superscope: ast::node_id)
|
||||
-> bool {
|
||||
/*!
|
||||
* Returns true if `subscope` is equal to or is lexically
|
||||
* nested inside `superscope` and false otherwise.
|
||||
@ -192,10 +175,7 @@ pub impl RegionMaps {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn sub_free_region(&self,
|
||||
sub: FreeRegion,
|
||||
sup: FreeRegion) -> bool
|
||||
{
|
||||
pub fn sub_free_region(&self, sub: FreeRegion, sup: FreeRegion) -> bool {
|
||||
/*!
|
||||
* Determines whether two free regions have a subregion relationship
|
||||
* by walking the graph encoded in `free_region_map`. Note that
|
||||
@ -233,10 +213,10 @@ pub impl RegionMaps {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn is_subregion_of(&self,
|
||||
sub_region: ty::Region,
|
||||
super_region: ty::Region) -> bool
|
||||
{
|
||||
pub fn is_subregion_of(&self,
|
||||
sub_region: ty::Region,
|
||||
super_region: ty::Region)
|
||||
-> bool {
|
||||
/*!
|
||||
* Determines whether one region is a subregion of another. This is
|
||||
* intended to run *after inference* and sadly the logic is somewhat
|
||||
@ -271,10 +251,10 @@ pub impl RegionMaps {
|
||||
}
|
||||
}
|
||||
|
||||
fn nearest_common_ancestor(&self,
|
||||
scope_a: ast::node_id,
|
||||
scope_b: ast::node_id) -> Option<ast::node_id>
|
||||
{
|
||||
pub fn nearest_common_ancestor(&self,
|
||||
scope_a: ast::node_id,
|
||||
scope_b: ast::node_id)
|
||||
-> Option<ast::node_id> {
|
||||
/*!
|
||||
* Finds the nearest common ancestor (if any) of two scopes. That
|
||||
* is, finds the smallest scope which is greater than or equal to
|
||||
@ -588,15 +568,15 @@ pub fn add_variance(ambient_variance: region_variance,
|
||||
}
|
||||
}
|
||||
|
||||
pub impl DetermineRpCtxt {
|
||||
fn add_variance(&self, variance: region_variance) -> region_variance {
|
||||
impl DetermineRpCtxt {
|
||||
pub fn add_variance(&self, variance: region_variance) -> region_variance {
|
||||
add_variance(self.ambient_variance, variance)
|
||||
}
|
||||
|
||||
/// Records that item `id` is region-parameterized with the
|
||||
/// variance `variance`. If `id` was already parameterized, then
|
||||
/// the new variance is joined with the old variance.
|
||||
fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
|
||||
pub fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
|
||||
assert!(id != 0);
|
||||
let old_variance = self.region_paramd_items.find(&id).
|
||||
map_consume(|x| *x);
|
||||
@ -622,7 +602,7 @@ pub impl DetermineRpCtxt {
|
||||
/// `from`. Put another way, it indicates that the current item
|
||||
/// contains a value of type `from`, so if `from` is
|
||||
/// region-parameterized, so is the current item.
|
||||
fn add_dep(&mut self, from: ast::node_id) {
|
||||
pub fn add_dep(&mut self, from: ast::node_id) {
|
||||
debug!("add dependency from %d -> %d (%s -> %s) with variance %?",
|
||||
from, self.item_id,
|
||||
ast_map::node_id_to_str(self.ast_map, from,
|
||||
@ -682,7 +662,7 @@ pub impl DetermineRpCtxt {
|
||||
// with &self type, &self is also bound. We detect those last two
|
||||
// cases via flags (anon_implies_rp and self_implies_rp) that are
|
||||
// true when the anon or self region implies RP.
|
||||
fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool {
|
||||
pub fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool {
|
||||
match r {
|
||||
None => {
|
||||
self.anon_implies_rp
|
||||
@ -699,10 +679,10 @@ pub impl DetermineRpCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn with(@mut self,
|
||||
item_id: ast::node_id,
|
||||
anon_implies_rp: bool,
|
||||
f: &fn()) {
|
||||
pub fn with(@mut self,
|
||||
item_id: ast::node_id,
|
||||
anon_implies_rp: bool,
|
||||
f: &fn()) {
|
||||
let old_item_id = self.item_id;
|
||||
let old_anon_implies_rp = self.anon_implies_rp;
|
||||
self.item_id = item_id;
|
||||
@ -716,7 +696,9 @@ pub impl DetermineRpCtxt {
|
||||
self.anon_implies_rp = old_anon_implies_rp;
|
||||
}
|
||||
|
||||
fn with_ambient_variance(@mut self, variance: region_variance, f: &fn()) {
|
||||
pub fn with_ambient_variance(@mut self,
|
||||
variance: region_variance,
|
||||
f: &fn()) {
|
||||
let old_ambient_variance = self.ambient_variance;
|
||||
self.ambient_variance = self.add_variance(variance);
|
||||
f();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -36,8 +36,8 @@ pub struct FnType {
|
||||
sret: bool
|
||||
}
|
||||
|
||||
pub impl FnType {
|
||||
fn decl_fn(&self, decl: &fn(fnty: TypeRef) -> ValueRef) -> ValueRef {
|
||||
impl FnType {
|
||||
pub fn decl_fn(&self, decl: &fn(fnty: TypeRef) -> ValueRef) -> ValueRef {
|
||||
let atys = vec::map(self.arg_tys, |t| t.ty);
|
||||
let rty = self.ret_ty.ty;
|
||||
let fnty = T_fn(atys, rty);
|
||||
@ -57,9 +57,11 @@ pub impl FnType {
|
||||
return llfn;
|
||||
}
|
||||
|
||||
fn build_shim_args(&self, bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
llargbundle: ValueRef) -> ~[ValueRef] {
|
||||
pub fn build_shim_args(&self,
|
||||
bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
llargbundle: ValueRef)
|
||||
-> ~[ValueRef] {
|
||||
let mut atys: &[LLVMType] = self.arg_tys;
|
||||
let mut attrs: &[option::Option<Attribute>] = self.attrs;
|
||||
|
||||
@ -92,12 +94,12 @@ pub impl FnType {
|
||||
return llargvals;
|
||||
}
|
||||
|
||||
fn build_shim_ret(&self,
|
||||
bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
ret_def: bool,
|
||||
llargbundle: ValueRef,
|
||||
llretval: ValueRef) {
|
||||
pub fn build_shim_ret(&self,
|
||||
bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
ret_def: bool,
|
||||
llargbundle: ValueRef,
|
||||
llretval: ValueRef) {
|
||||
for vec::eachi(self.attrs) |i, a| {
|
||||
match *a {
|
||||
option::Some(attr) => {
|
||||
@ -128,11 +130,11 @@ pub impl FnType {
|
||||
};
|
||||
}
|
||||
|
||||
fn build_wrap_args(&self,
|
||||
bcx: block,
|
||||
ret_ty: TypeRef,
|
||||
llwrapfn: ValueRef,
|
||||
llargbundle: ValueRef) {
|
||||
pub fn build_wrap_args(&self,
|
||||
bcx: block,
|
||||
ret_ty: TypeRef,
|
||||
llwrapfn: ValueRef,
|
||||
llargbundle: ValueRef) {
|
||||
let mut atys: &[LLVMType] = self.arg_tys;
|
||||
let mut attrs: &[option::Option<Attribute>] = self.attrs;
|
||||
let mut j = 0u;
|
||||
@ -167,10 +169,10 @@ pub impl FnType {
|
||||
store_inbounds(bcx, llretptr, llargbundle, [0u, n]);
|
||||
}
|
||||
|
||||
fn build_wrap_ret(&self,
|
||||
bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
llargbundle: ValueRef) {
|
||||
pub fn build_wrap_ret(&self,
|
||||
bcx: block,
|
||||
arg_tys: &[TypeRef],
|
||||
llargbundle: ValueRef) {
|
||||
unsafe {
|
||||
if llvm::LLVMGetTypeKind(self.ret_ty.ty) == Void {
|
||||
return;
|
||||
|
@ -118,8 +118,8 @@ pub struct EnvValue {
|
||||
datum: Datum
|
||||
}
|
||||
|
||||
pub impl EnvAction {
|
||||
fn to_str(&self) -> ~str {
|
||||
impl EnvAction {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
match *self {
|
||||
EnvCopy => ~"EnvCopy",
|
||||
EnvMove => ~"EnvMove",
|
||||
@ -128,8 +128,8 @@ pub impl EnvAction {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl EnvValue {
|
||||
fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
impl EnvValue {
|
||||
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
fmt!("%s(%s)", self.action.to_str(), self.datum.to_str(ccx))
|
||||
}
|
||||
}
|
||||
|
@ -249,8 +249,8 @@ pub struct param_substs {
|
||||
self_ty: Option<ty::t>
|
||||
}
|
||||
|
||||
pub impl param_substs {
|
||||
fn validate(&self) {
|
||||
impl param_substs {
|
||||
pub fn validate(&self) {
|
||||
for self.tys.each |t| { assert!(!ty::type_needs_infer(*t)); }
|
||||
for self.self_ty.each |t| { assert!(!ty::type_needs_infer(*t)); }
|
||||
}
|
||||
@ -353,7 +353,7 @@ pub struct fn_ctxt_ {
|
||||
ccx: @@CrateContext
|
||||
}
|
||||
|
||||
pub impl fn_ctxt_ {
|
||||
impl fn_ctxt_ {
|
||||
pub fn arg_pos(&self, arg: uint) -> uint {
|
||||
if self.has_immediate_return_value {
|
||||
arg + 1u
|
||||
@ -598,8 +598,8 @@ pub struct scope_info {
|
||||
landing_pad: Option<BasicBlockRef>,
|
||||
}
|
||||
|
||||
pub impl scope_info {
|
||||
fn empty_cleanups(&mut self) -> bool {
|
||||
impl scope_info {
|
||||
pub fn empty_cleanups(&mut self) -> bool {
|
||||
self.cleanups.is_empty()
|
||||
}
|
||||
}
|
||||
@ -695,8 +695,8 @@ pub fn rslt(bcx: block, val: ValueRef) -> Result {
|
||||
Result {bcx: bcx, val: val}
|
||||
}
|
||||
|
||||
pub impl Result {
|
||||
fn unpack(&self, bcx: &mut block) -> ValueRef {
|
||||
impl Result {
|
||||
pub fn unpack(&self, bcx: &mut block) -> ValueRef {
|
||||
*bcx = self.bcx;
|
||||
return self.val;
|
||||
}
|
||||
@ -742,28 +742,28 @@ pub fn block_parent(cx: block) -> block {
|
||||
|
||||
// Accessors
|
||||
|
||||
pub impl block_ {
|
||||
fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx }
|
||||
fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx }
|
||||
fn sess(@mut self) -> Session { self.fcx.ccx.sess }
|
||||
impl block_ {
|
||||
pub fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx }
|
||||
pub fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx }
|
||||
pub fn sess(@mut self) -> Session { self.fcx.ccx.sess }
|
||||
|
||||
fn node_id_to_str(@mut self, id: ast::node_id) -> ~str {
|
||||
pub fn node_id_to_str(@mut self, id: ast::node_id) -> ~str {
|
||||
ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr())
|
||||
}
|
||||
|
||||
fn expr_to_str(@mut self, e: @ast::expr) -> ~str {
|
||||
pub fn expr_to_str(@mut self, e: @ast::expr) -> ~str {
|
||||
e.repr(self.tcx())
|
||||
}
|
||||
|
||||
fn expr_is_lval(@mut self, e: @ast::expr) -> bool {
|
||||
pub fn expr_is_lval(@mut self, e: @ast::expr) -> bool {
|
||||
ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e)
|
||||
}
|
||||
|
||||
fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind {
|
||||
pub fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind {
|
||||
ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e)
|
||||
}
|
||||
|
||||
fn def(@mut self, nid: ast::node_id) -> ast::def {
|
||||
pub fn def(@mut self, nid: ast::node_id) -> ast::def {
|
||||
match self.tcx().def_map.find(&nid) {
|
||||
Some(&v) => v,
|
||||
None => {
|
||||
@ -773,18 +773,19 @@ pub impl block_ {
|
||||
}
|
||||
}
|
||||
|
||||
fn val_str(@mut self, val: ValueRef) -> @str {
|
||||
pub fn val_str(@mut self, val: ValueRef) -> @str {
|
||||
val_str(self.ccx().tn, val)
|
||||
}
|
||||
|
||||
fn llty_str(@mut self, llty: TypeRef) -> @str {
|
||||
pub fn llty_str(@mut self, llty: TypeRef) -> @str {
|
||||
ty_str(self.ccx().tn, llty)
|
||||
}
|
||||
|
||||
fn ty_to_str(@mut self, t: ty::t) -> ~str {
|
||||
pub fn ty_to_str(@mut self, t: ty::t) -> ~str {
|
||||
t.repr(self.tcx())
|
||||
}
|
||||
fn to_str(@mut self) -> ~str {
|
||||
|
||||
pub fn to_str(@mut self) -> ~str {
|
||||
unsafe {
|
||||
match self.node_info {
|
||||
Some(node_info) => fmt!("[block %d]", node_info.id),
|
||||
|
@ -145,12 +145,12 @@ pub enum DatumMode {
|
||||
ByValue,
|
||||
}
|
||||
|
||||
pub impl DatumMode {
|
||||
fn is_by_ref(&self) -> bool {
|
||||
impl DatumMode {
|
||||
pub fn is_by_ref(&self) -> bool {
|
||||
match *self { ByRef(_) => true, ByValue => false }
|
||||
}
|
||||
|
||||
fn is_by_value(&self) -> bool {
|
||||
pub fn is_by_value(&self) -> bool {
|
||||
match *self { ByRef(_) => false, ByValue => true }
|
||||
}
|
||||
}
|
||||
@ -205,9 +205,13 @@ pub fn appropriate_mode(ty: ty::t) -> DatumMode {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Datum {
|
||||
fn store_to(&self, bcx: block, id: ast::node_id,
|
||||
action: CopyAction, dst: ValueRef) -> block {
|
||||
impl Datum {
|
||||
pub fn store_to(&self,
|
||||
bcx: block,
|
||||
id: ast::node_id,
|
||||
action: CopyAction,
|
||||
dst: ValueRef)
|
||||
-> block {
|
||||
/*!
|
||||
*
|
||||
* Stores this value into its final home. This moves if
|
||||
@ -221,8 +225,11 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn store_to_dest(&self, bcx: block, id: ast::node_id,
|
||||
dest: expr::Dest) -> block {
|
||||
pub fn store_to_dest(&self,
|
||||
bcx: block,
|
||||
id: ast::node_id,
|
||||
dest: expr::Dest)
|
||||
-> block {
|
||||
match dest {
|
||||
expr::Ignore => {
|
||||
return bcx;
|
||||
@ -233,28 +240,32 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn store_to_datum(&self, bcx: block, id: ast::node_id,
|
||||
action: CopyAction, datum: Datum) -> block {
|
||||
pub fn store_to_datum(&self,
|
||||
bcx: block,
|
||||
id: ast::node_id,
|
||||
action: CopyAction,
|
||||
datum: Datum)
|
||||
-> block {
|
||||
debug!("store_to_datum(self=%s, action=%?, datum=%s)",
|
||||
self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx()));
|
||||
assert!(datum.mode.is_by_ref());
|
||||
self.store_to(bcx, id, action, datum.val)
|
||||
}
|
||||
|
||||
fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
|
||||
-> block {
|
||||
pub fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
|
||||
-> block {
|
||||
assert!(datum.mode.is_by_ref());
|
||||
self.move_to(bcx, action, datum.val)
|
||||
}
|
||||
|
||||
fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
|
||||
-> block {
|
||||
pub fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum)
|
||||
-> block {
|
||||
assert!(datum.mode.is_by_ref());
|
||||
self.copy_to(bcx, action, datum.val)
|
||||
}
|
||||
|
||||
fn copy_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
|
||||
-> block {
|
||||
pub fn copy_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
|
||||
-> block {
|
||||
/*!
|
||||
*
|
||||
* Copies the value into `dst`, which should be a pointer to a
|
||||
@ -296,9 +307,11 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_to_no_check(&self, bcx: block, action: CopyAction,
|
||||
dst: ValueRef) -> block
|
||||
{
|
||||
pub fn copy_to_no_check(&self,
|
||||
bcx: block,
|
||||
action: CopyAction,
|
||||
dst: ValueRef)
|
||||
-> block {
|
||||
/*!
|
||||
*
|
||||
* A helper for `copy_to()` which does not check to see if we
|
||||
@ -326,8 +339,8 @@ pub impl Datum {
|
||||
// This works like copy_val, except that it deinitializes the source.
|
||||
// Since it needs to zero out the source, src also needs to be an lval.
|
||||
//
|
||||
fn move_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
|
||||
-> block {
|
||||
pub fn move_to(&self, bcx: block, action: CopyAction, dst: ValueRef)
|
||||
-> block {
|
||||
let _icx = bcx.insn_ctxt("move_to");
|
||||
let mut bcx = bcx;
|
||||
|
||||
@ -356,7 +369,7 @@ pub impl Datum {
|
||||
return bcx;
|
||||
}
|
||||
|
||||
fn add_clean(&self, bcx: block) {
|
||||
pub fn add_clean(&self, bcx: block) {
|
||||
/*!
|
||||
* Schedules this datum for cleanup in `bcx`. The datum
|
||||
* must be an rvalue.
|
||||
@ -376,7 +389,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel_clean(&self, bcx: block) {
|
||||
pub fn cancel_clean(&self, bcx: block) {
|
||||
if ty::type_needs_drop(bcx.tcx(), self.ty) {
|
||||
match self.mode {
|
||||
ByValue |
|
||||
@ -394,14 +407,14 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_str(&self, ccx: &CrateContext) -> ~str {
|
||||
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
|
||||
fmt!("Datum { val=%s, ty=%s, mode=%? }",
|
||||
val_str(ccx.tn, self.val),
|
||||
ty_to_str(ccx.tcx, self.ty),
|
||||
self.mode)
|
||||
}
|
||||
|
||||
fn to_value_datum(&self, bcx: block) -> Datum {
|
||||
pub fn to_value_datum(&self, bcx: block) -> Datum {
|
||||
/*!
|
||||
*
|
||||
* Yields a by-ref form of this datum. This may involve
|
||||
@ -418,7 +431,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_value_llval(&self, bcx: block) -> ValueRef {
|
||||
pub fn to_value_llval(&self, bcx: block) -> ValueRef {
|
||||
/*!
|
||||
*
|
||||
* Yields the value itself. */
|
||||
@ -439,7 +452,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ref_datum(&self, bcx: block) -> Datum {
|
||||
pub fn to_ref_datum(&self, bcx: block) -> Datum {
|
||||
/*!
|
||||
* Yields a by-ref form of this datum. This may involve
|
||||
* creation of a temporary stack slot. The value returned by
|
||||
@ -456,7 +469,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ref_llval(&self, bcx: block) -> ValueRef {
|
||||
pub fn to_ref_llval(&self, bcx: block) -> ValueRef {
|
||||
match self.mode {
|
||||
ByRef(_) => self.val,
|
||||
ByValue => {
|
||||
@ -471,7 +484,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_zeroable_ref_llval(&self, bcx: block) -> ValueRef {
|
||||
pub fn to_zeroable_ref_llval(&self, bcx: block) -> ValueRef {
|
||||
/*!
|
||||
* Returns a by-ref llvalue that can be zeroed in order to
|
||||
* cancel cleanup. This is a kind of hokey bridge used
|
||||
@ -496,13 +509,13 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn appropriate_mode(&self) -> DatumMode {
|
||||
pub fn appropriate_mode(&self) -> DatumMode {
|
||||
/*! See the `appropriate_mode()` function */
|
||||
|
||||
appropriate_mode(self.ty)
|
||||
}
|
||||
|
||||
fn to_appropriate_llval(&self, bcx: block) -> ValueRef {
|
||||
pub fn to_appropriate_llval(&self, bcx: block) -> ValueRef {
|
||||
/*!
|
||||
*
|
||||
* Yields an llvalue with the `appropriate_mode()`. */
|
||||
@ -513,7 +526,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_appropriate_datum(&self, bcx: block) -> Datum {
|
||||
pub fn to_appropriate_datum(&self, bcx: block) -> Datum {
|
||||
/*!
|
||||
*
|
||||
* Yields a datum with the `appropriate_mode()`. */
|
||||
@ -524,10 +537,12 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_element(&self, bcx: block,
|
||||
ty: ty::t,
|
||||
source: DatumCleanup,
|
||||
gep: &fn(ValueRef) -> ValueRef) -> Datum {
|
||||
pub fn get_element(&self,
|
||||
bcx: block,
|
||||
ty: ty::t,
|
||||
source: DatumCleanup,
|
||||
gep: &fn(ValueRef) -> ValueRef)
|
||||
-> Datum {
|
||||
let base_val = self.to_ref_llval(bcx);
|
||||
Datum {
|
||||
val: gep(base_val),
|
||||
@ -536,7 +551,7 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_val(&self, bcx: block) -> block {
|
||||
pub fn drop_val(&self, bcx: block) -> block {
|
||||
if !ty::type_needs_drop(bcx.tcx(), self.ty) {
|
||||
return bcx;
|
||||
}
|
||||
@ -547,7 +562,7 @@ pub impl Datum {
|
||||
};
|
||||
}
|
||||
|
||||
fn box_body(&self, bcx: block) -> Datum {
|
||||
pub fn box_body(&self, bcx: block) -> Datum {
|
||||
/*!
|
||||
*
|
||||
* This datum must represent an @T or ~T box. Returns a new
|
||||
@ -567,7 +582,7 @@ pub impl Datum {
|
||||
Datum {val: body, ty: content_ty, mode: ByRef(ZeroMem)}
|
||||
}
|
||||
|
||||
fn to_rptr(&self, bcx: block) -> Datum {
|
||||
pub fn to_rptr(&self, bcx: block) -> Datum {
|
||||
//! Returns a new datum of region-pointer type containing the
|
||||
//! the same ptr as this datum (after converting to by-ref
|
||||
//! using `to_ref_llval()`).
|
||||
@ -582,14 +597,18 @@ pub impl Datum {
|
||||
Datum {val: llval, ty: rptr_ty, mode: ByValue}
|
||||
}
|
||||
|
||||
fn try_deref(&self,
|
||||
bcx: block, // block wherein to generate insn's
|
||||
span: span, // location where deref occurs
|
||||
expr_id: ast::node_id, // id of deref expr
|
||||
derefs: uint, // number of times deref'd already
|
||||
is_auto: bool) // if true, only deref if auto-derefable
|
||||
-> (Option<Datum>, block)
|
||||
{
|
||||
/// bcx: Block wherein to generate insns.
|
||||
/// span: Location where deref occurs.
|
||||
/// expr_id: ID of deref expr.
|
||||
/// derefs: Number of times deref'd already.
|
||||
/// is_auto: If true, only deref if auto-derefable.
|
||||
pub fn try_deref(&self,
|
||||
bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
derefs: uint,
|
||||
is_auto: bool)
|
||||
-> (Option<Datum>, block) {
|
||||
let ccx = bcx.ccx();
|
||||
|
||||
debug!("try_deref(expr_id=%?, derefs=%?, is_auto=%b, self=%?)",
|
||||
@ -703,10 +722,9 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn deref(&self, bcx: block,
|
||||
expr: @ast::expr, // the deref expression
|
||||
derefs: uint)
|
||||
-> DatumBlock {
|
||||
/// expr: The deref expression.
|
||||
pub fn deref(&self, bcx: block, expr: @ast::expr, derefs: uint)
|
||||
-> DatumBlock {
|
||||
match self.try_deref(bcx, expr.span, expr.id, derefs, false) {
|
||||
(Some(lvres), bcx) => DatumBlock { bcx: bcx, datum: lvres },
|
||||
(None, _) => {
|
||||
@ -716,11 +734,12 @@ pub impl Datum {
|
||||
}
|
||||
}
|
||||
|
||||
fn autoderef(&self, bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
max: uint)
|
||||
-> DatumBlock {
|
||||
pub fn autoderef(&self,
|
||||
bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
max: uint)
|
||||
-> DatumBlock {
|
||||
let _icx = bcx.insn_ctxt("autoderef");
|
||||
|
||||
debug!("autoderef(expr_id=%d, max=%?, self=%?)",
|
||||
@ -748,12 +767,12 @@ pub impl Datum {
|
||||
DatumBlock { bcx: bcx, datum: datum }
|
||||
}
|
||||
|
||||
fn get_vec_base_and_len(&self,
|
||||
mut bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
derefs: uint)
|
||||
-> (block, ValueRef, ValueRef) {
|
||||
pub fn get_vec_base_and_len(&self,
|
||||
mut bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
derefs: uint)
|
||||
-> (block, ValueRef, ValueRef) {
|
||||
//! Converts a vector into the slice pair. Performs rooting
|
||||
//! and write guards checks.
|
||||
|
||||
@ -763,7 +782,8 @@ pub impl Datum {
|
||||
(bcx, base, len)
|
||||
}
|
||||
|
||||
fn get_vec_base_and_len_no_root(&self, bcx: block) -> (ValueRef, ValueRef) {
|
||||
pub fn get_vec_base_and_len_no_root(&self, bcx: block)
|
||||
-> (ValueRef, ValueRef) {
|
||||
//! Converts a vector into the slice pair. Des not root
|
||||
//! nor perform write guard checks.
|
||||
|
||||
@ -771,64 +791,68 @@ pub impl Datum {
|
||||
tvec::get_base_and_len(bcx, llval, self.ty)
|
||||
}
|
||||
|
||||
fn root_and_write_guard(&self,
|
||||
bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
derefs: uint) -> block {
|
||||
pub fn root_and_write_guard(&self,
|
||||
bcx: block,
|
||||
span: span,
|
||||
expr_id: ast::node_id,
|
||||
derefs: uint)
|
||||
-> block {
|
||||
write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs)
|
||||
}
|
||||
|
||||
fn to_result(&self, bcx: block) -> common::Result {
|
||||
pub fn to_result(&self, bcx: block) -> common::Result {
|
||||
rslt(bcx, self.to_appropriate_llval(bcx))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl DatumBlock {
|
||||
fn unpack(&self, bcx: &mut block) -> Datum {
|
||||
impl DatumBlock {
|
||||
pub fn unpack(&self, bcx: &mut block) -> Datum {
|
||||
*bcx = self.bcx;
|
||||
return self.datum;
|
||||
}
|
||||
|
||||
fn assert_by_ref(&self) -> DatumBlock {
|
||||
pub fn assert_by_ref(&self) -> DatumBlock {
|
||||
assert!(self.datum.mode.is_by_ref());
|
||||
*self
|
||||
}
|
||||
|
||||
fn drop_val(&self) -> block {
|
||||
pub fn drop_val(&self) -> block {
|
||||
self.datum.drop_val(self.bcx)
|
||||
}
|
||||
|
||||
fn store_to(&self, id: ast::node_id, action: CopyAction,
|
||||
dst: ValueRef) -> block {
|
||||
pub fn store_to(&self,
|
||||
id: ast::node_id,
|
||||
action: CopyAction,
|
||||
dst: ValueRef)
|
||||
-> block {
|
||||
self.datum.store_to(self.bcx, id, action, dst)
|
||||
}
|
||||
|
||||
fn copy_to(&self, action: CopyAction, dst: ValueRef) -> block {
|
||||
pub fn copy_to(&self, action: CopyAction, dst: ValueRef) -> block {
|
||||
self.datum.copy_to(self.bcx, action, dst)
|
||||
}
|
||||
|
||||
fn move_to(&self, action: CopyAction, dst: ValueRef) -> block {
|
||||
pub fn move_to(&self, action: CopyAction, dst: ValueRef) -> block {
|
||||
self.datum.move_to(self.bcx, action, dst)
|
||||
}
|
||||
|
||||
fn to_value_llval(&self) -> ValueRef {
|
||||
pub fn to_value_llval(&self) -> ValueRef {
|
||||
self.datum.to_value_llval(self.bcx)
|
||||
}
|
||||
|
||||
fn to_result(&self) -> common::Result {
|
||||
pub fn to_result(&self) -> common::Result {
|
||||
rslt(self.bcx, self.datum.to_appropriate_llval(self.bcx))
|
||||
}
|
||||
|
||||
fn ccx(&self) -> @CrateContext {
|
||||
pub fn ccx(&self) -> @CrateContext {
|
||||
self.bcx.ccx()
|
||||
}
|
||||
|
||||
fn tcx(&self) -> ty::ctxt {
|
||||
pub fn tcx(&self) -> ty::ctxt {
|
||||
self.bcx.tcx()
|
||||
}
|
||||
|
||||
fn to_str(&self) -> ~str {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
self.datum.to_str(self.ccx())
|
||||
}
|
||||
}
|
||||
|
@ -170,8 +170,8 @@ pub enum Dest {
|
||||
Ignore,
|
||||
}
|
||||
|
||||
pub impl Dest {
|
||||
fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
impl Dest {
|
||||
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
match *self {
|
||||
SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)),
|
||||
Ignore => ~"Ignore"
|
||||
|
@ -41,16 +41,16 @@ pub struct Reflector {
|
||||
bcx: block
|
||||
}
|
||||
|
||||
pub impl Reflector {
|
||||
fn c_uint(&mut self, u: uint) -> ValueRef {
|
||||
impl Reflector {
|
||||
pub fn c_uint(&mut self, u: uint) -> ValueRef {
|
||||
C_uint(self.bcx.ccx(), u)
|
||||
}
|
||||
|
||||
fn c_int(&mut self, i: int) -> ValueRef {
|
||||
pub fn c_int(&mut self, i: int) -> ValueRef {
|
||||
C_int(self.bcx.ccx(), i)
|
||||
}
|
||||
|
||||
fn c_slice(&mut self, s: @~str) -> ValueRef {
|
||||
pub fn c_slice(&mut self, s: @~str) -> ValueRef {
|
||||
// We're careful to not use first class aggregates here because that
|
||||
// will kick us off fast isel. (Issue #4352.)
|
||||
let bcx = self.bcx;
|
||||
@ -64,7 +64,7 @@ pub impl Reflector {
|
||||
scratch.val
|
||||
}
|
||||
|
||||
fn c_size_and_align(&mut self, t: ty::t) -> ~[ValueRef] {
|
||||
pub fn c_size_and_align(&mut self, t: ty::t) -> ~[ValueRef] {
|
||||
let tr = type_of(self.bcx.ccx(), t);
|
||||
let s = machine::llsize_of_real(self.bcx.ccx(), tr);
|
||||
let a = machine::llalign_of_min(self.bcx.ccx(), tr);
|
||||
@ -72,19 +72,19 @@ pub impl Reflector {
|
||||
self.c_uint(a)];
|
||||
}
|
||||
|
||||
fn c_tydesc(&mut self, t: ty::t) -> ValueRef {
|
||||
pub fn c_tydesc(&mut self, t: ty::t) -> ValueRef {
|
||||
let bcx = self.bcx;
|
||||
let static_ti = get_tydesc(bcx.ccx(), t);
|
||||
glue::lazily_emit_all_tydesc_glue(bcx.ccx(), static_ti);
|
||||
PointerCast(bcx, static_ti.tydesc, T_ptr(self.tydesc_ty))
|
||||
}
|
||||
|
||||
fn c_mt(&mut self, mt: &ty::mt) -> ~[ValueRef] {
|
||||
pub fn c_mt(&mut self, mt: &ty::mt) -> ~[ValueRef] {
|
||||
~[self.c_uint(mt.mutbl as uint),
|
||||
self.c_tydesc(mt.ty)]
|
||||
}
|
||||
|
||||
fn visit(&mut self, ty_name: ~str, args: &[ValueRef]) {
|
||||
pub fn visit(&mut self, ty_name: ~str, args: &[ValueRef]) {
|
||||
let tcx = self.bcx.tcx();
|
||||
let mth_idx = ty::method_idx(
|
||||
tcx.sess.ident_of(~"visit_" + ty_name),
|
||||
@ -119,19 +119,19 @@ pub impl Reflector {
|
||||
self.bcx = next_bcx
|
||||
}
|
||||
|
||||
fn bracketed(&mut self,
|
||||
bracket_name: ~str,
|
||||
extra: &[ValueRef],
|
||||
inner: &fn(&mut Reflector)) {
|
||||
pub fn bracketed(&mut self,
|
||||
bracket_name: ~str,
|
||||
extra: &[ValueRef],
|
||||
inner: &fn(&mut Reflector)) {
|
||||
self.visit(~"enter_" + bracket_name, extra);
|
||||
inner(self);
|
||||
self.visit(~"leave_" + bracket_name, extra);
|
||||
}
|
||||
|
||||
fn vstore_name_and_extra(&mut self,
|
||||
t: ty::t,
|
||||
vstore: ty::vstore) -> (~str, ~[ValueRef])
|
||||
{
|
||||
pub fn vstore_name_and_extra(&mut self,
|
||||
t: ty::t,
|
||||
vstore: ty::vstore)
|
||||
-> (~str, ~[ValueRef]) {
|
||||
match vstore {
|
||||
ty::vstore_fixed(n) => {
|
||||
let extra = vec::append(~[self.c_uint(n)],
|
||||
@ -144,12 +144,12 @@ pub impl Reflector {
|
||||
}
|
||||
}
|
||||
|
||||
fn leaf(&mut self, name: ~str) {
|
||||
pub fn leaf(&mut self, name: ~str) {
|
||||
self.visit(name, []);
|
||||
}
|
||||
|
||||
// Entrypoint
|
||||
fn visit_ty(&mut self, t: ty::t) {
|
||||
pub fn visit_ty(&mut self, t: ty::t) {
|
||||
let bcx = self.bcx;
|
||||
debug!("reflect::visit_ty %s",
|
||||
ty_to_str(bcx.ccx().tcx, t));
|
||||
@ -351,7 +351,7 @@ pub impl Reflector {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) {
|
||||
pub fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) {
|
||||
for sig.inputs.eachi |i, arg| {
|
||||
let modeval = 5u; // "by copy"
|
||||
let extra = ~[self.c_uint(i),
|
||||
|
@ -149,8 +149,8 @@ pub struct VecTypes {
|
||||
llunit_size: ValueRef
|
||||
}
|
||||
|
||||
pub impl VecTypes {
|
||||
fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
impl VecTypes {
|
||||
pub fn to_str(&self, ccx: @CrateContext) -> ~str {
|
||||
fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}",
|
||||
ty_to_str(ccx.tcx, self.vec_ty),
|
||||
ty_to_str(ccx.tcx, self.unit_ty),
|
||||
|
@ -68,14 +68,15 @@ pub struct Method {
|
||||
def_id: ast::def_id
|
||||
}
|
||||
|
||||
pub impl Method {
|
||||
fn new(ident: ast::ident,
|
||||
generics: ty::Generics,
|
||||
transformed_self_ty: Option<ty::t>,
|
||||
fty: BareFnTy,
|
||||
explicit_self: ast::explicit_self_,
|
||||
vis: ast::visibility,
|
||||
def_id: ast::def_id) -> Method {
|
||||
impl Method {
|
||||
pub fn new(ident: ast::ident,
|
||||
generics: ty::Generics,
|
||||
transformed_self_ty: Option<ty::t>,
|
||||
fty: BareFnTy,
|
||||
explicit_self: ast::explicit_self_,
|
||||
vis: ast::visibility,
|
||||
def_id: ast::def_id)
|
||||
-> Method {
|
||||
// Check the invariants.
|
||||
if explicit_self == ast::sty_static {
|
||||
assert!(transformed_self_ty.is_none());
|
||||
@ -460,8 +461,8 @@ pub enum Region {
|
||||
re_empty,
|
||||
}
|
||||
|
||||
pub impl Region {
|
||||
fn is_bound(&self) -> bool {
|
||||
impl Region {
|
||||
pub fn is_bound(&self) -> bool {
|
||||
match self {
|
||||
&re_bound(*) => true,
|
||||
_ => false
|
||||
@ -879,8 +880,8 @@ pub struct Generics {
|
||||
region_param: Option<region_variance>,
|
||||
}
|
||||
|
||||
pub impl Generics {
|
||||
fn has_type_params(&self) -> bool {
|
||||
impl Generics {
|
||||
pub fn has_type_params(&self) -> bool {
|
||||
!self.type_param_defs.is_empty()
|
||||
}
|
||||
}
|
||||
@ -1817,12 +1818,12 @@ pub struct TypeContents {
|
||||
bits: u32
|
||||
}
|
||||
|
||||
pub impl TypeContents {
|
||||
fn meets_bounds(&self, cx: ctxt, bbs: BuiltinBounds) -> bool {
|
||||
impl TypeContents {
|
||||
pub fn meets_bounds(&self, cx: ctxt, bbs: BuiltinBounds) -> bool {
|
||||
iter::all(|bb| self.meets_bound(cx, bb), |f| bbs.each(f))
|
||||
}
|
||||
|
||||
fn meets_bound(&self, cx: ctxt, bb: BuiltinBound) -> bool {
|
||||
pub fn meets_bound(&self, cx: ctxt, bb: BuiltinBound) -> bool {
|
||||
match bb {
|
||||
BoundCopy => self.is_copy(cx),
|
||||
BoundStatic => self.is_static(cx),
|
||||
@ -1832,69 +1833,69 @@ pub impl TypeContents {
|
||||
}
|
||||
}
|
||||
|
||||
fn intersects(&self, tc: TypeContents) -> bool {
|
||||
pub fn intersects(&self, tc: TypeContents) -> bool {
|
||||
(self.bits & tc.bits) != 0
|
||||
}
|
||||
|
||||
fn is_copy(&self, cx: ctxt) -> bool {
|
||||
pub fn is_copy(&self, cx: ctxt) -> bool {
|
||||
!self.intersects(TypeContents::noncopyable(cx))
|
||||
}
|
||||
|
||||
fn noncopyable(_cx: ctxt) -> TypeContents {
|
||||
pub fn noncopyable(_cx: ctxt) -> TypeContents {
|
||||
TC_DTOR + TC_BORROWED_MUT + TC_ONCE_CLOSURE + TC_OWNED_CLOSURE +
|
||||
TC_EMPTY_ENUM
|
||||
}
|
||||
|
||||
fn is_static(&self, cx: ctxt) -> bool {
|
||||
pub fn is_static(&self, cx: ctxt) -> bool {
|
||||
!self.intersects(TypeContents::nonstatic(cx))
|
||||
}
|
||||
|
||||
fn nonstatic(_cx: ctxt) -> TypeContents {
|
||||
pub fn nonstatic(_cx: ctxt) -> TypeContents {
|
||||
TC_BORROWED_POINTER
|
||||
}
|
||||
|
||||
fn is_owned(&self, cx: ctxt) -> bool {
|
||||
pub fn is_owned(&self, cx: ctxt) -> bool {
|
||||
!self.intersects(TypeContents::nonowned(cx))
|
||||
}
|
||||
|
||||
fn nonowned(_cx: ctxt) -> TypeContents {
|
||||
pub fn nonowned(_cx: ctxt) -> TypeContents {
|
||||
TC_MANAGED + TC_BORROWED_POINTER + TC_NON_OWNED
|
||||
}
|
||||
|
||||
fn contains_managed(&self) -> bool {
|
||||
pub fn contains_managed(&self) -> bool {
|
||||
self.intersects(TC_MANAGED)
|
||||
}
|
||||
|
||||
fn is_const(&self, cx: ctxt) -> bool {
|
||||
pub fn is_const(&self, cx: ctxt) -> bool {
|
||||
!self.intersects(TypeContents::nonconst(cx))
|
||||
}
|
||||
|
||||
fn nonconst(_cx: ctxt) -> TypeContents {
|
||||
pub fn nonconst(_cx: ctxt) -> TypeContents {
|
||||
TC_MUTABLE
|
||||
}
|
||||
|
||||
fn is_sized(&self, cx: ctxt) -> bool {
|
||||
pub fn is_sized(&self, cx: ctxt) -> bool {
|
||||
!self.intersects(TypeContents::dynamically_sized(cx))
|
||||
}
|
||||
|
||||
fn dynamically_sized(_cx: ctxt) -> TypeContents {
|
||||
pub fn dynamically_sized(_cx: ctxt) -> TypeContents {
|
||||
TC_DYNAMIC_SIZE
|
||||
}
|
||||
|
||||
fn moves_by_default(&self, cx: ctxt) -> bool {
|
||||
pub fn moves_by_default(&self, cx: ctxt) -> bool {
|
||||
self.intersects(TypeContents::nonimplicitly_copyable(cx))
|
||||
}
|
||||
|
||||
fn nonimplicitly_copyable(cx: ctxt) -> TypeContents {
|
||||
pub fn nonimplicitly_copyable(cx: ctxt) -> TypeContents {
|
||||
TypeContents::noncopyable(cx) + TC_OWNED_POINTER + TC_OWNED_VEC
|
||||
}
|
||||
|
||||
fn needs_drop(&self, cx: ctxt) -> bool {
|
||||
pub fn needs_drop(&self, cx: ctxt) -> bool {
|
||||
let tc = TC_MANAGED + TC_DTOR + TypeContents::owned(cx);
|
||||
self.intersects(tc)
|
||||
}
|
||||
|
||||
fn owned(_cx: ctxt) -> TypeContents {
|
||||
pub fn owned(_cx: ctxt) -> TypeContents {
|
||||
//! Any kind of owned contents.
|
||||
TC_OWNED_CLOSURE + TC_OWNED_POINTER + TC_OWNED_VEC
|
||||
}
|
||||
@ -3120,8 +3121,8 @@ pub fn adjust_ty(cx: ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
pub impl AutoRef {
|
||||
fn map_region(&self, f: &fn(Region) -> Region) -> AutoRef {
|
||||
impl AutoRef {
|
||||
pub fn map_region(&self, f: &fn(Region) -> Region) -> AutoRef {
|
||||
match *self {
|
||||
ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m),
|
||||
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m),
|
||||
@ -3809,14 +3810,15 @@ pub enum DtorKind {
|
||||
TraitDtor(def_id)
|
||||
}
|
||||
|
||||
pub impl DtorKind {
|
||||
fn is_not_present(&const self) -> bool {
|
||||
impl DtorKind {
|
||||
pub fn is_not_present(&const self) -> bool {
|
||||
match *self {
|
||||
NoDtor => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
fn is_present(&const self) -> bool {
|
||||
|
||||
pub fn is_present(&const self) -> bool {
|
||||
!self.is_not_present()
|
||||
}
|
||||
}
|
||||
|
@ -179,8 +179,8 @@ pub struct Candidate {
|
||||
origin: method_origin,
|
||||
}
|
||||
|
||||
pub impl<'self> LookupContext<'self> {
|
||||
fn do_lookup(&self, self_ty: ty::t) -> Option<method_map_entry> {
|
||||
impl<'self> LookupContext<'self> {
|
||||
pub fn do_lookup(&self, self_ty: ty::t) -> Option<method_map_entry> {
|
||||
let self_ty = structurally_resolved_type(self.fcx,
|
||||
self.self_expr.span,
|
||||
self_ty);
|
||||
@ -248,8 +248,8 @@ pub impl<'self> LookupContext<'self> {
|
||||
self.search_for_autosliced_method(self_ty, autoderefs)
|
||||
}
|
||||
|
||||
fn deref(&self, ty: ty::t, enum_dids: &mut ~[ast::def_id])
|
||||
-> Option<ty::t> {
|
||||
pub fn deref(&self, ty: ty::t, enum_dids: &mut ~[ast::def_id])
|
||||
-> Option<ty::t> {
|
||||
match ty::get(ty).sty {
|
||||
ty_enum(did, _) => {
|
||||
// Watch out for newtype'd enums like "enum t = @T".
|
||||
@ -275,7 +275,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
// ______________________________________________________________________
|
||||
// Candidate collection (see comment at start of file)
|
||||
|
||||
fn push_inherent_candidates(&self, self_ty: ty::t) {
|
||||
pub fn push_inherent_candidates(&self, self_ty: ty::t) {
|
||||
/*!
|
||||
* Collect all inherent candidates into
|
||||
* `self.inherent_candidates`. See comment at the start of
|
||||
@ -326,7 +326,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_extension_candidates(&self, self_ty: ty::t) {
|
||||
pub fn push_extension_candidates(&self, self_ty: ty::t) {
|
||||
// If the method being called is associated with a trait, then
|
||||
// find all the impls of that trait. Each of those are
|
||||
// candidates.
|
||||
@ -359,9 +359,9 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_inherent_candidates_from_param(&self,
|
||||
rcvr_ty: ty::t,
|
||||
param_ty: param_ty) {
|
||||
pub fn push_inherent_candidates_from_param(&self,
|
||||
rcvr_ty: ty::t,
|
||||
param_ty: param_ty) {
|
||||
debug!("push_inherent_candidates_from_param(param_ty=%?)",
|
||||
param_ty);
|
||||
let _indenter = indenter();
|
||||
@ -417,11 +417,11 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_inherent_candidates_from_trait(&self,
|
||||
self_ty: ty::t,
|
||||
did: def_id,
|
||||
substs: &ty::substs,
|
||||
store: ty::TraitStore) {
|
||||
pub fn push_inherent_candidates_from_trait(&self,
|
||||
self_ty: ty::t,
|
||||
did: def_id,
|
||||
substs: &ty::substs,
|
||||
store: ty::TraitStore) {
|
||||
debug!("push_inherent_candidates_from_trait(did=%s, substs=%s)",
|
||||
self.did_to_str(did),
|
||||
substs_to_str(self.tcx(), substs));
|
||||
@ -469,10 +469,10 @@ pub impl<'self> LookupContext<'self> {
|
||||
});
|
||||
}
|
||||
|
||||
fn push_inherent_candidates_from_self(&self,
|
||||
self_ty: ty::t,
|
||||
did: def_id,
|
||||
substs: &ty::substs) {
|
||||
pub fn push_inherent_candidates_from_self(&self,
|
||||
self_ty: ty::t,
|
||||
did: def_id,
|
||||
substs: &ty::substs) {
|
||||
struct MethodInfo {
|
||||
method_ty: @ty::Method,
|
||||
trait_def_id: ast::def_id,
|
||||
@ -533,7 +533,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_inherent_impl_candidates_for_type(&self, did: def_id) {
|
||||
pub fn push_inherent_impl_candidates_for_type(&self, did: def_id) {
|
||||
let opt_impl_infos =
|
||||
self.fcx.ccx.coherence_info.inherent_methods.find(&did);
|
||||
for opt_impl_infos.each |impl_infos| {
|
||||
@ -544,8 +544,9 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_candidates_from_impl(&self, candidates: &mut ~[Candidate],
|
||||
impl_info: &resolve::Impl) {
|
||||
pub fn push_candidates_from_impl(&self,
|
||||
candidates: &mut ~[Candidate],
|
||||
impl_info: &resolve::Impl) {
|
||||
if !self.impl_dups.insert(impl_info.did) {
|
||||
return; // already visited
|
||||
}
|
||||
@ -579,12 +580,14 @@ pub impl<'self> LookupContext<'self> {
|
||||
});
|
||||
}
|
||||
|
||||
fn push_candidates_from_provided_methods(
|
||||
&self,
|
||||
candidates: &mut ~[Candidate],
|
||||
self_ty: ty::t,
|
||||
trait_def_id: def_id,
|
||||
methods: &mut ~[@ProvidedMethodInfo]) {
|
||||
pub fn push_candidates_from_provided_methods(&self,
|
||||
candidates:
|
||||
&mut ~[Candidate],
|
||||
self_ty: ty::t,
|
||||
trait_def_id: def_id,
|
||||
methods:
|
||||
&mut ~[@ProvidedMethodInfo])
|
||||
{
|
||||
debug!("(pushing candidates from provided methods) considering trait \
|
||||
id %d:%d",
|
||||
trait_def_id.crate,
|
||||
@ -618,12 +621,10 @@ pub impl<'self> LookupContext<'self> {
|
||||
// ______________________________________________________________________
|
||||
// Candidate selection (see comment at start of file)
|
||||
|
||||
fn search_for_autoderefd_method(
|
||||
&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
pub fn search_for_autoderefd_method(&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> Option<method_map_entry> {
|
||||
let (self_ty, autoadjust) =
|
||||
self.consider_reborrow(self_ty, autoderefs);
|
||||
match self.search_for_method(self_ty) {
|
||||
@ -639,10 +640,10 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn consider_reborrow(&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint) -> (ty::t, ty::AutoAdjustment)
|
||||
{
|
||||
pub fn consider_reborrow(&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> (ty::t, ty::AutoAdjustment) {
|
||||
/*!
|
||||
*
|
||||
* In the event that we are invoking a method with a receiver
|
||||
@ -702,12 +703,10 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_for_autosliced_method(
|
||||
&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
pub fn search_for_autosliced_method(&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> Option<method_map_entry> {
|
||||
/*!
|
||||
*
|
||||
* Searches for a candidate by converting things like
|
||||
@ -770,12 +769,8 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_for_autoptrd_method(
|
||||
&self,
|
||||
self_ty: ty::t,
|
||||
autoderefs: uint)
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
pub fn search_for_autoptrd_method(&self, self_ty: ty::t, autoderefs: uint)
|
||||
-> Option<method_map_entry> {
|
||||
/*!
|
||||
*
|
||||
* Converts any type `T` to `&M T` where `M` is an
|
||||
@ -806,14 +801,13 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn search_for_some_kind_of_autorefd_method(
|
||||
pub fn search_for_some_kind_of_autorefd_method(
|
||||
&self,
|
||||
kind: &fn(Region, ast::mutability) -> ty::AutoRef,
|
||||
autoderefs: uint,
|
||||
mutbls: &[ast::mutability],
|
||||
mk_autoref_ty: &fn(ast::mutability, ty::Region) -> ty::t)
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
-> Option<method_map_entry> {
|
||||
// This is hokey. We should have mutability inference as a
|
||||
// variable. But for now, try &const, then &, then &mut:
|
||||
let region = self.infcx().next_region_var_nb(self.expr.span);
|
||||
@ -834,10 +828,8 @@ pub impl<'self> LookupContext<'self> {
|
||||
return None;
|
||||
}
|
||||
|
||||
fn search_for_method(&self,
|
||||
rcvr_ty: ty::t)
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
pub fn search_for_method(&self, rcvr_ty: ty::t)
|
||||
-> Option<method_map_entry> {
|
||||
debug!("search_for_method(rcvr_ty=%s)", self.ty_to_str(rcvr_ty));
|
||||
let _indenter = indenter();
|
||||
|
||||
@ -864,11 +856,10 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn consider_candidates(&self,
|
||||
rcvr_ty: ty::t,
|
||||
candidates: &mut ~[Candidate])
|
||||
-> Option<method_map_entry>
|
||||
{
|
||||
pub fn consider_candidates(&self,
|
||||
rcvr_ty: ty::t,
|
||||
candidates: &mut ~[Candidate])
|
||||
-> Option<method_map_entry> {
|
||||
let relevant_candidates =
|
||||
candidates.filter_to_vec(|c| self.is_relevant(rcvr_ty, c));
|
||||
|
||||
@ -890,7 +881,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
Some(self.confirm_candidate(rcvr_ty, &relevant_candidates[0]))
|
||||
}
|
||||
|
||||
fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] {
|
||||
pub fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] {
|
||||
let mut merged = ~[];
|
||||
let mut i = 0;
|
||||
while i < candidates.len() {
|
||||
@ -936,11 +927,8 @@ pub impl<'self> LookupContext<'self> {
|
||||
return merged;
|
||||
}
|
||||
|
||||
fn confirm_candidate(&self,
|
||||
rcvr_ty: ty::t,
|
||||
candidate: &Candidate)
|
||||
-> method_map_entry
|
||||
{
|
||||
pub fn confirm_candidate(&self, rcvr_ty: ty::t, candidate: &Candidate)
|
||||
-> method_map_entry {
|
||||
let tcx = self.tcx();
|
||||
let fty = self.fn_ty_from_origin(&candidate.origin);
|
||||
|
||||
@ -1065,10 +1053,9 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn enforce_trait_instance_limitations(&self,
|
||||
method_fty: ty::t,
|
||||
candidate: &Candidate)
|
||||
{
|
||||
pub fn enforce_trait_instance_limitations(&self,
|
||||
method_fty: ty::t,
|
||||
candidate: &Candidate) {
|
||||
/*!
|
||||
*
|
||||
* There are some limitations to calling functions through a
|
||||
@ -1099,7 +1086,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn enforce_drop_trait_limitations(&self, candidate: &Candidate) {
|
||||
pub fn enforce_drop_trait_limitations(&self, candidate: &Candidate) {
|
||||
// No code can call the finalize method explicitly.
|
||||
let bad;
|
||||
match candidate.origin {
|
||||
@ -1121,7 +1108,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
|
||||
// `rcvr_ty` is the type of the expression. It may be a subtype of a
|
||||
// candidate method's `self_ty`.
|
||||
fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool {
|
||||
pub fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool {
|
||||
debug!("is_relevant(rcvr_ty=%s, candidate=%s)",
|
||||
self.ty_to_str(rcvr_ty), self.cand_to_str(candidate));
|
||||
|
||||
@ -1208,7 +1195,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_ty_from_origin(&self, origin: &method_origin) -> ty::t {
|
||||
pub fn fn_ty_from_origin(&self, origin: &method_origin) -> ty::t {
|
||||
return match *origin {
|
||||
method_static(did) => {
|
||||
ty::lookup_item_type(self.tcx(), did).ty
|
||||
@ -1230,7 +1217,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_candidate(&self, idx: uint, origin: &method_origin) {
|
||||
pub fn report_candidate(&self, idx: uint, origin: &method_origin) {
|
||||
match *origin {
|
||||
method_static(impl_did) => {
|
||||
self.report_static_candidate(idx, impl_did)
|
||||
@ -1245,7 +1232,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_static_candidate(&self, idx: uint, did: def_id) {
|
||||
pub fn report_static_candidate(&self, idx: uint, did: def_id) {
|
||||
let span = if did.crate == ast::local_crate {
|
||||
match self.tcx().items.find(&did.node) {
|
||||
Some(&ast_map::node_method(m, _, _)) => m.span,
|
||||
@ -1261,7 +1248,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
ty::item_path_str(self.tcx(), did)));
|
||||
}
|
||||
|
||||
fn report_param_candidate(&self, idx: uint, did: def_id) {
|
||||
pub fn report_param_candidate(&self, idx: uint, did: def_id) {
|
||||
self.tcx().sess.span_note(
|
||||
self.expr.span,
|
||||
fmt!("candidate #%u derives from the bound `%s`",
|
||||
@ -1269,7 +1256,7 @@ pub impl<'self> LookupContext<'self> {
|
||||
ty::item_path_str(self.tcx(), did)));
|
||||
}
|
||||
|
||||
fn report_trait_candidate(&self, idx: uint, did: def_id) {
|
||||
pub fn report_trait_candidate(&self, idx: uint, did: def_id) {
|
||||
self.tcx().sess.span_note(
|
||||
self.expr.span,
|
||||
fmt!("candidate #%u derives from the type of the receiver, \
|
||||
@ -1278,30 +1265,30 @@ pub impl<'self> LookupContext<'self> {
|
||||
ty::item_path_str(self.tcx(), did)));
|
||||
}
|
||||
|
||||
fn infcx(&self) -> @mut infer::InferCtxt {
|
||||
pub fn infcx(&self) -> @mut infer::InferCtxt {
|
||||
self.fcx.inh.infcx
|
||||
}
|
||||
|
||||
fn tcx(&self) -> ty::ctxt {
|
||||
pub fn tcx(&self) -> ty::ctxt {
|
||||
self.fcx.tcx()
|
||||
}
|
||||
|
||||
fn ty_to_str(&self, t: ty::t) -> ~str {
|
||||
pub fn ty_to_str(&self, t: ty::t) -> ~str {
|
||||
self.fcx.infcx().ty_to_str(t)
|
||||
}
|
||||
|
||||
fn cand_to_str(&self, cand: &Candidate) -> ~str {
|
||||
pub fn cand_to_str(&self, cand: &Candidate) -> ~str {
|
||||
fmt!("Candidate(rcvr_ty=%s, rcvr_substs=%s, origin=%?)",
|
||||
self.ty_to_str(cand.rcvr_ty),
|
||||
ty::substs_to_str(self.tcx(), &cand.rcvr_substs),
|
||||
cand.origin)
|
||||
}
|
||||
|
||||
fn did_to_str(&self, did: def_id) -> ~str {
|
||||
pub fn did_to_str(&self, did: def_id) -> ~str {
|
||||
ty::item_path_str(self.tcx(), did)
|
||||
}
|
||||
|
||||
fn bug(&self, s: ~str) -> ! {
|
||||
pub fn bug(&self, s: ~str) -> ! {
|
||||
self.tcx().sess.bug(s)
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ pub struct PurityState {
|
||||
priv from_fn: bool
|
||||
}
|
||||
|
||||
pub impl PurityState {
|
||||
impl PurityState {
|
||||
pub fn function(purity: ast::purity, def: ast::node_id) -> PurityState {
|
||||
PurityState { def: def, purity: purity, from_fn: true }
|
||||
}
|
||||
@ -658,18 +658,17 @@ impl AstConv for FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl FnCtxt {
|
||||
fn infcx(&self) -> @mut infer::InferCtxt {
|
||||
impl FnCtxt {
|
||||
pub fn infcx(&self) -> @mut infer::InferCtxt {
|
||||
self.inh.infcx
|
||||
}
|
||||
fn err_count_since_creation(&self) -> uint {
|
||||
pub fn err_count_since_creation(&self) -> uint {
|
||||
self.ccx.tcx.sess.err_count() - self.err_count_on_creation
|
||||
}
|
||||
fn search_in_scope_regions(
|
||||
&self,
|
||||
span: span,
|
||||
br: ty::bound_region) -> Result<ty::Region, RegionError>
|
||||
{
|
||||
pub fn search_in_scope_regions(&self,
|
||||
span: span,
|
||||
br: ty::bound_region)
|
||||
-> Result<ty::Region, RegionError> {
|
||||
let in_scope_regions = self.in_scope_regions;
|
||||
match in_scope_regions.find(br) {
|
||||
Some(r) => result::Ok(r),
|
||||
@ -703,14 +702,14 @@ impl region_scope for FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl FnCtxt {
|
||||
fn tag(&self) -> ~str {
|
||||
impl FnCtxt {
|
||||
pub fn tag(&self) -> ~str {
|
||||
unsafe {
|
||||
fmt!("%x", transmute(self))
|
||||
}
|
||||
}
|
||||
|
||||
fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t {
|
||||
pub fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t {
|
||||
match self.inh.locals.find(&nid) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
@ -721,23 +720,23 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_to_str(&self, expr: @ast::expr) -> ~str {
|
||||
pub fn expr_to_str(&self, expr: @ast::expr) -> ~str {
|
||||
fmt!("expr(%?:%s)", expr.id,
|
||||
pprust::expr_to_str(expr, self.tcx().sess.intr()))
|
||||
}
|
||||
|
||||
fn block_region(&self) -> ty::Region {
|
||||
pub fn block_region(&self) -> ty::Region {
|
||||
ty::re_scope(self.region_lb)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write_ty(&self, node_id: ast::node_id, ty: ty::t) {
|
||||
pub fn write_ty(&self, node_id: ast::node_id, ty: ty::t) {
|
||||
debug!("write_ty(%d, %s) in fcx %s",
|
||||
node_id, ppaux::ty_to_str(self.tcx(), ty), self.tag());
|
||||
self.inh.node_types.insert(node_id, ty);
|
||||
}
|
||||
|
||||
fn write_substs(&self, node_id: ast::node_id, substs: ty::substs) {
|
||||
pub fn write_substs(&self, node_id: ast::node_id, substs: ty::substs) {
|
||||
if !ty::substs_is_noop(&substs) {
|
||||
debug!("write_substs(%d, %s) in fcx %s",
|
||||
node_id,
|
||||
@ -747,18 +746,18 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_ty_substs(&self,
|
||||
node_id: ast::node_id,
|
||||
ty: ty::t,
|
||||
substs: ty::substs) {
|
||||
pub fn write_ty_substs(&self,
|
||||
node_id: ast::node_id,
|
||||
ty: ty::t,
|
||||
substs: ty::substs) {
|
||||
let ty = ty::subst(self.tcx(), &substs, ty);
|
||||
self.write_ty(node_id, ty);
|
||||
self.write_substs(node_id, substs);
|
||||
}
|
||||
|
||||
fn write_autoderef_adjustment(&self,
|
||||
node_id: ast::node_id,
|
||||
derefs: uint) {
|
||||
pub fn write_autoderef_adjustment(&self,
|
||||
node_id: ast::node_id,
|
||||
derefs: uint) {
|
||||
if derefs == 0 { return; }
|
||||
self.write_adjustment(
|
||||
node_id,
|
||||
@ -768,36 +767,36 @@ pub impl FnCtxt {
|
||||
);
|
||||
}
|
||||
|
||||
fn write_adjustment(&self,
|
||||
node_id: ast::node_id,
|
||||
adj: @ty::AutoAdjustment) {
|
||||
pub fn write_adjustment(&self,
|
||||
node_id: ast::node_id,
|
||||
adj: @ty::AutoAdjustment) {
|
||||
debug!("write_adjustment(node_id=%?, adj=%?)", node_id, adj);
|
||||
self.inh.adjustments.insert(node_id, adj);
|
||||
}
|
||||
|
||||
fn write_nil(&self, node_id: ast::node_id) {
|
||||
pub fn write_nil(&self, node_id: ast::node_id) {
|
||||
self.write_ty(node_id, ty::mk_nil());
|
||||
}
|
||||
fn write_bot(&self, node_id: ast::node_id) {
|
||||
pub fn write_bot(&self, node_id: ast::node_id) {
|
||||
self.write_ty(node_id, ty::mk_bot());
|
||||
}
|
||||
fn write_error(@mut self, node_id: ast::node_id) {
|
||||
pub fn write_error(@mut self, node_id: ast::node_id) {
|
||||
self.write_ty(node_id, ty::mk_err());
|
||||
}
|
||||
|
||||
fn to_ty(&self, ast_t: @ast::Ty) -> ty::t {
|
||||
pub fn to_ty(&self, ast_t: @ast::Ty) -> ty::t {
|
||||
ast_ty_to_ty(self, self, ast_t)
|
||||
}
|
||||
|
||||
fn expr_to_str(&self, expr: @ast::expr) -> ~str {
|
||||
pub fn expr_to_str(&self, expr: @ast::expr) -> ~str {
|
||||
expr.repr(self.tcx())
|
||||
}
|
||||
|
||||
fn pat_to_str(&self, pat: @ast::pat) -> ~str {
|
||||
pub fn pat_to_str(&self, pat: @ast::pat) -> ~str {
|
||||
pat.repr(self.tcx())
|
||||
}
|
||||
|
||||
fn expr_ty(&self, ex: @ast::expr) -> ty::t {
|
||||
pub fn expr_ty(&self, ex: @ast::expr) -> ty::t {
|
||||
match self.inh.node_types.find(&ex.id) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
@ -807,7 +806,8 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn node_ty(&self, id: ast::node_id) -> ty::t {
|
||||
|
||||
pub fn node_ty(&self, id: ast::node_id) -> ty::t {
|
||||
match self.inh.node_types.find(&id) {
|
||||
Some(&t) => t,
|
||||
None => {
|
||||
@ -820,7 +820,8 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn node_ty_substs(&self, id: ast::node_id) -> ty::substs {
|
||||
|
||||
pub fn node_ty_substs(&self, id: ast::node_id) -> ty::substs {
|
||||
match self.inh.node_type_substs.find(&id) {
|
||||
Some(ts) => (/*bad*/copy *ts),
|
||||
None => {
|
||||
@ -834,32 +835,32 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn opt_node_ty_substs(&self, id: ast::node_id,
|
||||
f: &fn(&ty::substs) -> bool) -> bool {
|
||||
pub fn opt_node_ty_substs(&self,
|
||||
id: ast::node_id,
|
||||
f: &fn(&ty::substs) -> bool)
|
||||
-> bool {
|
||||
match self.inh.node_type_substs.find(&id) {
|
||||
Some(s) => f(s),
|
||||
None => true
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_subty(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn mk_subty(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
infer::mk_subty(self.infcx(), a_is_expected, span, sub, sup)
|
||||
}
|
||||
|
||||
fn can_mk_subty(&self,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn can_mk_subty(&self, sub: ty::t, sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
infer::can_mk_subty(self.infcx(), sub, sup)
|
||||
}
|
||||
|
||||
fn mk_assignty(&self, expr: @ast::expr, sub: ty::t, sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn mk_assignty(&self, expr: @ast::expr, sub: ty::t, sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
match infer::mk_coercety(self.infcx(), false, expr.span, sub, sup) {
|
||||
Ok(None) => result::Ok(()),
|
||||
Err(ref e) => result::Err((*e)),
|
||||
@ -870,32 +871,31 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn can_mk_assignty(&self,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn can_mk_assignty(&self, sub: ty::t, sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
infer::can_mk_coercety(self.infcx(), sub, sup)
|
||||
}
|
||||
|
||||
fn mk_eqty(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn mk_eqty(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::t,
|
||||
sup: ty::t)
|
||||
-> Result<(), ty::type_err> {
|
||||
infer::mk_eqty(self.infcx(), a_is_expected, span, sub, sup)
|
||||
}
|
||||
|
||||
fn mk_subr(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::Region,
|
||||
sup: ty::Region)
|
||||
-> Result<(), ty::type_err> {
|
||||
pub fn mk_subr(&self,
|
||||
a_is_expected: bool,
|
||||
span: span,
|
||||
sub: ty::Region,
|
||||
sup: ty::Region)
|
||||
-> Result<(), ty::type_err> {
|
||||
infer::mk_subr(self.infcx(), a_is_expected, span, sub, sup)
|
||||
}
|
||||
|
||||
fn with_region_lb<R>(@mut self, lb: ast::node_id, f: &fn() -> R) -> R {
|
||||
pub fn with_region_lb<R>(@mut self, lb: ast::node_id, f: &fn() -> R)
|
||||
-> R {
|
||||
let old_region_lb = self.region_lb;
|
||||
self.region_lb = lb;
|
||||
let v = f();
|
||||
@ -903,26 +903,26 @@ pub impl FnCtxt {
|
||||
v
|
||||
}
|
||||
|
||||
fn region_var_if_parameterized(&self,
|
||||
rp: Option<ty::region_variance>,
|
||||
span: span)
|
||||
-> Option<ty::Region> {
|
||||
pub fn region_var_if_parameterized(&self,
|
||||
rp: Option<ty::region_variance>,
|
||||
span: span)
|
||||
-> Option<ty::Region> {
|
||||
rp.map(|_rp| self.infcx().next_region_var_nb(span))
|
||||
}
|
||||
|
||||
fn type_error_message(&self,
|
||||
sp: span,
|
||||
mk_msg: &fn(~str) -> ~str,
|
||||
actual_ty: ty::t,
|
||||
err: Option<&ty::type_err>) {
|
||||
pub fn type_error_message(&self,
|
||||
sp: span,
|
||||
mk_msg: &fn(~str) -> ~str,
|
||||
actual_ty: ty::t,
|
||||
err: Option<&ty::type_err>) {
|
||||
self.infcx().type_error_message(sp, mk_msg, actual_ty, err);
|
||||
}
|
||||
|
||||
fn report_mismatched_return_types(&self,
|
||||
sp: span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
pub fn report_mismatched_return_types(&self,
|
||||
sp: span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
// Derived error
|
||||
if ty::type_is_error(e) || ty::type_is_error(a) {
|
||||
return;
|
||||
@ -943,11 +943,11 @@ pub impl FnCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn report_mismatched_types(&self,
|
||||
sp: span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
pub fn report_mismatched_types(&self,
|
||||
sp: span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
self.infcx().report_mismatched_types(sp, e, a, err)
|
||||
}
|
||||
}
|
||||
|
@ -74,12 +74,12 @@ fn encl_region_of_def(fcx: @mut FnCtxt, def: ast::def) -> ty::Region {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Rcx {
|
||||
fn tcx(&self) -> ty::ctxt {
|
||||
impl Rcx {
|
||||
pub fn tcx(&self) -> ty::ctxt {
|
||||
self.fcx.ccx.tcx
|
||||
}
|
||||
|
||||
fn resolve_type(&mut self, unresolved_ty: ty::t) -> ty::t {
|
||||
pub fn resolve_type(&mut self, unresolved_ty: ty::t) -> ty::t {
|
||||
/*!
|
||||
* Try to resolve the type for the given node, returning
|
||||
* t_err if an error results. Note that we never care
|
||||
@ -116,12 +116,12 @@ pub impl Rcx {
|
||||
}
|
||||
|
||||
/// Try to resolve the type for the given node.
|
||||
fn resolve_node_type(@mut self, id: ast::node_id) -> ty::t {
|
||||
pub fn resolve_node_type(@mut self, id: ast::node_id) -> ty::t {
|
||||
self.resolve_type(self.fcx.node_ty(id))
|
||||
}
|
||||
|
||||
/// Try to resolve the type for the given node.
|
||||
fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t {
|
||||
pub fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t {
|
||||
let ty_unadjusted = self.resolve_node_type(expr.id);
|
||||
if ty::type_is_error(ty_unadjusted) || ty::type_is_bot(ty_unadjusted) {
|
||||
ty_unadjusted
|
||||
|
@ -65,8 +65,8 @@ pub struct VtableContext {
|
||||
infcx: @mut infer::InferCtxt
|
||||
}
|
||||
|
||||
pub impl VtableContext {
|
||||
fn tcx(&const self) -> ty::ctxt { self.ccx.tcx }
|
||||
impl VtableContext {
|
||||
pub fn tcx(&const self) -> ty::ctxt { self.ccx.tcx }
|
||||
}
|
||||
|
||||
fn has_trait_bounds(type_param_defs: &[ty::TypeParameterDef]) -> bool {
|
||||
|
@ -199,8 +199,8 @@ pub struct CoherenceChecker {
|
||||
base_type_def_ids: @mut HashMap<def_id,def_id>,
|
||||
}
|
||||
|
||||
pub impl CoherenceChecker {
|
||||
fn check_coherence(self, crate: @crate) {
|
||||
impl CoherenceChecker {
|
||||
pub fn check_coherence(self, crate: @crate) {
|
||||
// Check implementations and traits. This populates the tables
|
||||
// containing the inherent methods and extension methods. It also
|
||||
// builds up the trait inheritance table.
|
||||
@ -239,8 +239,9 @@ pub impl CoherenceChecker {
|
||||
self.populate_destructor_table();
|
||||
}
|
||||
|
||||
fn check_implementation(&self,
|
||||
item: @item, associated_traits: ~[@trait_ref]) {
|
||||
pub fn check_implementation(&self,
|
||||
item: @item,
|
||||
associated_traits: ~[@trait_ref]) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
let self_type = ty::lookup_item_type(tcx, local_def(item.id));
|
||||
|
||||
@ -325,9 +326,9 @@ pub impl CoherenceChecker {
|
||||
// Creates default method IDs and performs type substitutions for an impl
|
||||
// and trait pair. Then, for each provided method in the trait, inserts a
|
||||
// `ProvidedMethodInfo` instance into the `provided_method_sources` map.
|
||||
fn instantiate_default_methods(&self,
|
||||
impl_id: ast::node_id,
|
||||
trait_ref: &ty::TraitRef) {
|
||||
pub fn instantiate_default_methods(&self,
|
||||
impl_id: ast::node_id,
|
||||
trait_ref: &ty::TraitRef) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
debug!("instantiate_default_methods(impl_id=%?, trait_ref=%s)",
|
||||
impl_id, trait_ref.repr(tcx));
|
||||
@ -416,8 +417,9 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_inherent_method(&self,
|
||||
base_def_id: def_id, implementation: @Impl) {
|
||||
pub fn add_inherent_method(&self,
|
||||
base_def_id: def_id,
|
||||
implementation: @Impl) {
|
||||
let implementation_list;
|
||||
match self.crate_context.coherence_info.inherent_methods
|
||||
.find(&base_def_id) {
|
||||
@ -434,7 +436,7 @@ pub impl CoherenceChecker {
|
||||
implementation_list.push(implementation);
|
||||
}
|
||||
|
||||
fn add_trait_method(&self, trait_id: def_id, implementation: @Impl) {
|
||||
pub fn add_trait_method(&self, trait_id: def_id, implementation: @Impl) {
|
||||
let implementation_list;
|
||||
match self.crate_context.coherence_info.extension_methods
|
||||
.find(&trait_id) {
|
||||
@ -451,15 +453,14 @@ pub impl CoherenceChecker {
|
||||
implementation_list.push(implementation);
|
||||
}
|
||||
|
||||
fn check_implementation_coherence(&self) {
|
||||
pub fn check_implementation_coherence(&self) {
|
||||
let coherence_info = self.crate_context.coherence_info;
|
||||
for coherence_info.extension_methods.each_key |&trait_id| {
|
||||
self.check_implementation_coherence_of(trait_id);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_implementation_coherence_of(&self, trait_def_id: def_id) {
|
||||
|
||||
pub fn check_implementation_coherence_of(&self, trait_def_id: def_id) {
|
||||
// Unify pairs of polytypes.
|
||||
do self.iter_impls_of_trait(trait_def_id) |a| {
|
||||
let implementation_a = a;
|
||||
@ -492,8 +493,10 @@ pub impl CoherenceChecker {
|
||||
|
||||
// Adds an impl of trait trait_t for self type self_t; that impl
|
||||
// is the_impl
|
||||
fn add_impl_for_trait(&self,
|
||||
trait_t: def_id, self_t: t, the_impl: @Impl) {
|
||||
pub fn add_impl_for_trait(&self,
|
||||
trait_t: def_id,
|
||||
self_t: t,
|
||||
the_impl: @Impl) {
|
||||
debug!("Adding impl %? of %? for %s",
|
||||
the_impl.did, trait_t,
|
||||
ty_to_str(self.crate_context.tcx, self_t));
|
||||
@ -509,7 +512,7 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn iter_impls_of_trait(&self, trait_def_id: def_id, f: &fn(@Impl)) {
|
||||
pub fn iter_impls_of_trait(&self, trait_def_id: def_id, f: &fn(@Impl)) {
|
||||
let coherence_info = self.crate_context.coherence_info;
|
||||
let extension_methods = &*coherence_info.extension_methods;
|
||||
|
||||
@ -527,9 +530,10 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn each_provided_trait_method(&self,
|
||||
trait_did: ast::def_id,
|
||||
f: &fn(x: @ty::Method) -> bool) -> bool {
|
||||
pub fn each_provided_trait_method(&self,
|
||||
trait_did: ast::def_id,
|
||||
f: &fn(x: @ty::Method) -> bool)
|
||||
-> bool {
|
||||
// Make a list of all the names of the provided methods.
|
||||
// XXX: This is horrible.
|
||||
let mut provided_method_idents = HashSet::new();
|
||||
@ -548,9 +552,10 @@ pub impl CoherenceChecker {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn polytypes_unify(&self, polytype_a: ty_param_bounds_and_ty,
|
||||
polytype_b: ty_param_bounds_and_ty)
|
||||
-> bool {
|
||||
pub fn polytypes_unify(&self,
|
||||
polytype_a: ty_param_bounds_and_ty,
|
||||
polytype_b: ty_param_bounds_and_ty)
|
||||
-> bool {
|
||||
let universally_quantified_a =
|
||||
self.universally_quantify_polytype(polytype_a);
|
||||
let universally_quantified_b =
|
||||
@ -564,8 +569,9 @@ pub impl CoherenceChecker {
|
||||
|
||||
// Converts a polytype to a monotype by replacing all parameters with
|
||||
// type variables. Returns the monotype and the type variables created.
|
||||
fn universally_quantify_polytype(&self, polytype: ty_param_bounds_and_ty)
|
||||
-> UniversalQuantificationResult {
|
||||
pub fn universally_quantify_polytype(&self,
|
||||
polytype: ty_param_bounds_and_ty)
|
||||
-> UniversalQuantificationResult {
|
||||
// NDM--this span is bogus.
|
||||
let self_region =
|
||||
polytype.generics.region_param.map(
|
||||
@ -594,11 +600,12 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn can_unify_universally_quantified<'a>
|
||||
(&self,
|
||||
a: &'a UniversalQuantificationResult,
|
||||
b: &'a UniversalQuantificationResult)
|
||||
-> bool {
|
||||
pub fn can_unify_universally_quantified<'a>(&self,
|
||||
a: &'a
|
||||
UniversalQuantificationResult,
|
||||
b: &'a
|
||||
UniversalQuantificationResult)
|
||||
-> bool {
|
||||
let mut might_unify = true;
|
||||
let _ = do self.inference_context.probe {
|
||||
let result = self.inference_context.sub(true, dummy_sp())
|
||||
@ -642,13 +649,13 @@ pub impl CoherenceChecker {
|
||||
might_unify
|
||||
}
|
||||
|
||||
fn get_self_type_for_implementation(&self, implementation: @Impl)
|
||||
-> ty_param_bounds_and_ty {
|
||||
pub fn get_self_type_for_implementation(&self, implementation: @Impl)
|
||||
-> ty_param_bounds_and_ty {
|
||||
return self.crate_context.tcx.tcache.get_copy(&implementation.did);
|
||||
}
|
||||
|
||||
// Privileged scope checking
|
||||
fn check_privileged_scopes(self, crate: @crate) {
|
||||
pub fn check_privileged_scopes(self, crate: @crate) {
|
||||
visit_crate(crate, (), mk_vt(@Visitor {
|
||||
visit_item: |item, _context, visitor| {
|
||||
match item.node {
|
||||
@ -698,7 +705,7 @@ pub impl CoherenceChecker {
|
||||
}));
|
||||
}
|
||||
|
||||
fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
|
||||
pub fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id {
|
||||
let def_map = self.crate_context.tcx.def_map;
|
||||
let trait_def = def_map.get_copy(&trait_ref.ref_id);
|
||||
let trait_id = def_id_of_def(trait_def);
|
||||
@ -707,10 +714,13 @@ pub impl CoherenceChecker {
|
||||
|
||||
// This check doesn't really have anything to do with coherence. It's
|
||||
// here for historical reasons
|
||||
fn please_check_that_trait_methods_are_implemented(&self,
|
||||
all_methods: &mut ~[@MethodInfo],
|
||||
trait_did: def_id,
|
||||
trait_ref_span: span) {
|
||||
pub fn please_check_that_trait_methods_are_implemented(&self,
|
||||
all_methods:
|
||||
&mut
|
||||
~[@MethodInfo],
|
||||
trait_did: def_id,
|
||||
trait_ref_span:
|
||||
span) {
|
||||
|
||||
let tcx = self.crate_context.tcx;
|
||||
|
||||
@ -774,7 +784,7 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
|
||||
// Converts an implementation in the AST to an Impl structure.
|
||||
fn create_impl_from_item(&self, item: @item) -> @Impl {
|
||||
pub fn create_impl_from_item(&self, item: @item) -> @Impl {
|
||||
fn add_provided_methods(all_methods: &mut ~[@MethodInfo],
|
||||
all_provided_methods: &mut ~[@ProvidedMethodInfo],
|
||||
sess: driver::session::Session) {
|
||||
@ -844,7 +854,7 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn span_of_impl(&self, implementation: @Impl) -> span {
|
||||
pub fn span_of_impl(&self, implementation: @Impl) -> span {
|
||||
assert_eq!(implementation.did.crate, local_crate);
|
||||
match self.crate_context.tcx.items.find(&implementation.did.node) {
|
||||
Some(&node_item(item, _)) => {
|
||||
@ -859,9 +869,10 @@ pub impl CoherenceChecker {
|
||||
|
||||
// External crate handling
|
||||
|
||||
fn add_impls_for_module(&self, impls_seen: &mut HashSet<def_id>,
|
||||
crate_store: @mut CStore,
|
||||
module_def_id: def_id) {
|
||||
pub fn add_impls_for_module(&self,
|
||||
impls_seen: &mut HashSet<def_id>,
|
||||
crate_store: @mut CStore,
|
||||
module_def_id: def_id) {
|
||||
let implementations = get_impls_for_mod(crate_store,
|
||||
module_def_id,
|
||||
None);
|
||||
@ -934,8 +945,8 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_default_methods_for_external_trait(&self,
|
||||
trait_def_id: ast::def_id) {
|
||||
pub fn add_default_methods_for_external_trait(&self,
|
||||
trait_def_id: ast::def_id) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
let pmm = tcx.provided_methods;
|
||||
|
||||
@ -968,7 +979,7 @@ pub impl CoherenceChecker {
|
||||
|
||||
// Adds implementations and traits from external crates to the coherence
|
||||
// info.
|
||||
fn add_external_crates(&self) {
|
||||
pub fn add_external_crates(&self) {
|
||||
let mut impls_seen = HashSet::new();
|
||||
|
||||
let crate_store = self.crate_context.tcx.sess.cstore;
|
||||
@ -1001,7 +1012,7 @@ pub impl CoherenceChecker {
|
||||
// Destructors
|
||||
//
|
||||
|
||||
fn populate_destructor_table(&self) {
|
||||
pub fn populate_destructor_table(&self) {
|
||||
let coherence_info = self.crate_context.coherence_info;
|
||||
let tcx = self.crate_context.tcx;
|
||||
let drop_trait = tcx.lang_items.drop_trait();
|
||||
@ -1050,13 +1061,12 @@ pub impl CoherenceChecker {
|
||||
}
|
||||
}
|
||||
|
||||
fn subst_receiver_types_in_method_ty(
|
||||
tcx: ty::ctxt,
|
||||
impl_id: ast::node_id,
|
||||
trait_ref: &ty::TraitRef,
|
||||
new_def_id: ast::def_id,
|
||||
method: &ty::Method) -> ty::Method
|
||||
{
|
||||
fn subst_receiver_types_in_method_ty(tcx: ty::ctxt,
|
||||
impl_id: ast::node_id,
|
||||
trait_ref: &ty::TraitRef,
|
||||
new_def_id: ast::def_id,
|
||||
method: &ty::Method)
|
||||
-> ty::Method {
|
||||
/*!
|
||||
* Substitutes the values for the receiver's type parameters
|
||||
* that are found in method, leaving the method's type parameters
|
||||
|
@ -86,8 +86,8 @@ use syntax::ast;
|
||||
// function.
|
||||
pub struct Coerce(CombineFields);
|
||||
|
||||
pub impl Coerce {
|
||||
fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
|
||||
impl Coerce {
|
||||
pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
|
||||
debug!("Coerce.tys(%s => %s)",
|
||||
a.inf_str(self.infcx),
|
||||
b.inf_str(self.infcx));
|
||||
@ -149,17 +149,17 @@ pub impl Coerce {
|
||||
}
|
||||
}
|
||||
|
||||
fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult {
|
||||
pub fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult {
|
||||
match Sub(**self).tys(a, b) {
|
||||
Ok(_) => Ok(None), // No coercion required.
|
||||
Err(ref e) => Err(*e)
|
||||
}
|
||||
}
|
||||
|
||||
fn unpack_actual_value(&self,
|
||||
a: ty::t,
|
||||
f: &fn(&ty::sty) -> CoerceResult) -> CoerceResult
|
||||
{
|
||||
pub fn unpack_actual_value(&self,
|
||||
a: ty::t,
|
||||
f: &fn(&ty::sty) -> CoerceResult)
|
||||
-> CoerceResult {
|
||||
match resolve_type(self.infcx, a, try_resolve_tvar_shallow) {
|
||||
Ok(t) => {
|
||||
f(&ty::get(t).sty)
|
||||
@ -173,12 +173,12 @@ pub impl Coerce {
|
||||
}
|
||||
}
|
||||
|
||||
fn coerce_borrowed_pointer(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_borrowed_pointer(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt)
|
||||
-> CoerceResult {
|
||||
debug!("coerce_borrowed_pointer(a=%s, sty_a=%?, b=%s, mt_b=%?)",
|
||||
a.inf_str(self.infcx), sty_a,
|
||||
b.inf_str(self.infcx), mt_b);
|
||||
@ -211,11 +211,11 @@ pub impl Coerce {
|
||||
})))
|
||||
}
|
||||
|
||||
fn coerce_borrowed_string(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_borrowed_string(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t)
|
||||
-> CoerceResult {
|
||||
debug!("coerce_borrowed_string(a=%s, sty_a=%?, b=%s)",
|
||||
a.inf_str(self.infcx), sty_a,
|
||||
b.inf_str(self.infcx));
|
||||
@ -237,12 +237,12 @@ pub impl Coerce {
|
||||
})))
|
||||
}
|
||||
|
||||
fn coerce_borrowed_vector(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_borrowed_vector(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt)
|
||||
-> CoerceResult {
|
||||
debug!("coerce_borrowed_vector(a=%s, sty_a=%?, b=%s)",
|
||||
a.inf_str(self.infcx), sty_a,
|
||||
b.inf_str(self.infcx));
|
||||
@ -266,11 +266,11 @@ pub impl Coerce {
|
||||
})))
|
||||
}
|
||||
|
||||
fn coerce_borrowed_fn(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_borrowed_fn(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t)
|
||||
-> CoerceResult {
|
||||
debug!("coerce_borrowed_fn(a=%s, sty_a=%?, b=%s)",
|
||||
a.inf_str(self.infcx), sty_a,
|
||||
b.inf_str(self.infcx));
|
||||
@ -302,22 +302,22 @@ pub impl Coerce {
|
||||
})))
|
||||
}
|
||||
|
||||
fn coerce_from_bare_fn(&self,
|
||||
a: ty::t,
|
||||
fn_ty_a: &ty::BareFnTy,
|
||||
b: ty::t) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_from_bare_fn(&self,
|
||||
a: ty::t,
|
||||
fn_ty_a: &ty::BareFnTy,
|
||||
b: ty::t)
|
||||
-> CoerceResult {
|
||||
do self.unpack_actual_value(b) |sty_b| {
|
||||
self.coerce_from_bare_fn_post_unpack(a, fn_ty_a, b, sty_b)
|
||||
}
|
||||
}
|
||||
|
||||
fn coerce_from_bare_fn_post_unpack(&self,
|
||||
a: ty::t,
|
||||
fn_ty_a: &ty::BareFnTy,
|
||||
b: ty::t,
|
||||
sty_b: &ty::sty) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_from_bare_fn_post_unpack(&self,
|
||||
a: ty::t,
|
||||
fn_ty_a: &ty::BareFnTy,
|
||||
b: ty::t,
|
||||
sty_b: &ty::sty)
|
||||
-> CoerceResult {
|
||||
/*!
|
||||
*
|
||||
* Attempts to coerce from a bare Rust function (`extern
|
||||
@ -346,12 +346,12 @@ pub impl Coerce {
|
||||
Ok(Some(adj))
|
||||
}
|
||||
|
||||
fn coerce_unsafe_ptr(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt) -> CoerceResult
|
||||
{
|
||||
pub fn coerce_unsafe_ptr(&self,
|
||||
a: ty::t,
|
||||
sty_a: &ty::sty,
|
||||
b: ty::t,
|
||||
mt_b: ty::mt)
|
||||
-> CoerceResult {
|
||||
debug!("coerce_unsafe_ptr(a=%s, sty_a=%?, b=%s)",
|
||||
a.inf_str(self.infcx), sty_a,
|
||||
b.inf_str(self.infcx));
|
||||
|
@ -71,13 +71,15 @@ impl LatticeValue for ty::t {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl CombineFields {
|
||||
fn var_sub_var<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
|
||||
&self,
|
||||
a_id: V,
|
||||
b_id: V) -> ures
|
||||
{
|
||||
impl CombineFields {
|
||||
pub fn var_sub_var<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(&self,
|
||||
a_id:
|
||||
V,
|
||||
b_id:
|
||||
V)
|
||||
->
|
||||
ures {
|
||||
/*!
|
||||
*
|
||||
* Make one variable a subtype of another variable. This is a
|
||||
@ -125,12 +127,12 @@ pub impl CombineFields {
|
||||
}
|
||||
|
||||
/// make variable a subtype of T
|
||||
fn var_sub_t<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
|
||||
&self,
|
||||
a_id: V,
|
||||
b: T) -> ures
|
||||
{
|
||||
pub fn var_sub_t<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(&self,
|
||||
a_id: V,
|
||||
b: T)
|
||||
-> ures
|
||||
{
|
||||
/*!
|
||||
*
|
||||
* Make a variable (`a_id`) a subtype of the concrete type `b` */
|
||||
@ -149,12 +151,12 @@ pub impl CombineFields {
|
||||
a_id, a_bounds, b_bounds, node_a.rank)
|
||||
}
|
||||
|
||||
fn t_sub_var<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
|
||||
&self,
|
||||
a: T,
|
||||
b_id: V) -> ures
|
||||
{
|
||||
pub fn t_sub_var<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(&self,
|
||||
a: T,
|
||||
b_id: V)
|
||||
-> ures
|
||||
{
|
||||
/*!
|
||||
*
|
||||
* Make a concrete type (`a`) a subtype of the variable `b_id` */
|
||||
@ -173,13 +175,12 @@ pub impl CombineFields {
|
||||
b_id, a_bounds, b_bounds, node_b.rank)
|
||||
}
|
||||
|
||||
fn merge_bnd<T:Copy + InferStr + LatticeValue>(
|
||||
&self,
|
||||
a: &Bound<T>,
|
||||
b: &Bound<T>,
|
||||
lattice_op: LatticeOp<T>)
|
||||
-> cres<Bound<T>>
|
||||
{
|
||||
pub fn merge_bnd<T:Copy + InferStr + LatticeValue>(&self,
|
||||
a: &Bound<T>,
|
||||
b: &Bound<T>,
|
||||
lattice_op:
|
||||
LatticeOp<T>)
|
||||
-> cres<Bound<T>> {
|
||||
/*!
|
||||
*
|
||||
* Combines two bounds into a more general bound. */
|
||||
@ -201,14 +202,14 @@ pub impl CombineFields {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_var_to_merged_bounds<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy+Eq+ToStr+Vid+UnifyVid<Bounds<T>>>(
|
||||
&self,
|
||||
v_id: V,
|
||||
a: &Bounds<T>,
|
||||
b: &Bounds<T>,
|
||||
rank: uint) -> ures
|
||||
{
|
||||
pub fn set_var_to_merged_bounds<T:Copy + InferStr + LatticeValue,
|
||||
V:Copy+Eq+ToStr+Vid+UnifyVid<Bounds<T>>>(
|
||||
&self,
|
||||
v_id: V,
|
||||
a: &Bounds<T>,
|
||||
b: &Bounds<T>,
|
||||
rank: uint)
|
||||
-> ures {
|
||||
/*!
|
||||
*
|
||||
* Updates the bounds for the variable `v_id` to be the intersection
|
||||
@ -263,11 +264,10 @@ pub impl CombineFields {
|
||||
uok()
|
||||
}
|
||||
|
||||
fn bnds<T:Copy + InferStr + LatticeValue>(
|
||||
&self,
|
||||
a: &Bound<T>,
|
||||
b: &Bound<T>) -> ures
|
||||
{
|
||||
pub fn bnds<T:Copy + InferStr + LatticeValue>(&self,
|
||||
a: &Bound<T>,
|
||||
b: &Bound<T>)
|
||||
-> ures {
|
||||
debug!("bnds(%s <: %s)", a.inf_str(self.infcx),
|
||||
b.inf_str(self.infcx));
|
||||
let _r = indenter();
|
||||
|
@ -34,10 +34,11 @@ use syntax::codemap::span;
|
||||
|
||||
pub struct Lub(CombineFields); // least-upper-bound: common supertype
|
||||
|
||||
pub impl Lub {
|
||||
fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }
|
||||
fn ty_bot(&self, b: ty::t)
|
||||
-> cres<ty::t> { self.bot_ty(b) } // commutative
|
||||
impl Lub {
|
||||
pub fn bot_ty(&self, b: ty::t) -> cres<ty::t> { Ok(b) }
|
||||
pub fn ty_bot(&self, b: ty::t) -> cres<ty::t> {
|
||||
self.bot_ty(b) // commutative
|
||||
}
|
||||
}
|
||||
|
||||
impl Combine for Lub {
|
||||
|
@ -535,24 +535,23 @@ struct Snapshot {
|
||||
region_vars_snapshot: uint,
|
||||
}
|
||||
|
||||
pub impl InferCtxt {
|
||||
fn combine_fields(@mut self,
|
||||
a_is_expected: bool,
|
||||
span: span) -> CombineFields {
|
||||
impl InferCtxt {
|
||||
pub fn combine_fields(@mut self, a_is_expected: bool, span: span)
|
||||
-> CombineFields {
|
||||
CombineFields {infcx: self,
|
||||
a_is_expected: a_is_expected,
|
||||
span: span}
|
||||
}
|
||||
|
||||
fn sub(@mut self, a_is_expected: bool, span: span) -> Sub {
|
||||
pub fn sub(@mut self, a_is_expected: bool, span: span) -> Sub {
|
||||
Sub(self.combine_fields(a_is_expected, span))
|
||||
}
|
||||
|
||||
fn in_snapshot(&self) -> bool {
|
||||
pub fn in_snapshot(&self) -> bool {
|
||||
self.region_vars.in_snapshot()
|
||||
}
|
||||
|
||||
fn start_snapshot(&mut self) -> Snapshot {
|
||||
pub fn start_snapshot(&mut self) -> Snapshot {
|
||||
Snapshot {
|
||||
ty_var_bindings_len:
|
||||
self.ty_var_bindings.bindings.len(),
|
||||
@ -565,7 +564,7 @@ pub impl InferCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn rollback_to(&mut self, snapshot: &Snapshot) {
|
||||
pub fn rollback_to(&mut self, snapshot: &Snapshot) {
|
||||
debug!("rollback!");
|
||||
rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len);
|
||||
|
||||
@ -578,7 +577,7 @@ pub impl InferCtxt {
|
||||
}
|
||||
|
||||
/// Execute `f` and commit the bindings if successful
|
||||
fn commit<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
pub fn commit<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
assert!(!self.in_snapshot());
|
||||
|
||||
debug!("commit()");
|
||||
@ -593,7 +592,7 @@ pub impl InferCtxt {
|
||||
}
|
||||
|
||||
/// Execute `f`, unroll bindings on failure
|
||||
fn try<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
pub fn try<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
debug!("try()");
|
||||
do indent {
|
||||
let snapshot = self.start_snapshot();
|
||||
@ -607,7 +606,7 @@ pub impl InferCtxt {
|
||||
}
|
||||
|
||||
/// Execute `f` then unroll any bindings it creates
|
||||
fn probe<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
pub fn probe<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
|
||||
debug!("probe()");
|
||||
do indent {
|
||||
let snapshot = self.start_snapshot();
|
||||
@ -628,8 +627,8 @@ fn next_simple_var<V:Copy,T:Copy>(
|
||||
return id;
|
||||
}
|
||||
|
||||
pub impl InferCtxt {
|
||||
fn next_ty_var_id(&mut self) -> TyVid {
|
||||
impl InferCtxt {
|
||||
pub fn next_ty_var_id(&mut self) -> TyVid {
|
||||
let id = self.ty_var_counter;
|
||||
self.ty_var_counter += 1;
|
||||
{
|
||||
@ -639,38 +638,40 @@ pub impl InferCtxt {
|
||||
return TyVid(id);
|
||||
}
|
||||
|
||||
fn next_ty_var(&mut self) -> ty::t {
|
||||
pub fn next_ty_var(&mut self) -> ty::t {
|
||||
ty::mk_var(self.tcx, self.next_ty_var_id())
|
||||
}
|
||||
|
||||
fn next_ty_vars(&mut self, n: uint) -> ~[ty::t] {
|
||||
pub fn next_ty_vars(&mut self, n: uint) -> ~[ty::t] {
|
||||
vec::from_fn(n, |_i| self.next_ty_var())
|
||||
}
|
||||
|
||||
fn next_int_var_id(&mut self) -> IntVid {
|
||||
pub fn next_int_var_id(&mut self) -> IntVid {
|
||||
IntVid(next_simple_var(&mut self.int_var_counter,
|
||||
&mut self.int_var_bindings))
|
||||
}
|
||||
|
||||
fn next_int_var(&mut self) -> ty::t {
|
||||
pub fn next_int_var(&mut self) -> ty::t {
|
||||
ty::mk_int_var(self.tcx, self.next_int_var_id())
|
||||
}
|
||||
|
||||
fn next_float_var_id(&mut self) -> FloatVid {
|
||||
pub fn next_float_var_id(&mut self) -> FloatVid {
|
||||
FloatVid(next_simple_var(&mut self.float_var_counter,
|
||||
&mut self.float_var_bindings))
|
||||
}
|
||||
|
||||
fn next_float_var(&mut self) -> ty::t {
|
||||
pub fn next_float_var(&mut self) -> ty::t {
|
||||
ty::mk_float_var(self.tcx, self.next_float_var_id())
|
||||
}
|
||||
|
||||
fn next_region_var_nb(&mut self, span: span) -> ty::Region {
|
||||
pub fn next_region_var_nb(&mut self, span: span) -> ty::Region {
|
||||
ty::re_infer(ty::ReVar(self.region_vars.new_region_var(span)))
|
||||
}
|
||||
|
||||
fn next_region_var_with_lb(&mut self, span: span,
|
||||
lb_region: ty::Region) -> ty::Region {
|
||||
pub fn next_region_var_with_lb(&mut self,
|
||||
span: span,
|
||||
lb_region: ty::Region)
|
||||
-> ty::Region {
|
||||
let region_var = self.next_region_var_nb(span);
|
||||
|
||||
// add lb_region as a lower bound on the newly built variable
|
||||
@ -681,35 +682,36 @@ pub impl InferCtxt {
|
||||
return region_var;
|
||||
}
|
||||
|
||||
fn next_region_var(&mut self, span: span, scope_id: ast::node_id)
|
||||
-> ty::Region {
|
||||
pub fn next_region_var(&mut self, span: span, scope_id: ast::node_id)
|
||||
-> ty::Region {
|
||||
self.next_region_var_with_lb(span, ty::re_scope(scope_id))
|
||||
}
|
||||
|
||||
fn resolve_regions(&mut self) {
|
||||
pub fn resolve_regions(&mut self) {
|
||||
self.region_vars.resolve_regions();
|
||||
}
|
||||
|
||||
fn ty_to_str(@mut self, t: ty::t) -> ~str {
|
||||
pub fn ty_to_str(@mut self, t: ty::t) -> ~str {
|
||||
ty_to_str(self.tcx,
|
||||
self.resolve_type_vars_if_possible(t))
|
||||
}
|
||||
|
||||
fn trait_ref_to_str(@mut self, t: &ty::TraitRef) -> ~str {
|
||||
pub fn trait_ref_to_str(@mut self, t: &ty::TraitRef) -> ~str {
|
||||
let t = self.resolve_type_vars_in_trait_ref_if_possible(t);
|
||||
trait_ref_to_str(self.tcx, &t)
|
||||
}
|
||||
|
||||
fn resolve_type_vars_if_possible(@mut self, typ: ty::t) -> ty::t {
|
||||
pub fn resolve_type_vars_if_possible(@mut self, typ: ty::t) -> ty::t {
|
||||
match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) {
|
||||
result::Ok(new_type) => new_type,
|
||||
result::Err(_) => typ
|
||||
}
|
||||
}
|
||||
fn resolve_type_vars_in_trait_ref_if_possible(@mut self,
|
||||
trait_ref: &ty::TraitRef)
|
||||
-> ty::TraitRef
|
||||
{
|
||||
|
||||
pub fn resolve_type_vars_in_trait_ref_if_possible(@mut self,
|
||||
trait_ref:
|
||||
&ty::TraitRef)
|
||||
-> ty::TraitRef {
|
||||
// make up a dummy type just to reuse/abuse the resolve machinery
|
||||
let dummy0 = ty::mk_trait(self.tcx,
|
||||
trait_ref.def_id,
|
||||
@ -732,18 +734,22 @@ pub impl InferCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn type_error_message_str(@mut self,
|
||||
sp: span,
|
||||
mk_msg: &fn(Option<~str>, ~str) -> ~str,
|
||||
actual_ty: ~str, err: Option<&ty::type_err>) {
|
||||
pub fn type_error_message_str(@mut self,
|
||||
sp: span,
|
||||
mk_msg: &fn(Option<~str>, ~str) -> ~str,
|
||||
actual_ty: ~str,
|
||||
err: Option<&ty::type_err>) {
|
||||
self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err)
|
||||
}
|
||||
|
||||
fn type_error_message_str_with_expected(@mut self,
|
||||
sp: span,
|
||||
mk_msg: &fn(Option<~str>, ~str) -> ~str,
|
||||
expected_ty: Option<ty::t>, actual_ty: ~str,
|
||||
err: Option<&ty::type_err>) {
|
||||
pub fn type_error_message_str_with_expected(@mut self,
|
||||
sp: span,
|
||||
mk_msg:
|
||||
&fn(Option<~str>, ~str) ->
|
||||
~str,
|
||||
expected_ty: Option<ty::t>,
|
||||
actual_ty: ~str,
|
||||
err: Option<&ty::type_err>) {
|
||||
debug!("hi! expected_ty = %?, actual_ty = %s", expected_ty, actual_ty);
|
||||
|
||||
let error_str = err.map_default(~"", |t_err|
|
||||
@ -766,11 +772,11 @@ pub impl InferCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn type_error_message(@mut self,
|
||||
sp: span,
|
||||
mk_msg: &fn(~str) -> ~str,
|
||||
actual_ty: ty::t,
|
||||
err: Option<&ty::type_err>) {
|
||||
pub fn type_error_message(@mut self,
|
||||
sp: span,
|
||||
mk_msg: &fn(~str) -> ~str,
|
||||
actual_ty: ty::t,
|
||||
err: Option<&ty::type_err>) {
|
||||
let actual_ty = self.resolve_type_vars_if_possible(actual_ty);
|
||||
|
||||
// Don't report an error if actual type is ty_err.
|
||||
@ -781,8 +787,11 @@ pub impl InferCtxt {
|
||||
self.type_error_message_str(sp, |_e, a| { mk_msg(a) }, self.ty_to_str(actual_ty), err);
|
||||
}
|
||||
|
||||
fn report_mismatched_types(@mut self, sp: span, e: ty::t, a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
pub fn report_mismatched_types(@mut self,
|
||||
sp: span,
|
||||
e: ty::t,
|
||||
a: ty::t,
|
||||
err: &ty::type_err) {
|
||||
let resolved_expected =
|
||||
self.resolve_type_vars_if_possible(e);
|
||||
let mk_msg = match ty::get(resolved_expected).sty {
|
||||
@ -799,10 +808,11 @@ pub impl InferCtxt {
|
||||
self.type_error_message(sp, mk_msg, a, Some(err));
|
||||
}
|
||||
|
||||
fn replace_bound_regions_with_fresh_regions(&mut self,
|
||||
span: span,
|
||||
fsig: &ty::FnSig)
|
||||
-> (ty::FnSig, isr_alist) {
|
||||
pub fn replace_bound_regions_with_fresh_regions(&mut self,
|
||||
span: span,
|
||||
fsig: &ty::FnSig)
|
||||
-> (ty::FnSig,
|
||||
isr_alist) {
|
||||
let(isr, _, fn_sig) =
|
||||
replace_bound_regions_in_fn_sig(self.tcx, @Nil, None, fsig, |br| {
|
||||
// N.B.: The name of the bound region doesn't have anything to
|
||||
|
@ -643,12 +643,12 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl RegionVarBindings {
|
||||
fn in_snapshot(&self) -> bool {
|
||||
impl RegionVarBindings {
|
||||
pub fn in_snapshot(&self) -> bool {
|
||||
self.undo_log.len() > 0
|
||||
}
|
||||
|
||||
fn start_snapshot(&mut self) -> uint {
|
||||
pub fn start_snapshot(&mut self) -> uint {
|
||||
debug!("RegionVarBindings: snapshot()=%u", self.undo_log.len());
|
||||
if self.in_snapshot() {
|
||||
self.undo_log.len()
|
||||
@ -658,14 +658,14 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn commit(&mut self) {
|
||||
pub fn commit(&mut self) {
|
||||
debug!("RegionVarBindings: commit()");
|
||||
while self.undo_log.len() > 0 {
|
||||
self.undo_log.pop();
|
||||
}
|
||||
}
|
||||
|
||||
fn rollback_to(&mut self, snapshot: uint) {
|
||||
pub fn rollback_to(&mut self, snapshot: uint) {
|
||||
debug!("RegionVarBindings: rollback_to(%u)", snapshot);
|
||||
while self.undo_log.len() > snapshot {
|
||||
let undo_item = self.undo_log.pop();
|
||||
@ -689,11 +689,11 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn num_vars(&mut self) -> uint {
|
||||
pub fn num_vars(&mut self) -> uint {
|
||||
self.var_spans.len()
|
||||
}
|
||||
|
||||
fn new_region_var(&mut self, span: span) -> RegionVid {
|
||||
pub fn new_region_var(&mut self, span: span) -> RegionVid {
|
||||
let id = self.num_vars();
|
||||
self.var_spans.push(span);
|
||||
let vid = RegionVid { id: id };
|
||||
@ -705,13 +705,13 @@ pub impl RegionVarBindings {
|
||||
return vid;
|
||||
}
|
||||
|
||||
fn new_skolemized(&mut self, br: ty::bound_region) -> Region {
|
||||
pub fn new_skolemized(&mut self, br: ty::bound_region) -> Region {
|
||||
let sc = self.skolemization_count;
|
||||
self.skolemization_count += 1;
|
||||
re_infer(ReSkolemized(sc, br))
|
||||
}
|
||||
|
||||
fn new_bound(&mut self) -> Region {
|
||||
pub fn new_bound(&mut self) -> Region {
|
||||
// Creates a fresh bound variable for use in GLB computations.
|
||||
// See discussion of GLB computation in the large comment at
|
||||
// the top of this file for more details.
|
||||
@ -731,7 +731,7 @@ pub impl RegionVarBindings {
|
||||
re_bound(br_fresh(sc))
|
||||
}
|
||||
|
||||
fn add_constraint(&mut self, constraint: Constraint, span: span) {
|
||||
pub fn add_constraint(&mut self, constraint: Constraint, span: span) {
|
||||
// cannot add constraints once regions are resolved
|
||||
assert!(self.values.is_empty());
|
||||
|
||||
@ -744,10 +744,8 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_subregion(&mut self,
|
||||
span: span,
|
||||
sub: Region,
|
||||
sup: Region) -> cres<()> {
|
||||
pub fn make_subregion(&mut self, span: span, sub: Region, sup: Region)
|
||||
-> cres<()> {
|
||||
// cannot add constraints once regions are resolved
|
||||
assert!(self.values.is_empty());
|
||||
|
||||
@ -785,11 +783,8 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn lub_regions(&mut self,
|
||||
span: span,
|
||||
a: Region,
|
||||
b: Region)
|
||||
-> cres<Region> {
|
||||
pub fn lub_regions(&mut self, span: span, a: Region, b: Region)
|
||||
-> cres<Region> {
|
||||
// cannot add constraints once regions are resolved
|
||||
assert!(self.values.is_empty());
|
||||
|
||||
@ -811,11 +806,8 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn glb_regions(&mut self,
|
||||
span: span,
|
||||
a: Region,
|
||||
b: Region)
|
||||
-> cres<Region> {
|
||||
pub fn glb_regions(&mut self, span: span, a: Region, b: Region)
|
||||
-> cres<Region> {
|
||||
// cannot add constraints once regions are resolved
|
||||
assert!(self.values.is_empty());
|
||||
|
||||
@ -838,7 +830,7 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
|
||||
pub fn resolve_var(&mut self, rid: RegionVid) -> ty::Region {
|
||||
if self.values.is_empty() {
|
||||
self.tcx.sess.span_bug(
|
||||
self.var_spans[rid.to_uint()],
|
||||
@ -864,15 +856,15 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn combine_vars(&mut self,
|
||||
t: CombineMapType,
|
||||
a: Region,
|
||||
b: Region,
|
||||
span: span,
|
||||
relate: &fn(this: &mut RegionVarBindings,
|
||||
old_r: Region,
|
||||
new_r: Region) -> cres<()>)
|
||||
-> cres<Region> {
|
||||
pub fn combine_vars(&mut self,
|
||||
t: CombineMapType,
|
||||
a: Region,
|
||||
b: Region,
|
||||
span: span,
|
||||
relate: &fn(this: &mut RegionVarBindings,
|
||||
old_r: Region,
|
||||
new_r: Region) -> cres<()>)
|
||||
-> cres<Region> {
|
||||
let vars = TwoRegions { a: a, b: b };
|
||||
let c;
|
||||
{
|
||||
@ -906,9 +898,8 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn vars_created_since_snapshot(&mut self,
|
||||
snapshot: uint)
|
||||
-> ~[RegionVid] {
|
||||
pub fn vars_created_since_snapshot(&mut self, snapshot: uint)
|
||||
-> ~[RegionVid] {
|
||||
do vec::build |push| {
|
||||
for uint::range(snapshot, self.undo_log.len()) |i| {
|
||||
match self.undo_log[i] {
|
||||
@ -919,7 +910,7 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] {
|
||||
pub fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] {
|
||||
/*!
|
||||
*
|
||||
* Computes all regions that have been related to `r0` in any
|
||||
@ -1003,14 +994,14 @@ pub impl RegionVarBindings {
|
||||
constraints, assuming such values can be found; if they cannot,
|
||||
errors are reported.
|
||||
*/
|
||||
fn resolve_regions(&mut self) {
|
||||
pub fn resolve_regions(&mut self) {
|
||||
debug!("RegionVarBindings: resolve_regions()");
|
||||
let v = self.infer_variable_values();
|
||||
self.values.put_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
priv impl RegionVarBindings {
|
||||
impl RegionVarBindings {
|
||||
fn is_subregion_of(&self, sub: Region, sup: Region) -> bool {
|
||||
let rm = self.tcx.region_maps;
|
||||
rm.is_subregion_of(sub, sup)
|
||||
@ -1266,15 +1257,15 @@ struct SpannedRegion {
|
||||
span: span,
|
||||
}
|
||||
|
||||
pub impl RegionVarBindings {
|
||||
fn infer_variable_values(&mut self) -> ~[GraphNodeValue] {
|
||||
impl RegionVarBindings {
|
||||
pub fn infer_variable_values(&mut self) -> ~[GraphNodeValue] {
|
||||
let mut graph = self.construct_graph();
|
||||
self.expansion(&mut graph);
|
||||
self.contraction(&mut graph);
|
||||
self.extract_values_and_report_conflicts(&graph)
|
||||
}
|
||||
|
||||
fn construct_graph(&mut self) -> Graph {
|
||||
pub fn construct_graph(&mut self) -> Graph {
|
||||
let num_vars = self.num_vars();
|
||||
let num_edges = self.constraints.len();
|
||||
|
||||
@ -1339,7 +1330,7 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn expansion(&mut self, graph: &mut Graph) {
|
||||
pub fn expansion(&mut self, graph: &mut Graph) {
|
||||
do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| {
|
||||
match edge.constraint {
|
||||
ConstrainRegSubVar(a_region, b_vid) => {
|
||||
@ -1363,11 +1354,11 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_node(&mut self,
|
||||
a_region: Region,
|
||||
b_vid: RegionVid,
|
||||
b_node: &mut GraphNode)
|
||||
-> bool {
|
||||
pub fn expand_node(&mut self,
|
||||
a_region: Region,
|
||||
b_vid: RegionVid,
|
||||
b_node: &mut GraphNode)
|
||||
-> bool {
|
||||
debug!("expand_node(%?, %? == %?)",
|
||||
a_region, b_vid, b_node.value);
|
||||
|
||||
@ -1399,7 +1390,7 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn contraction(&mut self, graph: &mut Graph) {
|
||||
pub fn contraction(&mut self, graph: &mut Graph) {
|
||||
do iterate_until_fixed_point(~"Contraction", graph) |nodes, edge| {
|
||||
match edge.constraint {
|
||||
ConstrainRegSubVar(*) => {
|
||||
@ -1423,11 +1414,11 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn contract_node(&mut self,
|
||||
a_vid: RegionVid,
|
||||
a_node: &mut GraphNode,
|
||||
b_region: Region)
|
||||
-> bool {
|
||||
pub fn contract_node(&mut self,
|
||||
a_vid: RegionVid,
|
||||
a_node: &mut GraphNode,
|
||||
b_region: Region)
|
||||
-> bool {
|
||||
debug!("contract_node(%? == %?/%?, %?)",
|
||||
a_vid, a_node.value, a_node.classification, b_region);
|
||||
|
||||
@ -1495,10 +1486,8 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_values_and_report_conflicts(
|
||||
&mut self,
|
||||
graph: &Graph) -> ~[GraphNodeValue]
|
||||
{
|
||||
pub fn extract_values_and_report_conflicts(&mut self, graph: &Graph)
|
||||
-> ~[GraphNodeValue] {
|
||||
debug!("extract_values_and_report_conflicts()");
|
||||
|
||||
// This is the best way that I have found to suppress
|
||||
@ -1567,10 +1556,10 @@ pub impl RegionVarBindings {
|
||||
})
|
||||
}
|
||||
|
||||
fn report_error_for_expanding_node(&mut self,
|
||||
graph: &Graph,
|
||||
dup_vec: &mut [uint],
|
||||
node_idx: RegionVid) {
|
||||
pub fn report_error_for_expanding_node(&mut self,
|
||||
graph: &Graph,
|
||||
dup_vec: &mut [uint],
|
||||
node_idx: RegionVid) {
|
||||
// Errors in expanding nodes result from a lower-bound that is
|
||||
// not contained by an upper-bound.
|
||||
let (lower_bounds, lower_dup) =
|
||||
@ -1626,10 +1615,10 @@ pub impl RegionVarBindings {
|
||||
upper_bounds.map(|x| x.region).repr(self.tcx)));
|
||||
}
|
||||
|
||||
fn report_error_for_contracting_node(&mut self,
|
||||
graph: &Graph,
|
||||
dup_vec: &mut [uint],
|
||||
node_idx: RegionVid) {
|
||||
pub fn report_error_for_contracting_node(&mut self,
|
||||
graph: &Graph,
|
||||
dup_vec: &mut [uint],
|
||||
node_idx: RegionVid) {
|
||||
// Errors in contracting nodes result from two upper-bounds
|
||||
// that have no intersection.
|
||||
let (upper_bounds, dup_found) =
|
||||
@ -1685,12 +1674,12 @@ pub impl RegionVarBindings {
|
||||
upper_bounds.map(|x| x.region).repr(self.tcx)));
|
||||
}
|
||||
|
||||
fn collect_concrete_regions(&mut self,
|
||||
graph: &Graph,
|
||||
orig_node_idx: RegionVid,
|
||||
dir: Direction,
|
||||
dup_vec: &mut [uint])
|
||||
-> (~[SpannedRegion], bool) {
|
||||
pub fn collect_concrete_regions(&mut self,
|
||||
graph: &Graph,
|
||||
orig_node_idx: RegionVid,
|
||||
dir: Direction,
|
||||
dup_vec: &mut [uint])
|
||||
-> (~[SpannedRegion], bool) {
|
||||
struct WalkState {
|
||||
set: HashSet<RegionVid>,
|
||||
stack: ~[RegionVid],
|
||||
@ -1766,11 +1755,12 @@ pub impl RegionVarBindings {
|
||||
}
|
||||
}
|
||||
|
||||
fn each_edge(&mut self,
|
||||
graph: &Graph,
|
||||
node_idx: RegionVid,
|
||||
dir: Direction,
|
||||
op: &fn(edge: &GraphEdge) -> bool) -> bool {
|
||||
pub fn each_edge(&mut self,
|
||||
graph: &Graph,
|
||||
node_idx: RegionVid,
|
||||
dir: Direction,
|
||||
op: &fn(edge: &GraphEdge) -> bool)
|
||||
-> bool {
|
||||
let mut edge_idx =
|
||||
graph.nodes[node_idx.to_uint()].head_edge[dir as uint];
|
||||
while edge_idx != uint::max_value {
|
||||
|
@ -98,12 +98,12 @@ pub fn resolver(infcx: @mut InferCtxt, modes: uint) -> ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl ResolveState {
|
||||
fn should(&mut self, mode: uint) -> bool {
|
||||
impl ResolveState {
|
||||
pub fn should(&mut self, mode: uint) -> bool {
|
||||
(self.modes & mode) == mode
|
||||
}
|
||||
|
||||
fn resolve_type_chk(&mut self, typ: ty::t) -> fres<ty::t> {
|
||||
pub fn resolve_type_chk(&mut self, typ: ty::t) -> fres<ty::t> {
|
||||
self.err = None;
|
||||
|
||||
debug!("Resolving %s (modes=%x)",
|
||||
@ -128,7 +128,8 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_region_chk(&mut self, orig: ty::Region) -> fres<ty::Region> {
|
||||
pub fn resolve_region_chk(&mut self, orig: ty::Region)
|
||||
-> fres<ty::Region> {
|
||||
self.err = None;
|
||||
let resolved = indent(|| self.resolve_region(orig) );
|
||||
match self.err {
|
||||
@ -137,7 +138,7 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_type(&mut self, typ: ty::t) -> ty::t {
|
||||
pub fn resolve_type(&mut self, typ: ty::t) -> ty::t {
|
||||
debug!("resolve_type(%s)", typ.inf_str(self.infcx));
|
||||
let _i = indenter();
|
||||
|
||||
@ -179,7 +180,7 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_region(&mut self, orig: ty::Region) -> ty::Region {
|
||||
pub fn resolve_region(&mut self, orig: ty::Region) -> ty::Region {
|
||||
debug!("Resolve_region(%s)", orig.inf_str(self.infcx));
|
||||
match orig {
|
||||
ty::re_infer(ty::ReVar(rid)) => self.resolve_region_var(rid),
|
||||
@ -187,14 +188,14 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_region_var(&mut self, rid: RegionVid) -> ty::Region {
|
||||
pub fn resolve_region_var(&mut self, rid: RegionVid) -> ty::Region {
|
||||
if !self.should(resolve_rvar) {
|
||||
return ty::re_infer(ty::ReVar(rid));
|
||||
}
|
||||
self.infcx.region_vars.resolve_var(rid)
|
||||
}
|
||||
|
||||
fn assert_not_rvar(&mut self, rid: RegionVid, r: ty::Region) {
|
||||
pub fn assert_not_rvar(&mut self, rid: RegionVid, r: ty::Region) {
|
||||
match r {
|
||||
ty::re_infer(ty::ReVar(rid2)) => {
|
||||
self.err = Some(region_var_bound_by_region_var(rid, rid2));
|
||||
@ -203,7 +204,7 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t {
|
||||
pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t {
|
||||
if vec::contains(self.v_seen, &vid) {
|
||||
self.err = Some(cyclic_ty(vid));
|
||||
return ty::mk_var(self.infcx.tcx, vid);
|
||||
@ -237,7 +238,7 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_int_var(&mut self, vid: IntVid) -> ty::t {
|
||||
pub fn resolve_int_var(&mut self, vid: IntVid) -> ty::t {
|
||||
if !self.should(resolve_ivar) {
|
||||
return ty::mk_int_var(self.infcx.tcx, vid);
|
||||
}
|
||||
@ -260,7 +261,7 @@ pub impl ResolveState {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t {
|
||||
pub fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t {
|
||||
if !self.should(resolve_fvar) {
|
||||
return ty::mk_float_var(self.infcx.tcx, vid);
|
||||
}
|
||||
|
@ -77,15 +77,15 @@ fn setup_env(test_name: &str, source_string: &str) -> Env {
|
||||
err_messages: messages};
|
||||
}
|
||||
|
||||
pub impl Env {
|
||||
fn create_region_hierarchy(&self, rh: &RH) {
|
||||
impl Env {
|
||||
pub fn create_region_hierarchy(&self, rh: &RH) {
|
||||
for rh.sub.each |child_rh| {
|
||||
self.create_region_hierarchy(child_rh);
|
||||
self.tcx.region_map.insert(child_rh.id, rh.id);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_simple_region_hierarchy(&self) {
|
||||
pub fn create_simple_region_hierarchy(&self) {
|
||||
// creates a region hierarchy where 1 is root, 10 and 11 are
|
||||
// children of 1, etc
|
||||
self.create_region_hierarchy(
|
||||
@ -96,7 +96,7 @@ pub impl Env {
|
||||
sub: &[]}]});
|
||||
}
|
||||
|
||||
fn lookup_item(&self, names: &[~str]) -> ast::node_id {
|
||||
pub fn lookup_item(&self, names: &[~str]) -> ast::node_id {
|
||||
return match search_mod(self, &self.crate.node.module, 0, names) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
@ -144,14 +144,14 @@ pub impl Env {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_subtype(&self, a: ty::t, b: ty::t) -> bool {
|
||||
pub fn is_subtype(&self, a: ty::t, b: ty::t) -> bool {
|
||||
match infer::can_mk_subty(self.infcx, a, b) {
|
||||
Ok(_) => true,
|
||||
Err(_) => false
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_subtype(&self, a: ty::t, b: ty::t) {
|
||||
pub fn assert_subtype(&self, a: ty::t, b: ty::t) {
|
||||
if !self.is_subtype(a, b) {
|
||||
fail!("%s is not a subtype of %s, but it should be",
|
||||
self.ty_to_str(a),
|
||||
@ -159,7 +159,7 @@ pub impl Env {
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_not_subtype(&self, a: ty::t, b: ty::t) {
|
||||
pub fn assert_not_subtype(&self, a: ty::t, b: ty::t) {
|
||||
if self.is_subtype(a, b) {
|
||||
fail!("%s is a subtype of %s, but it shouldn't be",
|
||||
self.ty_to_str(a),
|
||||
@ -167,21 +167,21 @@ pub impl Env {
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_strict_subtype(&self, a: ty::t, b: ty::t) {
|
||||
pub fn assert_strict_subtype(&self, a: ty::t, b: ty::t) {
|
||||
self.assert_subtype(a, b);
|
||||
self.assert_not_subtype(b, a);
|
||||
}
|
||||
|
||||
fn assert_eq(&self, a: ty::t, b: ty::t) {
|
||||
pub fn assert_eq(&self, a: ty::t, b: ty::t) {
|
||||
self.assert_subtype(a, b);
|
||||
self.assert_subtype(b, a);
|
||||
}
|
||||
|
||||
fn ty_to_str(&self, a: ty::t) -> ~str {
|
||||
pub fn ty_to_str(&self, a: ty::t) -> ~str {
|
||||
ty_to_str(self.tcx, a)
|
||||
}
|
||||
|
||||
fn t_fn(&self, input_tys: &[ty::t], output_ty: ty::t) -> ty::t {
|
||||
pub fn t_fn(&self, input_tys: &[ty::t], output_ty: ty::t) -> ty::t {
|
||||
let inputs = input_tys.map(|t| {mode: ast::expl(ast::by_copy),
|
||||
ty: *t});
|
||||
ty::mk_fn(self.tcx, FnTyBase {
|
||||
@ -195,34 +195,34 @@ pub impl Env {
|
||||
})
|
||||
}
|
||||
|
||||
fn t_int(&self) -> ty::t {
|
||||
pub fn t_int(&self) -> ty::t {
|
||||
ty::mk_int(self.tcx)
|
||||
}
|
||||
|
||||
fn t_rptr_bound(&self, id: uint) -> ty::t {
|
||||
pub fn t_rptr_bound(&self, id: uint) -> ty::t {
|
||||
ty::mk_imm_rptr(self.tcx, ty::re_bound(ty::br_anon(id)), self.t_int())
|
||||
}
|
||||
|
||||
fn t_rptr_scope(&self, id: ast::node_id) -> ty::t {
|
||||
pub fn t_rptr_scope(&self, id: ast::node_id) -> ty::t {
|
||||
ty::mk_imm_rptr(self.tcx, ty::re_scope(id), self.t_int())
|
||||
}
|
||||
|
||||
fn t_rptr_free(&self, nid: ast::node_id, id: uint) -> ty::t {
|
||||
pub fn t_rptr_free(&self, nid: ast::node_id, id: uint) -> ty::t {
|
||||
ty::mk_imm_rptr(self.tcx,
|
||||
ty::re_free(ty::FreeRegion {scope_id: nid,
|
||||
bound_region: ty::br_anon(id)}),
|
||||
self.t_int())
|
||||
}
|
||||
|
||||
fn t_rptr_static(&self) -> ty::t {
|
||||
pub fn t_rptr_static(&self) -> ty::t {
|
||||
ty::mk_imm_rptr(self.tcx, ty::re_static, self.t_int())
|
||||
}
|
||||
|
||||
fn lub() -> Lub { Lub(self.infcx.combine_fields(true, dummy_sp())) }
|
||||
pub fn lub() -> Lub { Lub(self.infcx.combine_fields(true, dummy_sp())) }
|
||||
|
||||
fn glb() -> Glb { Glb(self.infcx.combine_fields(true, dummy_sp())) }
|
||||
pub fn glb() -> Glb { Glb(self.infcx.combine_fields(true, dummy_sp())) }
|
||||
|
||||
fn resolve_regions(exp_count: uint) {
|
||||
pub fn resolve_regions(exp_count: uint) {
|
||||
debug!("resolve_regions(%u)", exp_count);
|
||||
|
||||
self.infcx.resolve_regions();
|
||||
@ -237,7 +237,7 @@ pub impl Env {
|
||||
}
|
||||
|
||||
/// Checks that `LUB(t1,t2) == t_lub`
|
||||
fn check_lub(&self, t1: ty::t, t2: ty::t, t_lub: ty::t) {
|
||||
pub fn check_lub(&self, t1: ty::t, t2: ty::t, t_lub: ty::t) {
|
||||
match self.lub().tys(t1, t2) {
|
||||
Err(e) => {
|
||||
fail!("Unexpected error computing LUB: %?", e)
|
||||
@ -255,7 +255,7 @@ pub impl Env {
|
||||
}
|
||||
|
||||
/// Checks that `GLB(t1,t2) == t_glb`
|
||||
fn check_glb(&self, t1: ty::t, t2: ty::t, t_glb: ty::t) {
|
||||
pub fn check_glb(&self, t1: ty::t, t2: ty::t, t_glb: ty::t) {
|
||||
debug!("check_glb(t1=%s, t2=%s, t_glb=%s)",
|
||||
self.ty_to_str(t1),
|
||||
self.ty_to_str(t2),
|
||||
@ -277,7 +277,7 @@ pub impl Env {
|
||||
}
|
||||
|
||||
/// Checks that `LUB(t1,t2)` is undefined
|
||||
fn check_no_lub(&self, t1: ty::t, t2: ty::t) {
|
||||
pub fn check_no_lub(&self, t1: ty::t, t2: ty::t) {
|
||||
match self.lub().tys(t1, t2) {
|
||||
Err(_) => {}
|
||||
Ok(t) => {
|
||||
@ -287,7 +287,7 @@ pub impl Env {
|
||||
}
|
||||
|
||||
/// Checks that `GLB(t1,t2)` is undefined
|
||||
fn check_no_glb(&self, t1: ty::t, t2: ty::t) {
|
||||
pub fn check_no_glb(&self, t1: ty::t, t2: ty::t) {
|
||||
match self.glb().tys(t1, t2) {
|
||||
Err(_) => {}
|
||||
Ok(t) => {
|
||||
|
@ -40,11 +40,9 @@ pub trait UnifyVid<T> {
|
||||
-> &'v mut ValsAndBindings<Self, T>;
|
||||
}
|
||||
|
||||
pub impl InferCtxt {
|
||||
fn get<T:Copy, V:Copy+Eq+Vid+UnifyVid<T>>(
|
||||
&mut self,
|
||||
vid: V) -> Node<V, T>
|
||||
{
|
||||
impl InferCtxt {
|
||||
pub fn get<T:Copy, V:Copy+Eq+Vid+UnifyVid<T>>(&mut self, vid: V)
|
||||
-> Node<V, T> {
|
||||
/*!
|
||||
*
|
||||
* Find the root node for `vid`. This uses the standard
|
||||
@ -86,10 +84,10 @@ pub impl InferCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn set<T:Copy + InferStr,V:Copy + Vid + ToStr + UnifyVid<T>>(
|
||||
&mut self,
|
||||
vid: V,
|
||||
new_v: VarValue<V, T>) {
|
||||
pub fn set<T:Copy + InferStr,
|
||||
V:Copy + Vid + ToStr + UnifyVid<T>>(&mut self,
|
||||
vid: V,
|
||||
new_v: VarValue<V, T>) {
|
||||
/*!
|
||||
*
|
||||
* Sets the value for `vid` to `new_v`. `vid` MUST be a root node!
|
||||
@ -106,11 +104,11 @@ pub impl InferCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn unify<T:Copy + InferStr,V:Copy + Vid + ToStr + UnifyVid<T>>(
|
||||
&mut self,
|
||||
node_a: &Node<V, T>,
|
||||
node_b: &Node<V, T>) -> (V, uint)
|
||||
{
|
||||
pub fn unify<T:Copy + InferStr,
|
||||
V:Copy + Vid + ToStr + UnifyVid<T>>(&mut self,
|
||||
node_a: &Node<V, T>,
|
||||
node_b: &Node<V, T>)
|
||||
-> (V, uint) {
|
||||
// Rank optimization: if you don't know what it is, check
|
||||
// out <http://en.wikipedia.org/wiki/Disjoint-set_data_structure>
|
||||
|
||||
@ -159,14 +157,14 @@ pub fn mk_err<T:SimplyUnifiable>(a_is_expected: bool,
|
||||
}
|
||||
}
|
||||
|
||||
pub impl InferCtxt {
|
||||
fn simple_vars<T:Copy + Eq + InferStr + SimplyUnifiable,
|
||||
V:Copy + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
|
||||
&mut self,
|
||||
a_is_expected: bool,
|
||||
a_id: V,
|
||||
b_id: V)
|
||||
-> ures {
|
||||
impl InferCtxt {
|
||||
pub fn simple_vars<T:Copy+Eq+InferStr+SimplyUnifiable,
|
||||
V:Copy+Eq+Vid+ToStr+UnifyVid<Option<T>>>(&mut self,
|
||||
a_is_expected:
|
||||
bool,
|
||||
a_id: V,
|
||||
b_id: V)
|
||||
-> ures {
|
||||
/*!
|
||||
*
|
||||
* Unifies two simple variables. Because simple variables do
|
||||
@ -198,13 +196,13 @@ pub impl InferCtxt {
|
||||
return uok();
|
||||
}
|
||||
|
||||
fn simple_var_t<T:Copy + Eq + InferStr + SimplyUnifiable,
|
||||
V:Copy + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
|
||||
&mut self,
|
||||
a_is_expected: bool,
|
||||
a_id: V,
|
||||
b: T)
|
||||
-> ures {
|
||||
pub fn simple_var_t<T:Copy+Eq+InferStr+SimplyUnifiable,
|
||||
V:Copy+Eq+Vid+ToStr+UnifyVid<Option<T>>>(&mut self,
|
||||
a_is_expected
|
||||
: bool,
|
||||
a_id: V,
|
||||
b: T)
|
||||
-> ures {
|
||||
/*!
|
||||
*
|
||||
* Sets the value of the variable `a_id` to `b`. Because
|
||||
|
@ -26,40 +26,40 @@ fn bit<E:CLike>(e: E) -> uint {
|
||||
1 << e.to_uint()
|
||||
}
|
||||
|
||||
pub impl<E:CLike> EnumSet<E> {
|
||||
fn empty() -> EnumSet<E> {
|
||||
impl<E:CLike> EnumSet<E> {
|
||||
pub fn empty() -> EnumSet<E> {
|
||||
EnumSet {bits: 0}
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.bits == 0
|
||||
}
|
||||
|
||||
fn intersects(&self, e: EnumSet<E>) -> bool {
|
||||
pub fn intersects(&self, e: EnumSet<E>) -> bool {
|
||||
(self.bits & e.bits) != 0
|
||||
}
|
||||
|
||||
fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
EnumSet {bits: self.bits & e.bits}
|
||||
}
|
||||
|
||||
fn contains(&self, e: EnumSet<E>) -> bool {
|
||||
pub fn contains(&self, e: EnumSet<E>) -> bool {
|
||||
(self.bits & e.bits) == e.bits
|
||||
}
|
||||
|
||||
fn union(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
pub fn union(&self, e: EnumSet<E>) -> EnumSet<E> {
|
||||
EnumSet {bits: self.bits | e.bits}
|
||||
}
|
||||
|
||||
fn add(&mut self, e: E) {
|
||||
pub fn add(&mut self, e: E) {
|
||||
self.bits |= bit(e);
|
||||
}
|
||||
|
||||
fn contains_elem(&self, e: E) -> bool {
|
||||
pub fn contains_elem(&self, e: E) -> bool {
|
||||
(self.bits & bit(e)) != 0
|
||||
}
|
||||
|
||||
fn each(&self, f: &fn(E) -> bool) -> bool {
|
||||
pub fn each(&self, f: &fn(E) -> bool) -> bool {
|
||||
let mut bits = self.bits;
|
||||
let mut index = 0;
|
||||
while bits != 0 {
|
||||
|
@ -172,8 +172,8 @@ pub struct IndexEntry {
|
||||
link: ~str
|
||||
}
|
||||
|
||||
pub impl Doc {
|
||||
fn CrateDoc(&self) -> CrateDoc {
|
||||
impl Doc {
|
||||
pub fn CrateDoc(&self) -> CrateDoc {
|
||||
vec::foldl(None, self.pages, |_m, page| {
|
||||
match copy *page {
|
||||
doc::CratePage(doc) => Some(doc),
|
||||
@ -182,14 +182,14 @@ pub impl Doc {
|
||||
}).get()
|
||||
}
|
||||
|
||||
fn cratemod(&self) -> ModDoc {
|
||||
pub fn cratemod(&self) -> ModDoc {
|
||||
copy self.CrateDoc().topmod
|
||||
}
|
||||
}
|
||||
|
||||
/// Some helper methods on ModDoc, mostly for testing
|
||||
pub impl ModDoc {
|
||||
fn mods(&self) -> ~[ModDoc] {
|
||||
impl ModDoc {
|
||||
pub fn mods(&self) -> ~[ModDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
ModTag(ModDoc) => Some(ModDoc),
|
||||
@ -198,7 +198,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn nmods(&self) -> ~[NmodDoc] {
|
||||
pub fn nmods(&self) -> ~[NmodDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
NmodTag(nModDoc) => Some(nModDoc),
|
||||
@ -207,7 +207,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn fns(&self) -> ~[FnDoc] {
|
||||
pub fn fns(&self) -> ~[FnDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
FnTag(FnDoc) => Some(FnDoc),
|
||||
@ -216,7 +216,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn consts(&self) -> ~[ConstDoc] {
|
||||
pub fn consts(&self) -> ~[ConstDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
ConstTag(ConstDoc) => Some(ConstDoc),
|
||||
@ -225,7 +225,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn enums(&self) -> ~[EnumDoc] {
|
||||
pub fn enums(&self) -> ~[EnumDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
EnumTag(EnumDoc) => Some(EnumDoc),
|
||||
@ -234,7 +234,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn traits(&self) -> ~[TraitDoc] {
|
||||
pub fn traits(&self) -> ~[TraitDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
TraitTag(TraitDoc) => Some(TraitDoc),
|
||||
@ -243,7 +243,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn impls(&self) -> ~[ImplDoc] {
|
||||
pub fn impls(&self) -> ~[ImplDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
ImplTag(ImplDoc) => Some(ImplDoc),
|
||||
@ -252,7 +252,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn types(&self) -> ~[TyDoc] {
|
||||
pub fn types(&self) -> ~[TyDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
TyTag(TyDoc) => Some(TyDoc),
|
||||
@ -261,7 +261,7 @@ pub impl ModDoc {
|
||||
}
|
||||
}
|
||||
|
||||
fn structs(&self) -> ~[StructDoc] {
|
||||
pub fn structs(&self) -> ~[StructDoc] {
|
||||
do vec::filter_mapped(self.items) |itemtag| {
|
||||
match copy *itemtag {
|
||||
StructTag(StructDoc) => Some(StructDoc),
|
||||
|
@ -212,8 +212,8 @@ mod test {
|
||||
#[test]
|
||||
fn should_prune_priv_associated_methods_on_pub_impls() {
|
||||
let doc = mk_doc(
|
||||
~"pub impl Foo {\
|
||||
fn bar() { }\
|
||||
~"impl Foo {\
|
||||
pub fn bar() { }\
|
||||
priv fn baz() { }\
|
||||
}");
|
||||
assert_eq!(doc.cratemod().impls()[0].methods.len(), 1);
|
||||
@ -222,7 +222,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_prune_associated_methods_without_vis_modifier_on_priv_impls() {
|
||||
let doc = mk_doc(
|
||||
~"priv impl Foo {\
|
||||
~"impl Foo {\
|
||||
pub fn bar() { }\
|
||||
fn baz() { }\
|
||||
}");
|
||||
@ -232,7 +232,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_prune_priv_associated_methods_on_priv_impls() {
|
||||
let doc = mk_doc(
|
||||
~"priv impl Foo {\
|
||||
~"impl Foo {\
|
||||
pub fn bar() { }\
|
||||
priv fn baz() { }\
|
||||
}");
|
||||
@ -242,7 +242,7 @@ mod test {
|
||||
#[test]
|
||||
fn should_prune_associated_impls_with_no_pub_methods() {
|
||||
let doc = mk_doc(
|
||||
~"priv impl Foo {\
|
||||
~"impl Foo {\
|
||||
fn baz() { }\
|
||||
}");
|
||||
assert!(doc.cratemod().impls().is_empty());
|
||||
|
@ -47,7 +47,7 @@ fn test() {
|
||||
fn ifn() { } \
|
||||
enum ienum { ivar } \
|
||||
trait itrait { fn a(); } \
|
||||
pub impl int { fn a() { } } \
|
||||
impl int { fn a() { } } \
|
||||
type itype = int; \
|
||||
struct istruct { f: () }";
|
||||
do astsrv::from_str(source) |srv| {
|
||||
|
@ -430,9 +430,8 @@ pub struct Crate {
|
||||
cfgs: ~[~str]
|
||||
}
|
||||
|
||||
pub impl Crate {
|
||||
|
||||
fn new(p: &Path) -> Crate {
|
||||
impl Crate {
|
||||
pub fn new(p: &Path) -> Crate {
|
||||
Crate {
|
||||
file: copy *p,
|
||||
flags: ~[],
|
||||
@ -440,28 +439,28 @@ pub impl Crate {
|
||||
}
|
||||
}
|
||||
|
||||
fn flag(&self, flag: ~str) -> Crate {
|
||||
pub fn flag(&self, flag: ~str) -> Crate {
|
||||
Crate {
|
||||
flags: vec::append(copy self.flags, [flag]),
|
||||
.. copy *self
|
||||
}
|
||||
}
|
||||
|
||||
fn flags(&self, flags: ~[~str]) -> Crate {
|
||||
pub fn flags(&self, flags: ~[~str]) -> Crate {
|
||||
Crate {
|
||||
flags: vec::append(copy self.flags, flags),
|
||||
.. copy *self
|
||||
}
|
||||
}
|
||||
|
||||
fn cfg(&self, cfg: ~str) -> Crate {
|
||||
pub fn cfg(&self, cfg: ~str) -> Crate {
|
||||
Crate {
|
||||
cfgs: vec::append(copy self.cfgs, [cfg]),
|
||||
.. copy *self
|
||||
}
|
||||
}
|
||||
|
||||
fn cfgs(&self, cfgs: ~[~str]) -> Crate {
|
||||
pub fn cfgs(&self, cfgs: ~[~str]) -> Crate {
|
||||
Crate {
|
||||
cfgs: vec::append(copy self.cfgs, cfgs),
|
||||
.. copy *self
|
||||
|
@ -107,8 +107,8 @@ pub struct PkgId {
|
||||
version: Version
|
||||
}
|
||||
|
||||
pub impl PkgId {
|
||||
fn new(s: &str) -> PkgId {
|
||||
impl PkgId {
|
||||
pub fn new(s: &str) -> PkgId {
|
||||
use conditions::bad_pkg_id::cond;
|
||||
|
||||
let p = Path(s);
|
||||
@ -129,13 +129,13 @@ pub impl PkgId {
|
||||
}
|
||||
}
|
||||
|
||||
fn hash(&self) -> ~str {
|
||||
pub fn hash(&self) -> ~str {
|
||||
fmt!("%s-%s-%s", self.remote_path.to_str(),
|
||||
hash(self.remote_path.to_str() + self.version.to_str()),
|
||||
self.version.to_str())
|
||||
}
|
||||
|
||||
fn short_name_with_version(&self) -> ~str {
|
||||
pub fn short_name_with_version(&self) -> ~str {
|
||||
fmt!("%s-%s", self.short_name, self.version.to_str())
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
//! A mutable, nullable memory location
|
||||
|
||||
#[missing_doc];
|
||||
|
||||
use cast::transmute_mut;
|
||||
use prelude::*;
|
||||
use util::replace;
|
||||
@ -37,9 +39,9 @@ pub fn empty_cell<T>() -> Cell<T> {
|
||||
Cell { value: None }
|
||||
}
|
||||
|
||||
pub impl<T> Cell<T> {
|
||||
impl<T> Cell<T> {
|
||||
/// Yields the value, failing if the cell is empty.
|
||||
fn take(&self) -> T {
|
||||
pub fn take(&self) -> T {
|
||||
let this = unsafe { transmute_mut(self) };
|
||||
if this.is_empty() {
|
||||
fail!("attempt to take an empty cell");
|
||||
@ -49,7 +51,7 @@ pub impl<T> Cell<T> {
|
||||
}
|
||||
|
||||
/// Returns the value, failing if the cell is full.
|
||||
fn put_back(&self, value: T) {
|
||||
pub fn put_back(&self, value: T) {
|
||||
let this = unsafe { transmute_mut(self) };
|
||||
if !this.is_empty() {
|
||||
fail!("attempt to put a value back into a full cell");
|
||||
@ -58,20 +60,20 @@ pub impl<T> Cell<T> {
|
||||
}
|
||||
|
||||
/// Returns true if the cell is empty and false if the cell is full.
|
||||
fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.value.is_none()
|
||||
}
|
||||
|
||||
// Calls a closure with a reference to the value.
|
||||
fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
|
||||
/// Calls a closure with a reference to the value.
|
||||
pub fn with_ref<R>(&self, op: &fn(v: &T) -> R) -> R {
|
||||
let v = self.take();
|
||||
let r = op(&v);
|
||||
self.put_back(v);
|
||||
r
|
||||
}
|
||||
|
||||
// Calls a closure with a mutable reference to the value.
|
||||
fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
|
||||
/// Calls a closure with a mutable reference to the value.
|
||||
pub fn with_mut_ref<R>(&self, op: &fn(v: &mut T) -> R) -> R {
|
||||
let mut v = self.take();
|
||||
let r = op(&mut v);
|
||||
self.put_back(v);
|
||||
|
@ -150,14 +150,14 @@ pub struct PortSet<T> {
|
||||
ports: ~[pipesy::Port<T>],
|
||||
}
|
||||
|
||||
pub impl<T: Owned> PortSet<T> {
|
||||
fn new() -> PortSet<T> {
|
||||
impl<T: Owned> PortSet<T> {
|
||||
pub fn new() -> PortSet<T> {
|
||||
PortSet {
|
||||
ports: ~[]
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&self, port: Port<T>) {
|
||||
pub fn add(&self, port: Port<T>) {
|
||||
let Port { inner } = port;
|
||||
let port = match inner {
|
||||
Left(p) => p,
|
||||
@ -169,7 +169,7 @@ pub impl<T: Owned> PortSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn chan(&self) -> Chan<T> {
|
||||
pub fn chan(&self) -> Chan<T> {
|
||||
let (po, ch) = stream();
|
||||
self.add(po);
|
||||
ch
|
||||
@ -470,20 +470,20 @@ mod pipesy {
|
||||
(PortOne::new(port), ChanOne::new(chan))
|
||||
}
|
||||
|
||||
pub impl<T: Owned> PortOne<T> {
|
||||
fn recv(self) -> T { recv_one(self) }
|
||||
fn try_recv(self) -> Option<T> { try_recv_one(self) }
|
||||
fn unwrap(self) -> oneshot::server::Oneshot<T> {
|
||||
impl<T: Owned> PortOne<T> {
|
||||
pub fn recv(self) -> T { recv_one(self) }
|
||||
pub fn try_recv(self) -> Option<T> { try_recv_one(self) }
|
||||
pub fn unwrap(self) -> oneshot::server::Oneshot<T> {
|
||||
match self {
|
||||
PortOne { contents: s } => s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T: Owned> ChanOne<T> {
|
||||
fn send(self, data: T) { send_one(self, data) }
|
||||
fn try_send(self, data: T) -> bool { try_send_one(self, data) }
|
||||
fn unwrap(self) -> oneshot::client::Oneshot<T> {
|
||||
impl<T: Owned> ChanOne<T> {
|
||||
pub fn send(self, data: T) { send_one(self, data) }
|
||||
pub fn try_send(self, data: T) -> bool { try_send_one(self, data) }
|
||||
pub fn unwrap(self) -> oneshot::client::Oneshot<T> {
|
||||
match self {
|
||||
ChanOne { contents: s } => s
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ pub struct Condition<'self, T, U> {
|
||||
key: local_data::LocalDataKey<'self, Handler<T, U>>
|
||||
}
|
||||
|
||||
pub impl<'self, T, U> Condition<'self, T, U> {
|
||||
fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
|
||||
impl<'self, T, U> Condition<'self, T, U> {
|
||||
pub fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
|
||||
unsafe {
|
||||
let p : *RustClosure = ::cast::transmute(&h);
|
||||
let prev = local_data::local_data_get(self.key);
|
||||
@ -39,12 +39,12 @@ pub impl<'self, T, U> Condition<'self, T, U> {
|
||||
}
|
||||
}
|
||||
|
||||
fn raise(&self, t: T) -> U {
|
||||
pub fn raise(&self, t: T) -> U {
|
||||
let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
|
||||
self.raise_default(t, || fail!(copy msg))
|
||||
}
|
||||
|
||||
fn raise_default(&self, t: T, default: &fn() -> U) -> U {
|
||||
pub fn raise_default(&self, t: T, default: &fn() -> U) -> U {
|
||||
unsafe {
|
||||
match local_data_pop(self.key) {
|
||||
None => {
|
||||
@ -73,8 +73,8 @@ struct Trap<'self, T, U> {
|
||||
handler: @Handler<T, U>
|
||||
}
|
||||
|
||||
pub impl<'self, T, U> Trap<'self, T, U> {
|
||||
fn in<V>(&self, inner: &'self fn() -> V) -> V {
|
||||
impl<'self, T, U> Trap<'self, T, U> {
|
||||
pub fn in<V>(&self, inner: &'self fn() -> V) -> V {
|
||||
unsafe {
|
||||
let _g = Guard { cond: self.cond };
|
||||
debug!("Trap: pushing handler to TLS");
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
//! A type that represents one of two alternatives
|
||||
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use container::Container;
|
||||
use cmp::Eq;
|
||||
use kinds::Copy;
|
||||
@ -137,29 +139,29 @@ pub fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T, U> Either<T, U> {
|
||||
impl<T, U> Either<T, U> {
|
||||
#[inline(always)]
|
||||
fn either<V>(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V {
|
||||
pub fn either<V>(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V {
|
||||
either(f_left, f_right, self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn flip(self) -> Either<U, T> { flip(self) }
|
||||
pub fn flip(self) -> Either<U, T> { flip(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn to_result(self) -> Result<U, T> { to_result(self) }
|
||||
pub fn to_result(self) -> Result<U, T> { to_result(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn is_left(&self) -> bool { is_left(self) }
|
||||
pub fn is_left(&self) -> bool { is_left(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn is_right(&self) -> bool { is_right(self) }
|
||||
pub fn is_right(&self) -> bool { is_right(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn unwrap_left(self) -> T { unwrap_left(self) }
|
||||
pub fn unwrap_left(self) -> T { unwrap_left(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn unwrap_right(self) -> U { unwrap_right(self) }
|
||||
pub fn unwrap_right(self) -> U { unwrap_right(self) }
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -13,6 +13,8 @@
|
||||
//! The tables use a keyed hash with new random keys generated for each container, so the ordering
|
||||
//! of a set of keys in a hash table is randomized.
|
||||
|
||||
#[mutable_doc];
|
||||
|
||||
use container::{Container, Mutable, Map, Set};
|
||||
use cmp::{Eq, Equiv};
|
||||
use hash::Hash;
|
||||
@ -81,7 +83,7 @@ fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
|
||||
}
|
||||
}
|
||||
|
||||
priv impl<K:Hash + Eq,V> HashMap<K, V> {
|
||||
impl<K:Hash + Eq,V> HashMap<K, V> {
|
||||
#[inline(always)]
|
||||
fn to_bucket(&self, h: uint) -> uint {
|
||||
// A good hash function with entropy spread over all of the
|
||||
@ -403,20 +405,20 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
/// Create an empty HashMap
|
||||
fn new() -> HashMap<K, V> {
|
||||
pub fn new() -> HashMap<K, V> {
|
||||
HashMap::with_capacity(INITIAL_CAPACITY)
|
||||
}
|
||||
|
||||
/// Create an empty HashMap with space for at least `n` elements in
|
||||
/// the hash table.
|
||||
fn with_capacity(capacity: uint) -> HashMap<K, V> {
|
||||
pub fn with_capacity(capacity: uint) -> HashMap<K, V> {
|
||||
linear_map_with_capacity(capacity)
|
||||
}
|
||||
|
||||
/// Reserve space for at least `n` elements in the hash table.
|
||||
fn reserve_at_least(&mut self, n: uint) {
|
||||
pub fn reserve_at_least(&mut self, n: uint) {
|
||||
if n > self.buckets.len() {
|
||||
let buckets = n * 4 / 3 + 1;
|
||||
self.resize(uint::next_power_of_two(buckets));
|
||||
@ -425,7 +427,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, or insert
|
||||
/// and return the value if it doesn't exist.
|
||||
fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
|
||||
pub fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
@ -453,7 +455,8 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, or create,
|
||||
/// insert, and return a new value if it doesn't exist.
|
||||
fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V {
|
||||
pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V)
|
||||
-> &'a V {
|
||||
if self.size >= self.resize_at {
|
||||
// n.b.: We could also do this after searching, so
|
||||
// that we do not resize if this call to insert is
|
||||
@ -480,7 +483,9 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
self.value_for_bucket(idx)
|
||||
}
|
||||
|
||||
fn consume(&mut self, f: &fn(K, V)) {
|
||||
/// Calls a function on each element of a hash map, destroying the hash
|
||||
/// map in the process.
|
||||
pub fn consume(&mut self, f: &fn(K, V)) {
|
||||
let buckets = replace(&mut self.buckets,
|
||||
vec::from_fn(INITIAL_CAPACITY, |_| None));
|
||||
self.size = 0;
|
||||
@ -495,7 +500,9 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn get<'a>(&'a self, k: &K) -> &'a V {
|
||||
/// Retrieves a value for the given key, failing if the key is not
|
||||
/// present.
|
||||
pub fn get<'a>(&'a self, k: &K) -> &'a V {
|
||||
match self.find(k) {
|
||||
Some(v) => v,
|
||||
None => fail!("No entry found for key: %?", k),
|
||||
@ -504,7 +511,7 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return true if the map contains a value for the specified key,
|
||||
/// using equivalence
|
||||
fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {
|
||||
pub fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {
|
||||
match self.bucket_for_key_equiv(key) {
|
||||
FoundEntry(_) => {true}
|
||||
TableFull | FoundHole(_) => {false}
|
||||
@ -513,7 +520,8 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
|
||||
/// Return the value corresponding to the key in the map, using
|
||||
/// equivalence
|
||||
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
|
||||
pub fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q)
|
||||
-> Option<&'a V> {
|
||||
match self.bucket_for_key_equiv(k) {
|
||||
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
|
||||
TableFull | FoundHole(_) => None,
|
||||
@ -521,14 +529,14 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
|
||||
impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
|
||||
/// Like `find`, but returns a copy of the value.
|
||||
fn find_copy(&self, k: &K) -> Option<V> {
|
||||
pub fn find_copy(&self, k: &K) -> Option<V> {
|
||||
self.find(k).map_consume(|v| copy *v)
|
||||
}
|
||||
|
||||
/// Like `get`, but returns a copy of the value.
|
||||
fn get_copy(&self, k: &K) -> V {
|
||||
pub fn get_copy(&self, k: &K) -> V {
|
||||
copy *self.get(k)
|
||||
}
|
||||
}
|
||||
@ -632,29 +640,31 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl <T:Hash + Eq> HashSet<T> {
|
||||
impl<T:Hash + Eq> HashSet<T> {
|
||||
/// Create an empty HashSet
|
||||
fn new() -> HashSet<T> {
|
||||
pub fn new() -> HashSet<T> {
|
||||
HashSet::with_capacity(INITIAL_CAPACITY)
|
||||
}
|
||||
|
||||
/// Create an empty HashSet with space for at least `n` elements in
|
||||
/// the hash table.
|
||||
fn with_capacity(capacity: uint) -> HashSet<T> {
|
||||
pub fn with_capacity(capacity: uint) -> HashSet<T> {
|
||||
HashSet { map: HashMap::with_capacity(capacity) }
|
||||
}
|
||||
|
||||
/// Reserve space for at least `n` elements in the hash table.
|
||||
fn reserve_at_least(&mut self, n: uint) {
|
||||
pub fn reserve_at_least(&mut self, n: uint) {
|
||||
self.map.reserve_at_least(n)
|
||||
}
|
||||
|
||||
/// Consumes all of the elements in the set, emptying it out
|
||||
fn consume(&mut self, f: &fn(T)) {
|
||||
pub fn consume(&mut self, f: &fn(T)) {
|
||||
self.map.consume(|k, _| f(k))
|
||||
}
|
||||
|
||||
fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
|
||||
/// Returns true if the hash set contains a value equivalent to the
|
||||
/// given query value.
|
||||
pub fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
|
||||
self.map.contains_key_equiv(value)
|
||||
}
|
||||
}
|
||||
|
@ -145,21 +145,20 @@ impl<A> ExtendedIter<A> for Option<A> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> Option<T> {
|
||||
impl<T> Option<T> {
|
||||
/// Returns true if the option equals `none`
|
||||
fn is_none(&const self) -> bool {
|
||||
pub fn is_none(&const self) -> bool {
|
||||
match *self { None => true, Some(_) => false }
|
||||
}
|
||||
|
||||
/// Returns true if the option contains some value
|
||||
#[inline(always)]
|
||||
fn is_some(&const self) -> bool { !self.is_none() }
|
||||
pub fn is_some(&const self) -> bool { !self.is_none() }
|
||||
|
||||
/// Update an optional value by optionally running its content through a
|
||||
/// function that returns an option.
|
||||
#[inline(always)]
|
||||
fn chain<U>(self, f: &fn(t: T) -> Option<U>) -> Option<U> {
|
||||
|
||||
pub fn chain<U>(self, f: &fn(t: T) -> Option<U>) -> Option<U> {
|
||||
match self {
|
||||
Some(t) => f(t),
|
||||
None => None
|
||||
@ -168,7 +167,7 @@ pub impl<T> Option<T> {
|
||||
|
||||
/// Returns the leftmost Some() value, or None if both are None.
|
||||
#[inline(always)]
|
||||
fn or(self, optb: Option<T>) -> Option<T> {
|
||||
pub fn or(self, optb: Option<T>) -> Option<T> {
|
||||
match self {
|
||||
Some(opta) => Some(opta),
|
||||
_ => optb
|
||||
@ -178,45 +177,49 @@ pub impl<T> Option<T> {
|
||||
/// Update an optional value by optionally running its content by reference
|
||||
/// through a function that returns an option.
|
||||
#[inline(always)]
|
||||
fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
|
||||
match *self { Some(ref x) => f(x), None => None }
|
||||
pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>)
|
||||
-> Option<U> {
|
||||
match *self {
|
||||
Some(ref x) => f(x),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps a `some` value from one type to another by reference
|
||||
#[inline(always)]
|
||||
fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option<U> {
|
||||
pub fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option<U> {
|
||||
match *self { Some(ref x) => Some(f(x)), None => None }
|
||||
}
|
||||
|
||||
/// As `map`, but consumes the option and gives `f` ownership to avoid
|
||||
/// copying.
|
||||
#[inline(always)]
|
||||
fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
|
||||
pub fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
|
||||
match self { None => None, Some(v) => Some(f(v)) }
|
||||
}
|
||||
|
||||
/// Applies a function to the contained value or returns a default
|
||||
#[inline(always)]
|
||||
fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U {
|
||||
pub fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U {
|
||||
match *self { None => def, Some(ref t) => f(t) }
|
||||
}
|
||||
|
||||
/// As `map_default`, but consumes the option and gives `f`
|
||||
/// ownership to avoid copying.
|
||||
#[inline(always)]
|
||||
fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
|
||||
pub fn map_consume_default<U>(self, def: U, f: &fn(v: T) -> U) -> U {
|
||||
match self { None => def, Some(v) => f(v) }
|
||||
}
|
||||
|
||||
/// Apply a function to the contained value or do nothing
|
||||
fn mutate(&mut self, f: &fn(T) -> T) {
|
||||
pub fn mutate(&mut self, f: &fn(T) -> T) {
|
||||
if self.is_some() {
|
||||
*self = Some(f(self.swap_unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a function to the contained value or set it to a default
|
||||
fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
|
||||
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
|
||||
if self.is_some() {
|
||||
*self = Some(f(self.swap_unwrap()));
|
||||
} else {
|
||||
@ -239,7 +242,7 @@ pub impl<T> Option<T> {
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn get_ref<'a>(&'a self) -> &'a T {
|
||||
pub fn get_ref<'a>(&'a self) -> &'a T {
|
||||
match *self {
|
||||
Some(ref x) => x,
|
||||
None => fail!("option::get_ref none")
|
||||
@ -261,7 +264,7 @@ pub impl<T> Option<T> {
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn get_mut_ref<'a>(&'a mut self) -> &'a mut T {
|
||||
pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut T {
|
||||
match *self {
|
||||
Some(ref mut x) => x,
|
||||
None => fail!("option::get_mut_ref none")
|
||||
@ -269,7 +272,7 @@ pub impl<T> Option<T> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn unwrap(self) -> T {
|
||||
pub fn unwrap(self) -> T {
|
||||
/*!
|
||||
Moves a value out of an option type and returns it.
|
||||
|
||||
@ -301,7 +304,7 @@ pub impl<T> Option<T> {
|
||||
* Fails if the value equals `None`.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn swap_unwrap(&mut self) -> T {
|
||||
pub fn swap_unwrap(&mut self) -> T {
|
||||
if self.is_none() { fail!("option::swap_unwrap none") }
|
||||
util::replace(self, None).unwrap()
|
||||
}
|
||||
@ -315,7 +318,7 @@ pub impl<T> Option<T> {
|
||||
* Fails if the value equals `none`
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn expect(self, reason: &str) -> T {
|
||||
pub fn expect(self, reason: &str) -> T {
|
||||
match self {
|
||||
Some(val) => val,
|
||||
None => fail!(reason.to_owned()),
|
||||
@ -323,7 +326,7 @@ pub impl<T> Option<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Option<T> {
|
||||
impl<T:Copy> Option<T> {
|
||||
/**
|
||||
Gets the value out of an option
|
||||
|
||||
@ -339,7 +342,7 @@ pub impl<T:Copy> Option<T> {
|
||||
case explicitly.
|
||||
*/
|
||||
#[inline(always)]
|
||||
fn get(self) -> T {
|
||||
pub fn get(self) -> T {
|
||||
match self {
|
||||
Some(x) => return x,
|
||||
None => fail!("option::get none")
|
||||
@ -348,13 +351,13 @@ pub impl<T:Copy> Option<T> {
|
||||
|
||||
/// Returns the contained value or a default
|
||||
#[inline(always)]
|
||||
fn get_or_default(self, def: T) -> T {
|
||||
pub fn get_or_default(self, def: T) -> T {
|
||||
match self { Some(x) => x, None => def }
|
||||
}
|
||||
|
||||
/// Applies a function zero or more times until the result is none.
|
||||
#[inline(always)]
|
||||
fn while_some(self, blk: &fn(v: T) -> Option<T>) {
|
||||
pub fn while_some(self, blk: &fn(v: T) -> Option<T>) {
|
||||
let mut opt = self;
|
||||
while opt.is_some() {
|
||||
opt = blk(opt.unwrap());
|
||||
@ -362,11 +365,14 @@ pub impl<T:Copy> Option<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy + Zero> Option<T> {
|
||||
impl<T:Copy + Zero> Option<T> {
|
||||
/// Returns the contained value or zero (for this type)
|
||||
#[inline(always)]
|
||||
fn get_or_zero(self) -> T {
|
||||
match self { Some(x) => x, None => Zero::zero() }
|
||||
pub fn get_or_zero(self) -> T {
|
||||
match self {
|
||||
Some(x) => x,
|
||||
None => Zero::zero()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,8 +308,8 @@ mod stat {
|
||||
}
|
||||
|
||||
|
||||
pub impl Path {
|
||||
fn stat(&self) -> Option<libc::stat> {
|
||||
impl Path {
|
||||
pub fn stat(&self) -> Option<libc::stat> {
|
||||
unsafe {
|
||||
do str::as_c_str(self.to_str()) |buf| {
|
||||
let mut st = stat::arch::default_stat();
|
||||
@ -322,7 +322,7 @@ pub impl Path {
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn lstat(&self) -> Option<libc::stat> {
|
||||
pub fn lstat(&self) -> Option<libc::stat> {
|
||||
unsafe {
|
||||
do str::as_c_str(self.to_str()) |buf| {
|
||||
let mut st = stat::arch::default_stat();
|
||||
@ -334,21 +334,21 @@ pub impl Path {
|
||||
}
|
||||
}
|
||||
|
||||
fn exists(&self) -> bool {
|
||||
pub fn exists(&self) -> bool {
|
||||
match self.stat() {
|
||||
None => false,
|
||||
Some(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_size(&self) -> Option<i64> {
|
||||
pub fn get_size(&self) -> Option<i64> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => Some(st.st_size as i64),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_mode(&self) -> Option<uint> {
|
||||
pub fn get_mode(&self) -> Option<uint> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => Some(st.st_mode as uint),
|
||||
@ -359,8 +359,8 @@ pub impl Path {
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "macos")]
|
||||
pub impl Path {
|
||||
fn get_atime(&self) -> Option<(i64, int)> {
|
||||
impl Path {
|
||||
pub fn get_atime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -370,7 +370,7 @@ pub impl Path {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_mtime(&self) -> Option<(i64, int)> {
|
||||
pub fn get_mtime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -380,7 +380,7 @@ pub impl Path {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_ctime(&self) -> Option<(i64, int)> {
|
||||
pub fn get_ctime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -393,8 +393,8 @@ pub impl Path {
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "macos")]
|
||||
pub impl Path {
|
||||
fn get_birthtime(&self) -> Option<(i64, int)> {
|
||||
impl Path {
|
||||
pub fn get_birthtime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -406,8 +406,8 @@ pub impl Path {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub impl Path {
|
||||
fn get_atime(&self) -> Option<(i64, int)> {
|
||||
impl Path {
|
||||
pub fn get_atime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -416,7 +416,7 @@ pub impl Path {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_mtime(&self) -> Option<(i64, int)> {
|
||||
pub fn get_mtime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
@ -425,7 +425,7 @@ pub impl Path {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_ctime(&self) -> Option<(i64, int)> {
|
||||
pub fn get_ctime(&self) -> Option<(i64, int)> {
|
||||
match self.stat() {
|
||||
None => None,
|
||||
Some(ref st) => {
|
||||
|
@ -152,16 +152,16 @@ pub fn PacketHeader() -> PacketHeader {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl PacketHeader {
|
||||
impl PacketHeader {
|
||||
// Returns the old state.
|
||||
unsafe fn mark_blocked(&mut self, this: *rust_task) -> State {
|
||||
pub unsafe fn mark_blocked(&mut self, this: *rust_task) -> State {
|
||||
rustrt::rust_task_ref(this);
|
||||
let old_task = swap_task(&mut self.blocked_task, this);
|
||||
assert!(old_task.is_null());
|
||||
swap_state_acq(&mut self.state, Blocked)
|
||||
}
|
||||
|
||||
unsafe fn unblock(&mut self) {
|
||||
pub unsafe fn unblock(&mut self) {
|
||||
let old_task = swap_task(&mut self.blocked_task, ptr::null());
|
||||
if !old_task.is_null() {
|
||||
rustrt::rust_task_deref(old_task)
|
||||
@ -176,12 +176,12 @@ pub impl PacketHeader {
|
||||
// unsafe because this can do weird things to the space/time
|
||||
// continuum. It ends making multiple unique pointers to the same
|
||||
// thing. You'll probably want to forget them when you're done.
|
||||
unsafe fn buf_header(&mut self) -> ~BufferHeader {
|
||||
pub unsafe fn buf_header(&mut self) -> ~BufferHeader {
|
||||
assert!(self.buffer.is_not_null());
|
||||
transmute_copy(&self.buffer)
|
||||
}
|
||||
|
||||
fn set_buffer<T:Owned>(&mut self, b: ~Buffer<T>) {
|
||||
pub fn set_buffer<T:Owned>(&mut self, b: ~Buffer<T>) {
|
||||
unsafe {
|
||||
self.buffer = transmute_copy(&b);
|
||||
}
|
||||
@ -694,12 +694,12 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *mut Packet<T>)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
fn unwrap(&mut self) -> *mut Packet<T> {
|
||||
impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
pub fn unwrap(&mut self) -> *mut Packet<T> {
|
||||
replace(&mut self.p, None).unwrap()
|
||||
}
|
||||
|
||||
fn header(&mut self) -> *mut PacketHeader {
|
||||
pub fn header(&mut self) -> *mut PacketHeader {
|
||||
match self.p {
|
||||
Some(packet) => unsafe {
|
||||
let packet = &mut *packet;
|
||||
@ -710,7 +710,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
}
|
||||
}
|
||||
|
||||
fn reuse_buffer(&mut self) -> BufferResource<Tbuffer> {
|
||||
pub fn reuse_buffer(&mut self) -> BufferResource<Tbuffer> {
|
||||
//error!("send reuse_buffer");
|
||||
replace(&mut self.buffer, None).unwrap()
|
||||
}
|
||||
@ -742,12 +742,12 @@ impl<T:Owned,Tbuffer:Owned> Drop for RecvPacketBuffered<T,Tbuffer> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||
fn unwrap(&mut self) -> *mut Packet<T> {
|
||||
impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||
pub fn unwrap(&mut self) -> *mut Packet<T> {
|
||||
replace(&mut self.p, None).unwrap()
|
||||
}
|
||||
|
||||
fn reuse_buffer(&mut self) -> BufferResource<Tbuffer> {
|
||||
pub fn reuse_buffer(&mut self) -> BufferResource<Tbuffer> {
|
||||
replace(&mut self.buffer, None).unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -612,9 +612,9 @@ pub struct IsaacRng {
|
||||
priv c: u32
|
||||
}
|
||||
|
||||
pub impl IsaacRng {
|
||||
impl IsaacRng {
|
||||
/// Create an ISAAC random number generator with a random seed.
|
||||
fn new() -> IsaacRng {
|
||||
pub fn new() -> IsaacRng {
|
||||
IsaacRng::new_seeded(seed())
|
||||
}
|
||||
|
||||
@ -623,7 +623,7 @@ pub impl IsaacRng {
|
||||
/// will be silently ignored. A generator constructed with a given seed
|
||||
/// will generate the same sequence of values as all other generators
|
||||
/// constructed with the same seed.
|
||||
fn new_seeded(seed: &[u8]) -> IsaacRng {
|
||||
pub fn new_seeded(seed: &[u8]) -> IsaacRng {
|
||||
let mut rng = IsaacRng {
|
||||
cnt: 0,
|
||||
rsl: [0, .. RAND_SIZE],
|
||||
@ -643,7 +643,7 @@ pub impl IsaacRng {
|
||||
|
||||
/// Create an ISAAC random number generator using the default
|
||||
/// fixed seed.
|
||||
fn new_unseeded() -> IsaacRng {
|
||||
pub fn new_unseeded() -> IsaacRng {
|
||||
let mut rng = IsaacRng {
|
||||
cnt: 0,
|
||||
rsl: [0, .. RAND_SIZE],
|
||||
@ -657,7 +657,7 @@ pub impl IsaacRng {
|
||||
/// Initialises `self`. If `use_rsl` is true, then use the current value
|
||||
/// of `rsl` as a seed, otherwise construct one algorithmically (not
|
||||
/// randomly).
|
||||
priv fn init(&mut self, use_rsl: bool) {
|
||||
fn init(&mut self, use_rsl: bool) {
|
||||
macro_rules! init_mut_many (
|
||||
($( $var:ident ),* = $val:expr ) => {
|
||||
let mut $( $var = $val ),*;
|
||||
@ -715,7 +715,7 @@ pub impl IsaacRng {
|
||||
|
||||
/// Refills the output buffer (`self.rsl`)
|
||||
#[inline]
|
||||
priv fn isaac(&mut self) {
|
||||
fn isaac(&mut self) {
|
||||
self.c += 1;
|
||||
// abbreviations
|
||||
let mut a = self.a, b = self.b + self.c;
|
||||
@ -795,9 +795,9 @@ impl Rng for XorShiftRng {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl XorShiftRng {
|
||||
impl XorShiftRng {
|
||||
/// Create an xor shift random number generator with a default seed.
|
||||
fn new() -> XorShiftRng {
|
||||
pub fn new() -> XorShiftRng {
|
||||
// constants taken from http://en.wikipedia.org/wiki/Xorshift
|
||||
XorShiftRng::new_seeded(123456789u32,
|
||||
362436069u32,
|
||||
@ -807,10 +807,10 @@ pub impl XorShiftRng {
|
||||
|
||||
/**
|
||||
* Create a random number generator using the specified seed. A generator
|
||||
* constructed with a given seed will generate the same sequence of values as
|
||||
* all other generators constructed with the same seed.
|
||||
* constructed with a given seed will generate the same sequence of values
|
||||
* as all other generators constructed with the same seed.
|
||||
*/
|
||||
fn new_seeded(x: u32, y: u32, z: u32, w: u32) -> XorShiftRng {
|
||||
pub fn new_seeded(x: u32, y: u32, z: u32, w: u32) -> XorShiftRng {
|
||||
XorShiftRng {
|
||||
x: x,
|
||||
y: y,
|
||||
|
@ -48,28 +48,28 @@ pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
|
||||
MovePtrAdaptor { inner: v }
|
||||
}
|
||||
|
||||
pub impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
|
||||
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
|
||||
#[inline(always)]
|
||||
fn bump(&self, sz: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
pub fn bump(&self, sz: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
((p as uint) + sz) as *c_void
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn align(&self, a: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
pub fn align(&self, a: uint) {
|
||||
do self.inner.move_ptr() |p| {
|
||||
align(p as uint, a) as *c_void
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn align_to<T>(&self) {
|
||||
pub fn align_to<T>(&self) {
|
||||
self.align(sys::min_align_of::<T>());
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn bump_past<T>(&self) {
|
||||
pub fn bump_past<T>(&self) {
|
||||
self.bump(sys::size_of::<T>());
|
||||
}
|
||||
}
|
||||
|
@ -174,12 +174,11 @@ impl MovePtr for ReprVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl ReprVisitor {
|
||||
|
||||
impl ReprVisitor {
|
||||
// Various helpers for the TyVisitor impl
|
||||
|
||||
#[inline(always)]
|
||||
fn get<T>(&self, f: &fn(&T)) -> bool {
|
||||
pub fn get<T>(&self, f: &fn(&T)) -> bool {
|
||||
unsafe {
|
||||
f(transmute::<*c_void,&T>(*self.ptr));
|
||||
}
|
||||
@ -187,12 +186,12 @@ pub impl ReprVisitor {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_inner(&self, inner: *TyDesc) -> bool {
|
||||
pub fn visit_inner(&self, inner: *TyDesc) -> bool {
|
||||
self.visit_ptr_inner(*self.ptr, inner)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
|
||||
pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
|
||||
unsafe {
|
||||
let u = ReprVisitor(ptr, self.writer);
|
||||
let v = reflect::MovePtrAdaptor(u);
|
||||
@ -202,13 +201,13 @@ pub impl ReprVisitor {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn write<T:Repr>(&self) -> bool {
|
||||
pub fn write<T:Repr>(&self) -> bool {
|
||||
do self.get |v:&T| {
|
||||
v.write_repr(self.writer);
|
||||
}
|
||||
}
|
||||
|
||||
fn write_escaped_slice(&self, slice: &str) {
|
||||
pub fn write_escaped_slice(&self, slice: &str) {
|
||||
self.writer.write_char('"');
|
||||
for slice.each_char |ch| {
|
||||
self.writer.write_escaped_char(ch);
|
||||
@ -216,7 +215,7 @@ pub impl ReprVisitor {
|
||||
self.writer.write_char('"');
|
||||
}
|
||||
|
||||
fn write_mut_qualifier(&self, mtbl: uint) {
|
||||
pub fn write_mut_qualifier(&self, mtbl: uint) {
|
||||
if mtbl == 0 {
|
||||
self.writer.write_str("mut ");
|
||||
} else if mtbl == 1 {
|
||||
@ -227,8 +226,12 @@ pub impl ReprVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn write_vec_range(&self, mtbl: uint, ptr: *u8, len: uint,
|
||||
inner: *TyDesc) -> bool {
|
||||
pub fn write_vec_range(&self,
|
||||
mtbl: uint,
|
||||
ptr: *u8,
|
||||
len: uint,
|
||||
inner: *TyDesc)
|
||||
-> bool {
|
||||
let mut p = ptr;
|
||||
let end = ptr::offset(p, len);
|
||||
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
|
||||
@ -248,13 +251,14 @@ pub impl ReprVisitor {
|
||||
true
|
||||
}
|
||||
|
||||
fn write_unboxed_vec_repr(&self, mtbl: uint, v: &UnboxedVecRepr,
|
||||
inner: *TyDesc) -> bool {
|
||||
pub fn write_unboxed_vec_repr(&self,
|
||||
mtbl: uint,
|
||||
v: &UnboxedVecRepr,
|
||||
inner: *TyDesc)
|
||||
-> bool {
|
||||
self.write_vec_range(mtbl, ptr::to_unsafe_ptr(&v.data),
|
||||
v.fill, inner)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl TyVisitor for ReprVisitor {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
//! A type representing either success or failure
|
||||
|
||||
// NB: transitionary, de-mode-ing.
|
||||
#[allow(missing_doc)];
|
||||
|
||||
use cmp::Eq;
|
||||
use either;
|
||||
@ -227,55 +227,55 @@ pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T, E> Result<T, E> {
|
||||
impl<T, E> Result<T, E> {
|
||||
#[inline(always)]
|
||||
fn get_ref<'a>(&'a self) -> &'a T { get_ref(self) }
|
||||
pub fn get_ref<'a>(&'a self) -> &'a T { get_ref(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn is_ok(&self) -> bool { is_ok(self) }
|
||||
pub fn is_ok(&self) -> bool { is_ok(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn is_err(&self) -> bool { is_err(self) }
|
||||
pub fn is_err(&self) -> bool { is_err(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn iter(&self, f: &fn(&T)) { iter(self, f) }
|
||||
pub fn iter(&self, f: &fn(&T)) { iter(self, f) }
|
||||
|
||||
#[inline(always)]
|
||||
fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
|
||||
pub fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) }
|
||||
|
||||
#[inline(always)]
|
||||
fn unwrap(self) -> T { unwrap(self) }
|
||||
pub fn unwrap(self) -> T { unwrap(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn unwrap_err(self) -> E { unwrap_err(self) }
|
||||
pub fn unwrap_err(self) -> E { unwrap_err(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||
pub fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||
chain(self, op)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||
pub fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||
chain_err(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy,E> Result<T, E> {
|
||||
impl<T:Copy,E> Result<T, E> {
|
||||
#[inline(always)]
|
||||
fn get(&self) -> T { get(self) }
|
||||
pub fn get(&self) -> T { get(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
|
||||
pub fn map_err<F:Copy>(&self, op: &fn(&E) -> F) -> Result<T,F> {
|
||||
map_err(self, op)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T, E: Copy> Result<T, E> {
|
||||
impl<T, E: Copy> Result<T, E> {
|
||||
#[inline(always)]
|
||||
fn get_err(&self) -> E { get_err(self) }
|
||||
pub fn get_err(&self) -> E { get_err(self) }
|
||||
|
||||
#[inline(always)]
|
||||
fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
|
||||
pub fn map<U:Copy>(&self, op: &fn(&T) -> U) -> Result<U,E> {
|
||||
map(self, op)
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ pub struct Context {
|
||||
regs: ~Registers
|
||||
}
|
||||
|
||||
pub impl Context {
|
||||
fn empty() -> Context {
|
||||
impl Context {
|
||||
pub fn empty() -> Context {
|
||||
Context {
|
||||
start: None,
|
||||
regs: new_regs()
|
||||
@ -36,7 +36,7 @@ pub impl Context {
|
||||
}
|
||||
|
||||
/// Create a new context that will resume execution by running ~fn()
|
||||
fn new(start: ~fn(), stack: &mut StackSegment) -> Context {
|
||||
pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context {
|
||||
// XXX: Putting main into a ~ so it's a thin pointer and can
|
||||
// be passed to the spawn function. Another unfortunate
|
||||
// allocation
|
||||
@ -71,7 +71,7 @@ pub impl Context {
|
||||
saving the registers values of the executing thread to a Context
|
||||
then loading the registers from a previously saved Context.
|
||||
*/
|
||||
fn swap(out_context: &mut Context, in_context: &Context) {
|
||||
pub fn swap(out_context: &mut Context, in_context: &Context) {
|
||||
let out_regs: &mut Registers = match out_context {
|
||||
&Context { regs: ~ref mut r, _ } => r
|
||||
};
|
||||
|
@ -57,11 +57,10 @@ enum CleanupJob {
|
||||
GiveTask(~Coroutine, UnsafeTaskReceiver)
|
||||
}
|
||||
|
||||
pub impl Scheduler {
|
||||
impl Scheduler {
|
||||
pub fn in_task_context(&self) -> bool { self.current_task.is_some() }
|
||||
|
||||
fn in_task_context(&self) -> bool { self.current_task.is_some() }
|
||||
|
||||
fn new(event_loop: ~EventLoopObject) -> Scheduler {
|
||||
pub fn new(event_loop: ~EventLoopObject) -> Scheduler {
|
||||
|
||||
// Lazily initialize the runtime TLS key
|
||||
local_ptr::init_tls_key();
|
||||
@ -80,7 +79,7 @@ pub impl Scheduler {
|
||||
// the scheduler itself doesn't have to call event_loop.run.
|
||||
// That will be important for embedding the runtime into external
|
||||
// event loops.
|
||||
fn run(~self) -> ~Scheduler {
|
||||
pub fn run(~self) -> ~Scheduler {
|
||||
assert!(!self.in_task_context());
|
||||
|
||||
let mut self_sched = self;
|
||||
@ -107,7 +106,7 @@ pub impl Scheduler {
|
||||
/// Pushes the task onto the work stealing queue and tells the event loop
|
||||
/// to run it later. Always use this instead of pushing to the work queue
|
||||
/// directly.
|
||||
fn enqueue_task(&mut self, task: ~Coroutine) {
|
||||
pub fn enqueue_task(&mut self, task: ~Coroutine) {
|
||||
self.work_queue.push(task);
|
||||
self.event_loop.callback(resume_task_from_queue);
|
||||
|
||||
@ -119,7 +118,7 @@ pub impl Scheduler {
|
||||
|
||||
// * Scheduler-context operations
|
||||
|
||||
fn resume_task_from_queue(~self) {
|
||||
pub fn resume_task_from_queue(~self) {
|
||||
assert!(!self.in_task_context());
|
||||
|
||||
rtdebug!("looking in work queue for task to schedule");
|
||||
@ -141,7 +140,7 @@ pub impl Scheduler {
|
||||
|
||||
/// Called by a running task to end execution, after which it will
|
||||
/// be recycled by the scheduler for reuse in a new task.
|
||||
fn terminate_current_task(~self) {
|
||||
pub fn terminate_current_task(~self) {
|
||||
assert!(self.in_task_context());
|
||||
|
||||
rtdebug!("ending running task");
|
||||
@ -156,7 +155,7 @@ pub impl Scheduler {
|
||||
abort!("control reached end of task");
|
||||
}
|
||||
|
||||
fn schedule_new_task(~self, task: ~Coroutine) {
|
||||
pub fn schedule_new_task(~self, task: ~Coroutine) {
|
||||
assert!(self.in_task_context());
|
||||
|
||||
do self.switch_running_tasks_and_then(task) |last_task| {
|
||||
@ -167,7 +166,7 @@ pub impl Scheduler {
|
||||
}
|
||||
}
|
||||
|
||||
fn schedule_task(~self, task: ~Coroutine) {
|
||||
pub fn schedule_task(~self, task: ~Coroutine) {
|
||||
assert!(self.in_task_context());
|
||||
|
||||
do self.switch_running_tasks_and_then(task) |last_task| {
|
||||
@ -180,7 +179,7 @@ pub impl Scheduler {
|
||||
|
||||
// Core scheduling ops
|
||||
|
||||
fn resume_task_immediately(~self, task: ~Coroutine) {
|
||||
pub fn resume_task_immediately(~self, task: ~Coroutine) {
|
||||
let mut this = self;
|
||||
assert!(!this.in_task_context());
|
||||
|
||||
@ -218,7 +217,7 @@ pub impl Scheduler {
|
||||
/// The closure here is a *stack* closure that lives in the
|
||||
/// running task. It gets transmuted to the scheduler's lifetime
|
||||
/// and called while the task is blocked.
|
||||
fn deschedule_running_task_and_then(~self, f: &fn(~Coroutine)) {
|
||||
pub fn deschedule_running_task_and_then(~self, f: &fn(~Coroutine)) {
|
||||
let mut this = self;
|
||||
assert!(this.in_task_context());
|
||||
|
||||
@ -248,7 +247,9 @@ pub impl Scheduler {
|
||||
/// Switch directly to another task, without going through the scheduler.
|
||||
/// You would want to think hard about doing this, e.g. if there are
|
||||
/// pending I/O events it would be a bad idea.
|
||||
fn switch_running_tasks_and_then(~self, next_task: ~Coroutine, f: &fn(~Coroutine)) {
|
||||
pub fn switch_running_tasks_and_then(~self,
|
||||
next_task: ~Coroutine,
|
||||
f: &fn(~Coroutine)) {
|
||||
let mut this = self;
|
||||
assert!(this.in_task_context());
|
||||
|
||||
@ -279,12 +280,12 @@ pub impl Scheduler {
|
||||
|
||||
// * Other stuff
|
||||
|
||||
fn enqueue_cleanup_job(&mut self, job: CleanupJob) {
|
||||
pub fn enqueue_cleanup_job(&mut self, job: CleanupJob) {
|
||||
assert!(self.cleanup_job.is_none());
|
||||
self.cleanup_job = Some(job);
|
||||
}
|
||||
|
||||
fn run_cleanup_job(&mut self) {
|
||||
pub fn run_cleanup_job(&mut self) {
|
||||
rtdebug!("running cleanup job");
|
||||
|
||||
assert!(self.cleanup_job.is_some());
|
||||
@ -305,9 +306,9 @@ pub impl Scheduler {
|
||||
/// callers should first arrange for that task to be located in the
|
||||
/// Scheduler's current_task slot and set up the
|
||||
/// post-context-switch cleanup job.
|
||||
fn get_contexts<'a>(&'a mut self) -> (&'a mut Context,
|
||||
Option<&'a mut Context>,
|
||||
Option<&'a mut Context>) {
|
||||
pub fn get_contexts<'a>(&'a mut self) -> (&'a mut Context,
|
||||
Option<&'a mut Context>,
|
||||
Option<&'a mut Context>) {
|
||||
let last_task = match self.cleanup_job {
|
||||
Some(GiveTask(~ref task, _)) => {
|
||||
Some(task)
|
||||
@ -349,14 +350,14 @@ pub struct Coroutine {
|
||||
task: ~Task
|
||||
}
|
||||
|
||||
pub impl Coroutine {
|
||||
fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
|
||||
impl Coroutine {
|
||||
pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
|
||||
Coroutine::with_task(stack_pool, ~Task::new(), start)
|
||||
}
|
||||
|
||||
fn with_task(stack_pool: &mut StackPool,
|
||||
task: ~Task,
|
||||
start: ~fn()) -> Coroutine {
|
||||
pub fn with_task(stack_pool: &mut StackPool,
|
||||
task: ~Task,
|
||||
start: ~fn()) -> Coroutine {
|
||||
let start = Coroutine::build_start_wrapper(start);
|
||||
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
|
||||
// NB: Context holds a pointer to that ~fn
|
||||
@ -368,7 +369,7 @@ pub impl Coroutine {
|
||||
};
|
||||
}
|
||||
|
||||
priv fn build_start_wrapper(start: ~fn()) -> ~fn() {
|
||||
fn build_start_wrapper(start: ~fn()) -> ~fn() {
|
||||
// XXX: The old code didn't have this extra allocation
|
||||
let wrapper: ~fn() = || {
|
||||
// This is the first code to execute after the initial
|
||||
@ -391,7 +392,7 @@ pub impl Coroutine {
|
||||
}
|
||||
|
||||
/// Destroy the task and try to reuse its components
|
||||
fn recycle(~self, stack_pool: &mut StackPool) {
|
||||
pub fn recycle(~self, stack_pool: &mut StackPool) {
|
||||
match self {
|
||||
~Coroutine {current_stack_segment, _} => {
|
||||
stack_pool.give_segment(current_stack_segment);
|
||||
|
@ -19,8 +19,8 @@ pub struct StackSegment {
|
||||
valgrind_id: c_uint
|
||||
}
|
||||
|
||||
pub impl StackSegment {
|
||||
fn new(size: uint) -> StackSegment {
|
||||
impl StackSegment {
|
||||
pub fn new(size: uint) -> StackSegment {
|
||||
unsafe {
|
||||
// Crate a block of uninitialized values
|
||||
let mut stack = vec::with_capacity(size);
|
||||
@ -38,12 +38,12 @@ pub impl StackSegment {
|
||||
}
|
||||
|
||||
/// Point to the low end of the allocated stack
|
||||
fn start(&self) -> *uint {
|
||||
vec::raw::to_ptr(self.buf) as *uint
|
||||
pub fn start(&self) -> *uint {
|
||||
vec::raw::to_ptr(self.buf) as *uint
|
||||
}
|
||||
|
||||
/// Point one word beyond the high end of the allocated stack
|
||||
fn end(&self) -> *uint {
|
||||
pub fn end(&self) -> *uint {
|
||||
vec::raw::to_ptr(self.buf).offset(self.buf.len()) as *uint
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ pub struct Thread {
|
||||
raw_thread: *raw_thread
|
||||
}
|
||||
|
||||
pub impl Thread {
|
||||
fn start(main: ~fn()) -> Thread {
|
||||
impl Thread {
|
||||
pub fn start(main: ~fn()) -> Thread {
|
||||
fn substart(main: &~fn()) -> *raw_thread {
|
||||
unsafe { rust_raw_thread_start(main) }
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ use rt::uv::status_to_maybe_uv_error;
|
||||
pub struct IdleWatcher(*uvll::uv_idle_t);
|
||||
impl Watcher for IdleWatcher { }
|
||||
|
||||
pub impl IdleWatcher {
|
||||
fn new(loop_: &mut Loop) -> IdleWatcher {
|
||||
impl IdleWatcher {
|
||||
pub fn new(loop_: &mut Loop) -> IdleWatcher {
|
||||
unsafe {
|
||||
let handle = uvll::idle_new();
|
||||
assert!(handle.is_not_null());
|
||||
@ -29,7 +29,7 @@ pub impl IdleWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn start(&mut self, cb: IdleCallback) {
|
||||
pub fn start(&mut self, cb: IdleCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
data.idle_cb = Some(cb);
|
||||
@ -48,16 +48,17 @@ pub impl IdleWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn stop(&mut self) {
|
||||
// NB: Not resetting the Rust idle_cb to None here because `stop` is likely
|
||||
// called from *within* the idle callback, causing a use after free
|
||||
pub fn stop(&mut self) {
|
||||
// NB: Not resetting the Rust idle_cb to None here because `stop` is
|
||||
// likely called from *within* the idle callback, causing a use after
|
||||
// free
|
||||
|
||||
unsafe {
|
||||
assert!(0 == uvll::idle_stop(self.native_handle()));
|
||||
}
|
||||
}
|
||||
|
||||
fn close(self, cb: NullCallback) {
|
||||
pub fn close(self, cb: NullCallback) {
|
||||
{
|
||||
let mut this = self;
|
||||
let data = this.get_watcher_data();
|
||||
|
@ -92,18 +92,18 @@ pub trait NativeHandle<T> {
|
||||
pub fn native_handle(&self) -> T;
|
||||
}
|
||||
|
||||
pub impl Loop {
|
||||
fn new() -> Loop {
|
||||
impl Loop {
|
||||
pub fn new() -> Loop {
|
||||
let handle = unsafe { uvll::loop_new() };
|
||||
assert!(handle.is_not_null());
|
||||
NativeHandle::from_native_handle(handle)
|
||||
}
|
||||
|
||||
fn run(&mut self) {
|
||||
pub fn run(&mut self) {
|
||||
unsafe { uvll::run(self.native_handle()) };
|
||||
}
|
||||
|
||||
fn close(&mut self) {
|
||||
pub fn close(&mut self) {
|
||||
unsafe { uvll::loop_delete(self.native_handle()) };
|
||||
}
|
||||
}
|
||||
@ -193,9 +193,8 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
|
||||
|
||||
pub struct UvError(uvll::uv_err_t);
|
||||
|
||||
pub impl UvError {
|
||||
|
||||
fn name(&self) -> ~str {
|
||||
impl UvError {
|
||||
pub fn name(&self) -> ~str {
|
||||
unsafe {
|
||||
let inner = match self { &UvError(ref a) => a };
|
||||
let name_str = uvll::err_name(inner);
|
||||
@ -204,7 +203,7 @@ pub impl UvError {
|
||||
}
|
||||
}
|
||||
|
||||
fn desc(&self) -> ~str {
|
||||
pub fn desc(&self) -> ~str {
|
||||
unsafe {
|
||||
let inner = match self { &UvError(ref a) => a };
|
||||
let desc_str = uvll::strerror(inner);
|
||||
@ -213,7 +212,7 @@ pub impl UvError {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_eof(&self) -> bool {
|
||||
pub fn is_eof(&self) -> bool {
|
||||
self.code == uvll::EOF
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,8 @@ fn ip4_as_uv_ip4<T>(addr: IpAddr, f: &fn(*sockaddr_in) -> T) -> T {
|
||||
pub struct StreamWatcher(*uvll::uv_stream_t);
|
||||
impl Watcher for StreamWatcher { }
|
||||
|
||||
pub impl StreamWatcher {
|
||||
|
||||
fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
|
||||
impl StreamWatcher {
|
||||
pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
data.alloc_cb = Some(alloc);
|
||||
@ -73,7 +72,7 @@ pub impl StreamWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_stop(&mut self) {
|
||||
pub fn read_stop(&mut self) {
|
||||
// It would be nice to drop the alloc and read callbacks here,
|
||||
// but read_stop may be called from inside one of them and we
|
||||
// would end up freeing the in-use environment
|
||||
@ -81,7 +80,7 @@ pub impl StreamWatcher {
|
||||
unsafe { uvll::read_stop(handle); }
|
||||
}
|
||||
|
||||
fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
|
||||
pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
assert!(data.write_cb.is_none());
|
||||
@ -110,7 +109,7 @@ pub impl StreamWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn accept(&mut self, stream: StreamWatcher) {
|
||||
pub fn accept(&mut self, stream: StreamWatcher) {
|
||||
let self_handle = self.native_handle() as *c_void;
|
||||
let stream_handle = stream.native_handle() as *c_void;
|
||||
unsafe {
|
||||
@ -118,7 +117,7 @@ pub impl StreamWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn close(self, cb: NullCallback) {
|
||||
pub fn close(self, cb: NullCallback) {
|
||||
{
|
||||
let mut this = self;
|
||||
let data = this.get_watcher_data();
|
||||
@ -153,8 +152,8 @@ impl NativeHandle<*uvll::uv_stream_t> for StreamWatcher {
|
||||
pub struct TcpWatcher(*uvll::uv_tcp_t);
|
||||
impl Watcher for TcpWatcher { }
|
||||
|
||||
pub impl TcpWatcher {
|
||||
fn new(loop_: &mut Loop) -> TcpWatcher {
|
||||
impl TcpWatcher {
|
||||
pub fn new(loop_: &mut Loop) -> TcpWatcher {
|
||||
unsafe {
|
||||
let handle = malloc_handle(UV_TCP);
|
||||
assert!(handle.is_not_null());
|
||||
@ -165,7 +164,7 @@ pub impl TcpWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn bind(&mut self, address: IpAddr) -> Result<(), UvError> {
|
||||
pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> {
|
||||
match address {
|
||||
Ipv4(*) => {
|
||||
do ip4_as_uv_ip4(address) |addr| {
|
||||
@ -183,7 +182,7 @@ pub impl TcpWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) {
|
||||
pub fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) {
|
||||
unsafe {
|
||||
assert!(self.get_watcher_data().connect_cb.is_none());
|
||||
self.get_watcher_data().connect_cb = Some(cb);
|
||||
@ -216,7 +215,7 @@ pub impl TcpWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn listen(&mut self, cb: ConnectionCallback) {
|
||||
pub fn listen(&mut self, cb: ConnectionCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
assert!(data.connect_cb.is_none());
|
||||
@ -240,7 +239,7 @@ pub impl TcpWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
fn as_stream(&self) -> StreamWatcher {
|
||||
pub fn as_stream(&self) -> StreamWatcher {
|
||||
NativeHandle::from_native_handle(self.native_handle() as *uvll::uv_stream_t)
|
||||
}
|
||||
}
|
||||
@ -295,9 +294,8 @@ pub struct WriteRequest(*uvll::uv_write_t);
|
||||
|
||||
impl Request for WriteRequest { }
|
||||
|
||||
pub impl WriteRequest {
|
||||
|
||||
fn new() -> WriteRequest {
|
||||
impl WriteRequest {
|
||||
pub fn new() -> WriteRequest {
|
||||
let write_handle = unsafe {
|
||||
malloc_req(UV_WRITE)
|
||||
};
|
||||
@ -306,14 +304,14 @@ pub impl WriteRequest {
|
||||
WriteRequest(write_handle)
|
||||
}
|
||||
|
||||
fn stream(&self) -> StreamWatcher {
|
||||
pub fn stream(&self) -> StreamWatcher {
|
||||
unsafe {
|
||||
let stream_handle = uvll::get_stream_handle_from_write_req(self.native_handle());
|
||||
NativeHandle::from_native_handle(stream_handle)
|
||||
}
|
||||
}
|
||||
|
||||
fn delete(self) {
|
||||
pub fn delete(self) {
|
||||
unsafe { free_req(self.native_handle() as *c_void) }
|
||||
}
|
||||
}
|
||||
|
@ -33,15 +33,15 @@ pub struct UvEventLoop {
|
||||
uvio: UvIoFactory
|
||||
}
|
||||
|
||||
pub impl UvEventLoop {
|
||||
fn new() -> UvEventLoop {
|
||||
impl UvEventLoop {
|
||||
pub fn new() -> UvEventLoop {
|
||||
UvEventLoop {
|
||||
uvio: UvIoFactory(Loop::new())
|
||||
}
|
||||
}
|
||||
|
||||
/// A convenience constructor
|
||||
fn new_scheduler() -> Scheduler {
|
||||
pub fn new_scheduler() -> Scheduler {
|
||||
Scheduler::new(~UvEventLoop::new())
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,6 @@ impl Drop for UvEventLoop {
|
||||
}
|
||||
|
||||
impl EventLoop for UvEventLoop {
|
||||
|
||||
fn run(&mut self) {
|
||||
self.uvio.uv_loop().run();
|
||||
}
|
||||
@ -103,8 +102,8 @@ fn test_callback_run_once() {
|
||||
|
||||
pub struct UvIoFactory(Loop);
|
||||
|
||||
pub impl UvIoFactory {
|
||||
fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
|
||||
impl UvIoFactory {
|
||||
pub fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
|
||||
match self { &UvIoFactory(ref mut ptr) => ptr }
|
||||
}
|
||||
}
|
||||
|
@ -29,15 +29,15 @@ pub struct UvEventLoop {
|
||||
uvio: UvIoFactory
|
||||
}
|
||||
|
||||
pub impl UvEventLoop {
|
||||
fn new() -> UvEventLoop {
|
||||
impl UvEventLoop {
|
||||
pub fn new() -> UvEventLoop {
|
||||
UvEventLoop {
|
||||
uvio: UvIoFactory(Loop::new())
|
||||
}
|
||||
}
|
||||
|
||||
/// A convenience constructor
|
||||
fn new_scheduler() -> Scheduler {
|
||||
pub fn new_scheduler() -> Scheduler {
|
||||
Scheduler::new(~UvEventLoop::new())
|
||||
}
|
||||
}
|
||||
@ -90,8 +90,8 @@ fn test_callback_run_once() {
|
||||
|
||||
pub struct UvIoFactory(Loop);
|
||||
|
||||
pub impl UvIoFactory {
|
||||
fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
|
||||
impl UvIoFactory {
|
||||
pub fn uv_loop<'a>(&'a mut self) -> &'a mut Loop {
|
||||
match self { &UvIoFactory(ref mut ptr) => ptr }
|
||||
}
|
||||
}
|
||||
|
@ -21,21 +21,21 @@ pub struct WorkQueue<T> {
|
||||
priv queue: ~Exclusive<~[T]>
|
||||
}
|
||||
|
||||
pub impl<T: Owned> WorkQueue<T> {
|
||||
fn new() -> WorkQueue<T> {
|
||||
impl<T: Owned> WorkQueue<T> {
|
||||
pub fn new() -> WorkQueue<T> {
|
||||
WorkQueue {
|
||||
queue: ~exclusive(~[])
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&mut self, value: T) {
|
||||
pub fn push(&mut self, value: T) {
|
||||
unsafe {
|
||||
let value = Cell(value);
|
||||
self.queue.with(|q| q.unshift(value.take()) );
|
||||
}
|
||||
}
|
||||
|
||||
fn pop(&mut self) -> Option<T> {
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
unsafe {
|
||||
do self.queue.with |q| {
|
||||
if !q.is_empty() {
|
||||
@ -47,7 +47,7 @@ pub impl<T: Owned> WorkQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn steal(&mut self) -> Option<T> {
|
||||
pub fn steal(&mut self) -> Option<T> {
|
||||
unsafe {
|
||||
do self.queue.with |q| {
|
||||
if !q.is_empty() {
|
||||
@ -59,7 +59,7 @@ pub impl<T: Owned> WorkQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
unsafe {
|
||||
self.queue.with_imm(|q| q.is_empty() )
|
||||
}
|
||||
|
@ -136,8 +136,7 @@ pub struct ProcessOutput {
|
||||
error: ~[u8],
|
||||
}
|
||||
|
||||
pub impl Process {
|
||||
|
||||
impl Process {
|
||||
/**
|
||||
* Spawns a new Process.
|
||||
*
|
||||
@ -148,8 +147,8 @@ pub impl Process {
|
||||
* * options - Options to configure the environment of the process,
|
||||
* the working directory and the standard IO streams.
|
||||
*/
|
||||
pub fn new(prog: &str, args: &[~str], options: ProcessOptions) -> Process {
|
||||
|
||||
pub fn new(prog: &str, args: &[~str], options: ProcessOptions)
|
||||
-> Process {
|
||||
let (in_pipe, in_fd) = match options.in_fd {
|
||||
None => {
|
||||
let pipe = os::pipe();
|
||||
@ -192,9 +191,9 @@ pub impl Process {
|
||||
}
|
||||
|
||||
/// Returns the unique id of the process
|
||||
fn get_id(&self) -> pid_t { self.pid }
|
||||
pub fn get_id(&self) -> pid_t { self.pid }
|
||||
|
||||
priv fn input_fd(&mut self) -> c_int {
|
||||
fn input_fd(&mut self) -> c_int {
|
||||
match self.input {
|
||||
Some(fd) => fd,
|
||||
None => fail!("This Process's stdin was redirected to an \
|
||||
@ -202,7 +201,7 @@ pub impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn output_file(&mut self) -> *libc::FILE {
|
||||
fn output_file(&mut self) -> *libc::FILE {
|
||||
match self.output {
|
||||
Some(file) => file,
|
||||
None => fail!("This Process's stdout was redirected to an \
|
||||
@ -210,7 +209,7 @@ pub impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn error_file(&mut self) -> *libc::FILE {
|
||||
fn error_file(&mut self) -> *libc::FILE {
|
||||
match self.error {
|
||||
Some(file) => file,
|
||||
None => fail!("This Process's stderr was redirected to an \
|
||||
@ -225,7 +224,7 @@ pub impl Process {
|
||||
*
|
||||
* If this method returns true then self.input() will fail.
|
||||
*/
|
||||
fn input_redirected(&self) -> bool {
|
||||
pub fn input_redirected(&self) -> bool {
|
||||
self.input.is_none()
|
||||
}
|
||||
|
||||
@ -236,7 +235,7 @@ pub impl Process {
|
||||
*
|
||||
* If this method returns true then self.output() will fail.
|
||||
*/
|
||||
fn output_redirected(&self) -> bool {
|
||||
pub fn output_redirected(&self) -> bool {
|
||||
self.output.is_none()
|
||||
}
|
||||
|
||||
@ -247,7 +246,7 @@ pub impl Process {
|
||||
*
|
||||
* If this method returns true then self.error() will fail.
|
||||
*/
|
||||
fn error_redirected(&self) -> bool {
|
||||
pub fn error_redirected(&self) -> bool {
|
||||
self.error.is_none()
|
||||
}
|
||||
|
||||
@ -256,7 +255,7 @@ pub impl Process {
|
||||
*
|
||||
* Fails if this Process's stdin was redirected to an existing file descriptor.
|
||||
*/
|
||||
fn input(&mut self) -> @io::Writer {
|
||||
pub fn input(&mut self) -> @io::Writer {
|
||||
// FIXME: the Writer can still be used after self is destroyed: #2625
|
||||
io::fd_writer(self.input_fd(), false)
|
||||
}
|
||||
@ -266,7 +265,7 @@ pub impl Process {
|
||||
*
|
||||
* Fails if this Process's stdout was redirected to an existing file descriptor.
|
||||
*/
|
||||
fn output(&mut self) -> @io::Reader {
|
||||
pub fn output(&mut self) -> @io::Reader {
|
||||
// FIXME: the Reader can still be used after self is destroyed: #2625
|
||||
io::FILE_reader(self.output_file(), false)
|
||||
}
|
||||
@ -276,7 +275,7 @@ pub impl Process {
|
||||
*
|
||||
* Fails if this Process's stderr was redirected to an existing file descriptor.
|
||||
*/
|
||||
fn error(&mut self) -> @io::Reader {
|
||||
pub fn error(&mut self) -> @io::Reader {
|
||||
// FIXME: the Reader can still be used after self is destroyed: #2625
|
||||
io::FILE_reader(self.error_file(), false)
|
||||
}
|
||||
@ -287,7 +286,7 @@ pub impl Process {
|
||||
* If this process is reading its stdin from an existing file descriptor, then this
|
||||
* method does nothing.
|
||||
*/
|
||||
fn close_input(&mut self) {
|
||||
pub fn close_input(&mut self) {
|
||||
match self.input {
|
||||
Some(-1) | None => (),
|
||||
Some(fd) => {
|
||||
@ -299,7 +298,7 @@ pub impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
priv fn close_outputs(&mut self) {
|
||||
fn close_outputs(&mut self) {
|
||||
fclose_and_null(&mut self.output);
|
||||
fclose_and_null(&mut self.error);
|
||||
|
||||
@ -322,7 +321,7 @@ pub impl Process {
|
||||
*
|
||||
* If the child has already been finished then the exit code is returned.
|
||||
*/
|
||||
fn finish(&mut self) -> int {
|
||||
pub fn finish(&mut self) -> int {
|
||||
for self.exit_code.each |&code| {
|
||||
return code;
|
||||
}
|
||||
@ -342,8 +341,7 @@ pub impl Process {
|
||||
* This method will fail if the child process's stdout or stderr streams were
|
||||
* redirected to existing file descriptors.
|
||||
*/
|
||||
fn finish_with_output(&mut self) -> ProcessOutput {
|
||||
|
||||
pub fn finish_with_output(&mut self) -> ProcessOutput {
|
||||
let output_file = self.output_file();
|
||||
let error_file = self.error_file();
|
||||
|
||||
@ -378,8 +376,7 @@ pub impl Process {
|
||||
error: errs};
|
||||
}
|
||||
|
||||
priv fn destroy_internal(&mut self, force: bool) {
|
||||
|
||||
fn destroy_internal(&mut self, force: bool) {
|
||||
// if the process has finished, and therefore had waitpid called,
|
||||
// and we kill it, then on unix we might ending up killing a
|
||||
// newer process that happens to have the same (re-used) id
|
||||
@ -417,7 +414,7 @@ pub impl Process {
|
||||
* On Posix OSs SIGTERM will be sent to the process. On Win32
|
||||
* TerminateProcess(..) will be called.
|
||||
*/
|
||||
fn destroy(&mut self) { self.destroy_internal(false); }
|
||||
pub fn destroy(&mut self) { self.destroy_internal(false); }
|
||||
|
||||
/**
|
||||
* Terminates the process as soon as possible without giving it a
|
||||
@ -426,7 +423,7 @@ pub impl Process {
|
||||
* On Posix OSs SIGKILL will be sent to the process. On Win32
|
||||
* TerminateProcess(..) will be called.
|
||||
*/
|
||||
fn force_destroy(&mut self) { self.destroy_internal(true); }
|
||||
pub fn force_destroy(&mut self) { self.destroy_internal(true); }
|
||||
}
|
||||
|
||||
impl Drop for Process {
|
||||
|
@ -21,22 +21,22 @@ use vec::{CopyableVector, ImmutableVector, OwnedVector};
|
||||
#[deriving(Clone, Eq)]
|
||||
pub struct Ascii { priv chr: u8 }
|
||||
|
||||
pub impl Ascii {
|
||||
impl Ascii {
|
||||
/// Converts a ascii character into a `u8`.
|
||||
#[inline(always)]
|
||||
fn to_byte(self) -> u8 {
|
||||
pub fn to_byte(self) -> u8 {
|
||||
self.chr
|
||||
}
|
||||
|
||||
/// Converts a ascii character into a `char`.
|
||||
#[inline(always)]
|
||||
fn to_char(self) -> char {
|
||||
pub fn to_char(self) -> char {
|
||||
self.chr as char
|
||||
}
|
||||
|
||||
/// Convert to lowercase.
|
||||
#[inline(always)]
|
||||
fn to_lower(self) -> Ascii {
|
||||
pub fn to_lower(self) -> Ascii {
|
||||
if self.chr >= 65 && self.chr <= 90 {
|
||||
Ascii{chr: self.chr | 0x20 }
|
||||
} else {
|
||||
@ -46,7 +46,7 @@ pub impl Ascii {
|
||||
|
||||
/// Convert to uppercase.
|
||||
#[inline(always)]
|
||||
fn to_upper(self) -> Ascii {
|
||||
pub fn to_upper(self) -> Ascii {
|
||||
if self.chr >= 97 && self.chr <= 122 {
|
||||
Ascii{chr: self.chr & !0x20 }
|
||||
} else {
|
||||
@ -54,9 +54,9 @@ pub impl Ascii {
|
||||
}
|
||||
}
|
||||
|
||||
// Compares two ascii characters of equality, ignoring case.
|
||||
/// Compares two ascii characters of equality, ignoring case.
|
||||
#[inline(always)]
|
||||
fn eq_ignore_case(self, other: Ascii) -> bool {
|
||||
pub fn eq_ignore_case(self, other: Ascii) -> bool {
|
||||
self.to_lower().chr == other.to_lower().chr
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ pub fn task() -> TaskBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
priv impl TaskBuilder {
|
||||
impl TaskBuilder {
|
||||
fn consume(&mut self) -> TaskBuilder {
|
||||
if self.consumed {
|
||||
fail!("Cannot copy a task_builder"); // Fake move mode on self
|
||||
@ -224,24 +224,24 @@ priv impl TaskBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl TaskBuilder {
|
||||
impl TaskBuilder {
|
||||
/// Decouple the child task's failure from the parent's. If either fails,
|
||||
/// the other will not be killed.
|
||||
fn unlinked(&mut self) {
|
||||
pub fn unlinked(&mut self) {
|
||||
self.opts.linked = false;
|
||||
}
|
||||
|
||||
/// Unidirectionally link the child task's failure with the parent's. The
|
||||
/// child's failure will not kill the parent, but the parent's will kill
|
||||
/// the child.
|
||||
fn supervised(&mut self) {
|
||||
pub fn supervised(&mut self) {
|
||||
self.opts.supervised = true;
|
||||
self.opts.linked = false;
|
||||
}
|
||||
|
||||
/// Link the child task's and parent task's failures. If either fails, the
|
||||
/// other will be killed.
|
||||
fn linked(&mut self) {
|
||||
pub fn linked(&mut self) {
|
||||
self.opts.linked = true;
|
||||
self.opts.supervised = false;
|
||||
}
|
||||
@ -263,7 +263,7 @@ pub impl TaskBuilder {
|
||||
* # Failure
|
||||
* Fails if a future_result was already set for this task.
|
||||
*/
|
||||
fn future_result(&mut self, blk: &fn(v: Port<TaskResult>)) {
|
||||
pub fn future_result(&mut self, blk: &fn(v: Port<TaskResult>)) {
|
||||
// FIXME (#3725): Once linked failure and notification are
|
||||
// handled in the library, I can imagine implementing this by just
|
||||
// registering an arbitrary number of task::on_exit handlers and
|
||||
@ -283,7 +283,7 @@ pub impl TaskBuilder {
|
||||
}
|
||||
|
||||
/// Configure a custom scheduler mode for the task.
|
||||
fn sched_mode(&mut self, mode: SchedMode) {
|
||||
pub fn sched_mode(&mut self, mode: SchedMode) {
|
||||
self.opts.sched.mode = mode;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ pub impl TaskBuilder {
|
||||
* generator by applying the task body which results from the
|
||||
* existing body generator to the new body generator.
|
||||
*/
|
||||
fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) {
|
||||
pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) {
|
||||
let prev_gen_body = replace(&mut self.gen_body, None);
|
||||
let prev_gen_body = match prev_gen_body {
|
||||
Some(gen) => gen,
|
||||
@ -331,7 +331,7 @@ pub impl TaskBuilder {
|
||||
* When spawning into a new scheduler, the number of threads requested
|
||||
* must be greater than zero.
|
||||
*/
|
||||
fn spawn(&mut self, f: ~fn()) {
|
||||
pub fn spawn(&mut self, f: ~fn()) {
|
||||
let gen_body = replace(&mut self.gen_body, None);
|
||||
let notify_chan = replace(&mut self.opts.notify_chan, None);
|
||||
let x = self.consume();
|
||||
@ -353,7 +353,7 @@ pub impl TaskBuilder {
|
||||
}
|
||||
|
||||
/// Runs a task, while transfering ownership of one argument to the child.
|
||||
fn spawn_with<A:Owned>(&mut self, arg: A, f: ~fn(v: A)) {
|
||||
pub fn spawn_with<A:Owned>(&mut self, arg: A, f: ~fn(v: A)) {
|
||||
let arg = Cell(arg);
|
||||
do self.spawn {
|
||||
f(arg.take());
|
||||
@ -373,7 +373,7 @@ pub impl TaskBuilder {
|
||||
* # Failure
|
||||
* Fails if a future_result was already set for this task.
|
||||
*/
|
||||
fn try<T:Owned>(&mut self, f: ~fn() -> T) -> Result<T,()> {
|
||||
pub fn try<T:Owned>(&mut self, f: ~fn() -> T) -> Result<T,()> {
|
||||
let (po, ch) = stream::<T>();
|
||||
let mut result = None;
|
||||
|
||||
|
@ -145,28 +145,28 @@ impl<T> Map<uint, T> for TrieMap<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> TrieMap<T> {
|
||||
impl<T> TrieMap<T> {
|
||||
/// Create an empty TrieMap
|
||||
#[inline(always)]
|
||||
fn new() -> TrieMap<T> {
|
||||
pub fn new() -> TrieMap<T> {
|
||||
TrieMap{root: TrieNode::new(), length: 0}
|
||||
}
|
||||
|
||||
/// Visit all key-value pairs in reverse order
|
||||
#[inline(always)]
|
||||
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
||||
pub fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
|
||||
self.root.each_reverse(f)
|
||||
}
|
||||
|
||||
/// Visit all keys in reverse order
|
||||
#[inline(always)]
|
||||
fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {
|
||||
pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool {
|
||||
self.each_reverse(|k, _| f(k))
|
||||
}
|
||||
|
||||
/// Visit all values in reverse order
|
||||
#[inline(always)]
|
||||
fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool {
|
||||
pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool {
|
||||
self.each_reverse(|_, v| f(v))
|
||||
}
|
||||
}
|
||||
@ -208,28 +208,32 @@ impl Mutable for TrieSet {
|
||||
fn clear(&mut self) { self.map.clear() }
|
||||
}
|
||||
|
||||
pub impl TrieSet {
|
||||
impl TrieSet {
|
||||
/// Create an empty TrieSet
|
||||
#[inline(always)]
|
||||
fn new() -> TrieSet {
|
||||
pub fn new() -> TrieSet {
|
||||
TrieSet{map: TrieMap::new()}
|
||||
}
|
||||
|
||||
/// Return true if the set contains a value
|
||||
#[inline(always)]
|
||||
fn contains(&self, value: &uint) -> bool {
|
||||
pub fn contains(&self, value: &uint) -> bool {
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
||||
/// Add a value to the set. Return true if the value was not already
|
||||
/// present in the set.
|
||||
#[inline(always)]
|
||||
fn insert(&mut self, value: uint) -> bool { self.map.insert(value, ()) }
|
||||
pub fn insert(&mut self, value: uint) -> bool {
|
||||
self.map.insert(value, ())
|
||||
}
|
||||
|
||||
/// Remove a value from the set. Return true if the value was
|
||||
/// present in the set.
|
||||
#[inline(always)]
|
||||
fn remove(&mut self, value: &uint) -> bool { self.map.remove(value) }
|
||||
pub fn remove(&mut self, value: &uint) -> bool {
|
||||
self.map.remove(value)
|
||||
}
|
||||
}
|
||||
|
||||
struct TrieNode<T> {
|
||||
|
@ -139,8 +139,8 @@ pub mod ct {
|
||||
next: uint
|
||||
}
|
||||
|
||||
pub impl<T> Parsed<T> {
|
||||
fn new(val: T, next: uint) -> Parsed<T> {
|
||||
impl<T> Parsed<T> {
|
||||
pub fn new(val: T, next: uint) -> Parsed<T> {
|
||||
Parsed {val: val, next: next}
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +117,9 @@ fn LittleLock() -> LittleLock {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl LittleLock {
|
||||
impl LittleLock {
|
||||
#[inline(always)]
|
||||
unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
|
||||
pub unsafe fn lock<T>(&self, f: &fn() -> T) -> T {
|
||||
do atomically {
|
||||
rust_lock_little_lock(self.l);
|
||||
do (|| {
|
||||
@ -162,7 +162,7 @@ impl<T:Owned> Clone for Exclusive<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Owned> Exclusive<T> {
|
||||
impl<T:Owned> Exclusive<T> {
|
||||
// Exactly like std::arc::mutex_arc,access(), but with the little_lock
|
||||
// instead of a proper mutex. Same reason for being unsafe.
|
||||
//
|
||||
@ -170,7 +170,7 @@ pub impl<T:Owned> Exclusive<T> {
|
||||
// accessing the provided condition variable) are prohibited while inside
|
||||
// the exclusive. Supporting that is a work in progress.
|
||||
#[inline(always)]
|
||||
unsafe fn with<U>(&self, f: &fn(x: &mut T) -> U) -> U {
|
||||
pub unsafe fn with<U>(&self, f: &fn(x: &mut T) -> U) -> U {
|
||||
let rec = self.x.get();
|
||||
do (*rec).lock.lock {
|
||||
if (*rec).failed {
|
||||
@ -184,7 +184,7 @@ pub impl<T:Owned> Exclusive<T> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn with_imm<U>(&self, f: &fn(x: &T) -> U) -> U {
|
||||
pub unsafe fn with_imm<U>(&self, f: &fn(x: &T) -> U) -> U {
|
||||
do self.with |x| {
|
||||
f(cast::transmute_immut(x))
|
||||
}
|
||||
|
@ -90,9 +90,9 @@ pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } }
|
||||
/// A type with no inhabitants
|
||||
pub enum Void { }
|
||||
|
||||
pub impl Void {
|
||||
impl Void {
|
||||
/// A utility function for ignoring this uninhabited type
|
||||
fn uninhabited(self) -> ! {
|
||||
pub fn uninhabited(self) -> ! {
|
||||
match self {
|
||||
// Nothing to match on
|
||||
}
|
||||
|
@ -109,18 +109,18 @@ pub fn all_names() -> ~[&'static str] {
|
||||
AbiDatas.map(|d| d.name)
|
||||
}
|
||||
|
||||
pub impl Abi {
|
||||
impl Abi {
|
||||
#[inline]
|
||||
fn index(&self) -> uint {
|
||||
pub fn index(&self) -> uint {
|
||||
*self as uint
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn data(&self) -> &'static AbiData {
|
||||
pub fn data(&self) -> &'static AbiData {
|
||||
&AbiDatas[self.index()]
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
pub fn name(&self) -> &'static str {
|
||||
self.data().name
|
||||
}
|
||||
}
|
||||
@ -131,70 +131,70 @@ impl Architecture {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl AbiSet {
|
||||
fn from(abi: Abi) -> AbiSet {
|
||||
impl AbiSet {
|
||||
pub fn from(abi: Abi) -> AbiSet {
|
||||
AbiSet { bits: (1 << abi.index()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn Rust() -> AbiSet {
|
||||
pub fn Rust() -> AbiSet {
|
||||
AbiSet::from(Rust)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn C() -> AbiSet {
|
||||
pub fn C() -> AbiSet {
|
||||
AbiSet::from(C)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn Intrinsic() -> AbiSet {
|
||||
pub fn Intrinsic() -> AbiSet {
|
||||
AbiSet::from(RustIntrinsic)
|
||||
}
|
||||
|
||||
fn default() -> AbiSet {
|
||||
pub fn default() -> AbiSet {
|
||||
AbiSet::C()
|
||||
}
|
||||
|
||||
fn empty() -> AbiSet {
|
||||
pub fn empty() -> AbiSet {
|
||||
AbiSet { bits: 0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_rust(&self) -> bool {
|
||||
pub fn is_rust(&self) -> bool {
|
||||
self.bits == 1 << Rust.index()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_c(&self) -> bool {
|
||||
pub fn is_c(&self) -> bool {
|
||||
self.bits == 1 << C.index()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_intrinsic(&self) -> bool {
|
||||
pub fn is_intrinsic(&self) -> bool {
|
||||
self.bits == 1 << RustIntrinsic.index()
|
||||
}
|
||||
|
||||
fn contains(&self, abi: Abi) -> bool {
|
||||
pub fn contains(&self, abi: Abi) -> bool {
|
||||
(self.bits & (1 << abi.index())) != 0
|
||||
}
|
||||
|
||||
fn subset_of(&self, other_abi_set: AbiSet) -> bool {
|
||||
pub fn subset_of(&self, other_abi_set: AbiSet) -> bool {
|
||||
(self.bits & other_abi_set.bits) == self.bits
|
||||
}
|
||||
|
||||
fn add(&mut self, abi: Abi) {
|
||||
pub fn add(&mut self, abi: Abi) {
|
||||
self.bits |= (1 << abi.index());
|
||||
}
|
||||
|
||||
fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
|
||||
pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool {
|
||||
each_abi(|abi| !self.contains(abi) || op(abi))
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.bits == 0
|
||||
}
|
||||
|
||||
fn for_arch(&self, arch: Architecture) -> Option<Abi> {
|
||||
pub fn for_arch(&self, arch: Architecture) -> Option<Abi> {
|
||||
// NB---Single platform ABIs come first
|
||||
for self.each |abi| {
|
||||
let data = abi.data();
|
||||
@ -208,7 +208,7 @@ pub impl AbiSet {
|
||||
None
|
||||
}
|
||||
|
||||
fn check_valid(&self) -> Option<(Abi, Abi)> {
|
||||
pub fn check_valid(&self) -> Option<(Abi, Abi)> {
|
||||
let mut abis = ~[];
|
||||
for self.each |abi| { abis.push(abi); }
|
||||
|
||||
|
@ -166,14 +166,14 @@ pub struct Generics {
|
||||
ty_params: OptVec<TyParam>
|
||||
}
|
||||
|
||||
pub impl Generics {
|
||||
fn is_parameterized(&self) -> bool {
|
||||
impl Generics {
|
||||
pub fn is_parameterized(&self) -> bool {
|
||||
self.lifetimes.len() + self.ty_params.len() > 0
|
||||
}
|
||||
fn is_lt_parameterized(&self) -> bool {
|
||||
pub fn is_lt_parameterized(&self) -> bool {
|
||||
self.lifetimes.len() > 0
|
||||
}
|
||||
fn is_type_parameterized(&self) -> bool {
|
||||
pub fn is_type_parameterized(&self) -> bool {
|
||||
self.ty_params.len() > 0
|
||||
}
|
||||
}
|
||||
|
@ -373,17 +373,19 @@ pub struct id_range {
|
||||
max: node_id,
|
||||
}
|
||||
|
||||
pub impl id_range {
|
||||
fn max() -> id_range {
|
||||
id_range {min: int::max_value,
|
||||
max: int::min_value}
|
||||
impl id_range {
|
||||
pub fn max() -> id_range {
|
||||
id_range {
|
||||
min: int::max_value,
|
||||
max: int::min_value,
|
||||
}
|
||||
}
|
||||
|
||||
fn empty(&self) -> bool {
|
||||
pub fn empty(&self) -> bool {
|
||||
self.min >= self.max
|
||||
}
|
||||
|
||||
fn add(&mut self, id: node_id) {
|
||||
pub fn add(&mut self, id: node_id) {
|
||||
self.min = int::min(self.min, id);
|
||||
self.max = int::max(self.max, id + 1);
|
||||
}
|
||||
|
@ -271,13 +271,13 @@ pub struct FileMap {
|
||||
multibyte_chars: @mut ~[MultiByteChar],
|
||||
}
|
||||
|
||||
pub impl FileMap {
|
||||
impl FileMap {
|
||||
// EFFECT: register a start-of-line offset in the
|
||||
// table of line-beginnings.
|
||||
// UNCHECKED INVARIANT: these offsets must be added in the right
|
||||
// order and must be in the right places; there is shared knowledge
|
||||
// about what ends a line between this file and parse.rs
|
||||
fn next_line(&self, pos: BytePos) {
|
||||
pub fn next_line(&self, pos: BytePos) {
|
||||
// the new charpos must be > the last one (or it's the first one).
|
||||
let lines = &mut *self.lines;
|
||||
assert!((lines.len() == 0) || (lines[lines.len() - 1] < pos))
|
||||
@ -309,7 +309,7 @@ pub struct CodeMap {
|
||||
files: @mut ~[@FileMap]
|
||||
}
|
||||
|
||||
pub impl CodeMap {
|
||||
impl CodeMap {
|
||||
pub fn new() -> CodeMap {
|
||||
CodeMap {
|
||||
files: @mut ~[],
|
||||
@ -317,16 +317,15 @@ pub impl CodeMap {
|
||||
}
|
||||
|
||||
/// Add a new FileMap to the CodeMap and return it
|
||||
fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap {
|
||||
pub fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap {
|
||||
return self.new_filemap_w_substr(filename, FssNone, src);
|
||||
}
|
||||
|
||||
fn new_filemap_w_substr(
|
||||
&self,
|
||||
filename: FileName,
|
||||
substr: FileSubstr,
|
||||
src: @~str
|
||||
) -> @FileMap {
|
||||
pub fn new_filemap_w_substr(&self,
|
||||
filename: FileName,
|
||||
substr: FileSubstr,
|
||||
src: @~str)
|
||||
-> @FileMap {
|
||||
let files = &mut *self.files;
|
||||
let start_pos = if files.len() == 0 {
|
||||
0
|
||||
@ -359,8 +358,7 @@ pub impl CodeMap {
|
||||
return self.lookup_pos(pos);
|
||||
}
|
||||
|
||||
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt
|
||||
{
|
||||
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
|
||||
let loc = self.lookup_char_pos(pos);
|
||||
match (loc.file.substr) {
|
||||
FssNone =>
|
||||
@ -430,11 +428,9 @@ pub impl CodeMap {
|
||||
// (or expected function, found _|_)
|
||||
fail!(); // ("asking for " + filename + " which we don't know about");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
priv impl CodeMap {
|
||||
|
||||
impl CodeMap {
|
||||
fn lookup_filemap_idx(&self, pos: BytePos) -> uint {
|
||||
let files = &*self.files;
|
||||
let len = files.len();
|
||||
|
@ -219,8 +219,9 @@ pub struct ExtCtxt {
|
||||
trace_mac: @mut bool
|
||||
}
|
||||
|
||||
pub impl ExtCtxt {
|
||||
fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) -> @ExtCtxt {
|
||||
impl ExtCtxt {
|
||||
pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
|
||||
-> @ExtCtxt {
|
||||
@ExtCtxt {
|
||||
parse_sess: parse_sess,
|
||||
cfg: cfg,
|
||||
@ -230,21 +231,21 @@ pub impl ExtCtxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
|
||||
fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
|
||||
fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
|
||||
fn call_site(&self) -> span {
|
||||
pub fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
|
||||
pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
|
||||
pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
|
||||
pub fn call_site(&self) -> span {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
|
||||
None => self.bug("missing top span")
|
||||
}
|
||||
}
|
||||
fn print_backtrace(&self) { }
|
||||
fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
|
||||
fn mod_pop(&self) { self.mod_path.pop(); }
|
||||
fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
|
||||
fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
pub fn print_backtrace(&self) { }
|
||||
pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
||||
pub fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
|
||||
pub fn mod_pop(&self) { self.mod_path.pop(); }
|
||||
pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
|
||||
pub fn bt_push(&self, ei: codemap::ExpnInfo) {
|
||||
match ei {
|
||||
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
|
||||
*self.backtrace =
|
||||
@ -255,7 +256,7 @@ pub impl ExtCtxt {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn bt_pop(&self) {
|
||||
pub fn bt_pop(&self) {
|
||||
match *self.backtrace {
|
||||
Some(@ExpandedFrom(
|
||||
CallInfo {
|
||||
@ -266,43 +267,43 @@ pub impl ExtCtxt {
|
||||
_ => self.bug("tried to pop without a push")
|
||||
}
|
||||
}
|
||||
fn span_fatal(&self, sp: span, msg: &str) -> ! {
|
||||
pub fn span_fatal(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_fatal(sp, msg);
|
||||
}
|
||||
fn span_err(&self, sp: span, msg: &str) {
|
||||
pub fn span_err(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_err(sp, msg);
|
||||
}
|
||||
fn span_warn(&self, sp: span, msg: &str) {
|
||||
pub fn span_warn(&self, sp: span, msg: &str) {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_warn(sp, msg);
|
||||
}
|
||||
fn span_unimpl(&self, sp: span, msg: &str) -> ! {
|
||||
pub fn span_unimpl(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
|
||||
}
|
||||
fn span_bug(&self, sp: span, msg: &str) -> ! {
|
||||
pub fn span_bug(&self, sp: span, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||
}
|
||||
fn bug(&self, msg: &str) -> ! {
|
||||
pub fn bug(&self, msg: &str) -> ! {
|
||||
self.print_backtrace();
|
||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||
}
|
||||
fn next_id(&self) -> ast::node_id {
|
||||
pub fn next_id(&self) -> ast::node_id {
|
||||
parse::next_node_id(self.parse_sess)
|
||||
}
|
||||
fn trace_macros(&self) -> bool {
|
||||
pub fn trace_macros(&self) -> bool {
|
||||
*self.trace_mac
|
||||
}
|
||||
fn set_trace_macros(&self, x: bool) {
|
||||
pub fn set_trace_macros(&self, x: bool) {
|
||||
*self.trace_mac = x
|
||||
}
|
||||
fn str_of(&self, id: ast::ident) -> ~str {
|
||||
pub fn str_of(&self, id: ast::ident) -> ~str {
|
||||
copy *self.parse_sess.interner.get(id)
|
||||
}
|
||||
fn ident_of(&self, st: &str) -> ast::ident {
|
||||
pub fn ident_of(&self, st: &str) -> ast::ident {
|
||||
self.parse_sess.interner.intern(st)
|
||||
}
|
||||
}
|
||||
@ -436,7 +437,7 @@ impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{
|
||||
}
|
||||
|
||||
// traits just don't work anywhere...?
|
||||
//pub impl Map<Name,SyntaxExtension> for MapChain {
|
||||
//impl Map<Name,SyntaxExtension> for MapChain {
|
||||
|
||||
fn contains_key (&self, key: &K) -> bool {
|
||||
match *self {
|
||||
|
@ -38,15 +38,18 @@ pub struct Path<'self> {
|
||||
global: bool
|
||||
}
|
||||
|
||||
pub impl<'self> Path<'self> {
|
||||
fn new<'r>(path: ~[&'r str]) -> Path<'r> {
|
||||
impl<'self> Path<'self> {
|
||||
pub fn new<'r>(path: ~[&'r str]) -> Path<'r> {
|
||||
Path::new_(path, None, ~[], true)
|
||||
}
|
||||
fn new_local<'r>(path: &'r str) -> Path<'r> {
|
||||
pub fn new_local<'r>(path: &'r str) -> Path<'r> {
|
||||
Path::new_(~[ path ], None, ~[], false)
|
||||
}
|
||||
fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], global: bool)
|
||||
-> Path<'r> {
|
||||
pub fn new_<'r>(path: ~[&'r str],
|
||||
lifetime: Option<&'r str>,
|
||||
params: ~[~Ty<'r>],
|
||||
global: bool)
|
||||
-> Path<'r> {
|
||||
Path {
|
||||
path: path,
|
||||
lifetime: lifetime,
|
||||
@ -55,13 +58,21 @@ pub impl<'self> Path<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_ty(&self, cx: @ExtCtxt, span: span,
|
||||
self_ty: ident, self_generics: &Generics) -> @ast::Ty {
|
||||
pub fn to_ty(&self,
|
||||
cx: @ExtCtxt,
|
||||
span: span,
|
||||
self_ty: ident,
|
||||
self_generics: &Generics)
|
||||
-> @ast::Ty {
|
||||
cx.ty_path(self.to_path(cx, span,
|
||||
self_ty, self_generics))
|
||||
}
|
||||
fn to_path(&self, cx: @ExtCtxt, span: span,
|
||||
self_ty: ident, self_generics: &Generics) -> @ast::Path {
|
||||
pub fn to_path(&self,
|
||||
cx: @ExtCtxt,
|
||||
span: span,
|
||||
self_ty: ident,
|
||||
self_generics: &Generics)
|
||||
-> @ast::Path {
|
||||
let idents = self.path.map(|s| cx.ident_of(*s) );
|
||||
let lt = mk_lifetime(cx, span, &self.lifetime);
|
||||
let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics));
|
||||
@ -108,9 +119,13 @@ fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Life
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<'self> Ty<'self> {
|
||||
fn to_ty(&self, cx: @ExtCtxt, span: span,
|
||||
self_ty: ident, self_generics: &Generics) -> @ast::Ty {
|
||||
impl<'self> Ty<'self> {
|
||||
pub fn to_ty(&self,
|
||||
cx: @ExtCtxt,
|
||||
span: span,
|
||||
self_ty: ident,
|
||||
self_generics: &Generics)
|
||||
-> @ast::Ty {
|
||||
match *self {
|
||||
Ptr(ref ty, ref ptr) => {
|
||||
let raw_ty = ty.to_ty(cx, span, self_ty, self_generics);
|
||||
@ -143,8 +158,12 @@ pub impl<'self> Ty<'self> {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_path(&self, cx: @ExtCtxt, span: span,
|
||||
self_ty: ident, self_generics: &Generics) -> @ast::Path {
|
||||
pub fn to_path(&self,
|
||||
cx: @ExtCtxt,
|
||||
span: span,
|
||||
self_ty: ident,
|
||||
self_generics: &Generics)
|
||||
-> @ast::Path {
|
||||
match *self {
|
||||
Self => {
|
||||
let self_params = do self_generics.ty_params.map |ty_param| {
|
||||
@ -192,14 +211,18 @@ pub struct LifetimeBounds<'self> {
|
||||
bounds: ~[(&'self str, ~[Path<'self>])]
|
||||
}
|
||||
|
||||
pub impl<'self> LifetimeBounds<'self> {
|
||||
fn empty() -> LifetimeBounds<'static> {
|
||||
impl<'self> LifetimeBounds<'self> {
|
||||
pub fn empty() -> LifetimeBounds<'static> {
|
||||
LifetimeBounds {
|
||||
lifetimes: ~[], bounds: ~[]
|
||||
}
|
||||
}
|
||||
fn to_generics(&self, cx: @ExtCtxt, span: span,
|
||||
self_ty: ident, self_generics: &Generics) -> Generics {
|
||||
pub fn to_generics(&self,
|
||||
cx: @ExtCtxt,
|
||||
span: span,
|
||||
self_ty: ident,
|
||||
self_generics: &Generics)
|
||||
-> Generics {
|
||||
let lifetimes = do self.lifetimes.map |lt| {
|
||||
cx.lifetime(span, cx.ident_of(*lt))
|
||||
};
|
||||
|
@ -28,8 +28,8 @@ impl ToStr for direction {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl direction {
|
||||
fn reverse(&self) -> direction {
|
||||
impl direction {
|
||||
pub fn reverse(&self) -> direction {
|
||||
match *self {
|
||||
send => recv,
|
||||
recv => send
|
||||
@ -45,21 +45,21 @@ pub struct next_state {
|
||||
// name, span, data, current state, next state
|
||||
pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>);
|
||||
|
||||
pub impl message {
|
||||
fn name(&mut self) -> ~str {
|
||||
impl message {
|
||||
pub fn name(&mut self) -> ~str {
|
||||
match *self {
|
||||
message(ref id, _, _, _, _) => copy *id
|
||||
}
|
||||
}
|
||||
|
||||
fn span(&mut self) -> span {
|
||||
pub fn span(&mut self) -> span {
|
||||
match *self {
|
||||
message(_, span, _, _, _) => span
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the type parameters actually used by this message
|
||||
fn get_generics(&self) -> ast::Generics {
|
||||
pub fn get_generics(&self) -> ast::Generics {
|
||||
match *self {
|
||||
message(_, _, _, this, _) => copy this.generics
|
||||
}
|
||||
@ -79,23 +79,26 @@ pub struct state_ {
|
||||
proto: protocol
|
||||
}
|
||||
|
||||
pub impl state_ {
|
||||
fn add_message(@self, name: ~str, span: span,
|
||||
data: ~[@ast::Ty], next: Option<next_state>) {
|
||||
impl state_ {
|
||||
pub fn add_message(@self,
|
||||
name: ~str,
|
||||
span: span,
|
||||
data: ~[@ast::Ty],
|
||||
next: Option<next_state>) {
|
||||
self.messages.push(message(name, span, data, self,
|
||||
next));
|
||||
}
|
||||
|
||||
fn filename(&self) -> ~str {
|
||||
pub fn filename(&self) -> ~str {
|
||||
self.proto.filename()
|
||||
}
|
||||
|
||||
fn data_name(&self) -> ast::ident {
|
||||
pub fn data_name(&self) -> ast::ident {
|
||||
self.ident
|
||||
}
|
||||
|
||||
/// Returns the type that is used for the messages.
|
||||
fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty {
|
||||
pub fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty {
|
||||
cx.ty_path
|
||||
(path(~[cx.ident_of(self.name)],self.span).add_tys(
|
||||
cx.ty_vars(&self.generics.ty_params)))
|
||||
@ -103,7 +106,7 @@ pub impl state_ {
|
||||
|
||||
/// Iterate over the states that can be reached in one message
|
||||
/// from this state.
|
||||
fn reachable(&self, f: &fn(state) -> bool) -> bool {
|
||||
pub fn reachable(&self, f: &fn(state) -> bool) -> bool {
|
||||
for self.messages.each |m| {
|
||||
match *m {
|
||||
message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
|
||||
@ -140,28 +143,28 @@ pub struct protocol_ {
|
||||
bounded: Option<bool>,
|
||||
}
|
||||
|
||||
pub impl protocol_ {
|
||||
impl protocol_ {
|
||||
/// Get a state.
|
||||
fn get_state(&self, name: &str) -> state {
|
||||
pub fn get_state(&self, name: &str) -> state {
|
||||
self.states.find(|i| name == i.name).get()
|
||||
}
|
||||
|
||||
fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
|
||||
pub fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
|
||||
|
||||
fn has_state(&self, name: &str) -> bool {
|
||||
pub fn has_state(&self, name: &str) -> bool {
|
||||
self.states.find(|i| name == i.name).is_some()
|
||||
}
|
||||
|
||||
fn filename(&self) -> ~str {
|
||||
pub fn filename(&self) -> ~str {
|
||||
~"proto://" + self.name
|
||||
}
|
||||
|
||||
fn num_states(&self) -> uint {
|
||||
pub fn num_states(&self) -> uint {
|
||||
let states = &mut *self.states;
|
||||
states.len()
|
||||
}
|
||||
|
||||
fn has_ty_params(&self) -> bool {
|
||||
pub fn has_ty_params(&self) -> bool {
|
||||
for self.states.each |s| {
|
||||
if s.generics.ty_params.len() > 0 {
|
||||
return true;
|
||||
@ -169,19 +172,20 @@ pub impl protocol_ {
|
||||
}
|
||||
false
|
||||
}
|
||||
fn is_bounded(&self) -> bool {
|
||||
|
||||
pub fn is_bounded(&self) -> bool {
|
||||
let bounded = self.bounded.get();
|
||||
bounded
|
||||
}
|
||||
}
|
||||
|
||||
pub impl protocol_ {
|
||||
fn add_state_poly(@mut self,
|
||||
name: ~str,
|
||||
ident: ast::ident,
|
||||
dir: direction,
|
||||
generics: ast::Generics)
|
||||
-> state {
|
||||
impl protocol_ {
|
||||
pub fn add_state_poly(@mut self,
|
||||
name: ~str,
|
||||
ident: ast::ident,
|
||||
dir: direction,
|
||||
generics: ast::Generics)
|
||||
-> state {
|
||||
let messages = @mut ~[];
|
||||
let states = &mut *self.states;
|
||||
|
||||
|
@ -52,18 +52,18 @@ pub fn token_to_str(reader: @reader, token: &token::Token) -> ~str {
|
||||
token::to_str(reader.interner(), token)
|
||||
}
|
||||
|
||||
pub impl Parser {
|
||||
impl Parser {
|
||||
// convert a token to a string using self's reader
|
||||
fn token_to_str(&self, token: &token::Token) -> ~str {
|
||||
pub fn token_to_str(&self, token: &token::Token) -> ~str {
|
||||
token::to_str(self.reader.interner(), token)
|
||||
}
|
||||
|
||||
// convert the current token to a string using self's reader
|
||||
fn this_token_to_str(&self) -> ~str {
|
||||
pub fn this_token_to_str(&self) -> ~str {
|
||||
self.token_to_str(self.token)
|
||||
}
|
||||
|
||||
fn unexpected_last(&self, t: &token::Token) -> ! {
|
||||
pub fn unexpected_last(&self, t: &token::Token) -> ! {
|
||||
self.span_fatal(
|
||||
*self.last_span,
|
||||
fmt!(
|
||||
@ -73,7 +73,7 @@ pub impl Parser {
|
||||
);
|
||||
}
|
||||
|
||||
fn unexpected(&self) -> ! {
|
||||
pub fn unexpected(&self) -> ! {
|
||||
self.fatal(
|
||||
fmt!(
|
||||
"unexpected token: `%s`",
|
||||
@ -84,7 +84,7 @@ pub impl Parser {
|
||||
|
||||
// expect and consume the token t. Signal an error if
|
||||
// the next token is not t.
|
||||
fn expect(&self, t: &token::Token) {
|
||||
pub fn expect(&self, t: &token::Token) {
|
||||
if *self.token == *t {
|
||||
self.bump();
|
||||
} else {
|
||||
@ -98,7 +98,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_ident(&self) -> ast::ident {
|
||||
pub fn parse_ident(&self) -> ast::ident {
|
||||
self.check_strict_keywords();
|
||||
self.check_reserved_keywords();
|
||||
match *self.token {
|
||||
@ -120,7 +120,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_path_list_ident(&self) -> ast::path_list_ident {
|
||||
pub fn parse_path_list_ident(&self) -> ast::path_list_ident {
|
||||
let lo = self.span.lo;
|
||||
let ident = self.parse_ident();
|
||||
let hi = self.last_span.hi;
|
||||
@ -130,17 +130,17 @@ pub impl Parser {
|
||||
|
||||
// consume token 'tok' if it exists. Returns true if the given
|
||||
// token was present, false otherwise.
|
||||
fn eat(&self, tok: &token::Token) -> bool {
|
||||
pub fn eat(&self, tok: &token::Token) -> bool {
|
||||
return if *self.token == *tok { self.bump(); true } else { false };
|
||||
}
|
||||
|
||||
fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
token::is_keyword(kw, self.token)
|
||||
}
|
||||
|
||||
// if the next token is the given keyword, eat it and return
|
||||
// true. Otherwise, return false.
|
||||
fn eat_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
pub fn eat_keyword(&self, kw: keywords::Keyword) -> bool {
|
||||
let is_kw = match *self.token {
|
||||
token::IDENT(sid, false) => kw.to_ident().repr == sid.repr,
|
||||
_ => false
|
||||
@ -152,7 +152,7 @@ pub impl Parser {
|
||||
// if the given word is not a keyword, signal an error.
|
||||
// if the next token is not the given word, signal an error.
|
||||
// otherwise, eat it.
|
||||
fn expect_keyword(&self, kw: keywords::Keyword) {
|
||||
pub fn expect_keyword(&self, kw: keywords::Keyword) {
|
||||
if !self.eat_keyword(kw) {
|
||||
self.fatal(
|
||||
fmt!(
|
||||
@ -165,7 +165,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// signal an error if the given string is a strict keyword
|
||||
fn check_strict_keywords(&self) {
|
||||
pub fn check_strict_keywords(&self) {
|
||||
if token::is_strict_keyword(self.token) {
|
||||
self.span_err(*self.last_span,
|
||||
fmt!("found `%s` in ident position", self.this_token_to_str()));
|
||||
@ -173,7 +173,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// signal an error if the current token is a reserved keyword
|
||||
fn check_reserved_keywords(&self) {
|
||||
pub fn check_reserved_keywords(&self) {
|
||||
if token::is_reserved_keyword(self.token) {
|
||||
self.fatal(fmt!("`%s` is a reserved keyword", self.this_token_to_str()));
|
||||
}
|
||||
@ -182,7 +182,7 @@ pub impl Parser {
|
||||
// expect and consume a GT. if a >> is seen, replace it
|
||||
// with a single > and continue. If a GT is not seen,
|
||||
// signal an error.
|
||||
fn expect_gt(&self) {
|
||||
pub fn expect_gt(&self) {
|
||||
if *self.token == token::GT {
|
||||
self.bump();
|
||||
} else if *self.token == token::BINOP(token::SHR) {
|
||||
@ -203,11 +203,10 @@ pub impl Parser {
|
||||
|
||||
// parse a sequence bracketed by '<' and '>', stopping
|
||||
// before the '>'.
|
||||
fn parse_seq_to_before_gt<T: Copy>(
|
||||
&self,
|
||||
sep: Option<token::Token>,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> OptVec<T> {
|
||||
pub fn parse_seq_to_before_gt<T: Copy>(&self,
|
||||
sep: Option<token::Token>,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> OptVec<T> {
|
||||
let mut first = true;
|
||||
let mut v = opt_vec::Empty;
|
||||
while *self.token != token::GT
|
||||
@ -224,11 +223,10 @@ pub impl Parser {
|
||||
return v;
|
||||
}
|
||||
|
||||
fn parse_seq_to_gt<T: Copy>(
|
||||
&self,
|
||||
sep: Option<token::Token>,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> OptVec<T> {
|
||||
pub fn parse_seq_to_gt<T: Copy>(&self,
|
||||
sep: Option<token::Token>,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> OptVec<T> {
|
||||
let v = self.parse_seq_to_before_gt(sep, f);
|
||||
self.expect_gt();
|
||||
return v;
|
||||
@ -237,12 +235,11 @@ pub impl Parser {
|
||||
// parse a sequence, including the closing delimiter. The function
|
||||
// f must consume tokens until reaching the next separator or
|
||||
// closing bracket.
|
||||
fn parse_seq_to_end<T: Copy>(
|
||||
&self,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> ~[T] {
|
||||
pub fn parse_seq_to_end<T: Copy>(&self,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> ~[T] {
|
||||
let val = self.parse_seq_to_before_end(ket, sep, f);
|
||||
self.bump();
|
||||
val
|
||||
@ -251,12 +248,11 @@ pub impl Parser {
|
||||
// parse a sequence, not including the closing delimiter. The function
|
||||
// f must consume tokens until reaching the next separator or
|
||||
// closing bracket.
|
||||
fn parse_seq_to_before_end<T: Copy>(
|
||||
&self,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> ~[T] {
|
||||
pub fn parse_seq_to_before_end<T: Copy>(&self,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> ~[T] {
|
||||
let mut first: bool = true;
|
||||
let mut v: ~[T] = ~[];
|
||||
while *self.token != *ket {
|
||||
@ -276,13 +272,12 @@ pub impl Parser {
|
||||
// parse a sequence, including the closing delimiter. The function
|
||||
// f must consume tokens until reaching the next separator or
|
||||
// closing bracket.
|
||||
fn parse_unspanned_seq<T: Copy>(
|
||||
&self,
|
||||
bra: &token::Token,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> ~[T] {
|
||||
pub fn parse_unspanned_seq<T: Copy>(&self,
|
||||
bra: &token::Token,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> ~[T] {
|
||||
self.expect(bra);
|
||||
let result = self.parse_seq_to_before_end(ket, sep, f);
|
||||
self.bump();
|
||||
@ -291,13 +286,12 @@ pub impl Parser {
|
||||
|
||||
// NB: Do not use this function unless you actually plan to place the
|
||||
// spanned list in the AST.
|
||||
fn parse_seq<T: Copy>(
|
||||
&self,
|
||||
bra: &token::Token,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T
|
||||
) -> spanned<~[T]> {
|
||||
pub fn parse_seq<T: Copy>(&self,
|
||||
bra: &token::Token,
|
||||
ket: &token::Token,
|
||||
sep: SeqSep,
|
||||
f: &fn(&Parser) -> T)
|
||||
-> spanned<~[T]> {
|
||||
let lo = self.span.lo;
|
||||
self.expect(bra);
|
||||
let result = self.parse_seq_to_before_end(ket, sep, f);
|
||||
|
@ -73,9 +73,9 @@ impl to_bytes::IterBytes for ObsoleteSyntax {
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Parser {
|
||||
impl Parser {
|
||||
/// Reports an obsolete syntax non-fatal error.
|
||||
fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
|
||||
pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) {
|
||||
let (kind_str, desc) = match kind {
|
||||
ObsoleteLowerCaseKindBounds => (
|
||||
"lower-case kind bounds",
|
||||
@ -232,13 +232,16 @@ pub impl Parser {
|
||||
|
||||
// Reports an obsolete syntax non-fatal error, and returns
|
||||
// a placeholder expression
|
||||
fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr {
|
||||
pub fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr {
|
||||
self.obsolete(sp, kind);
|
||||
self.mk_expr(sp.lo, sp.hi, expr_lit(@respan(sp, lit_nil)))
|
||||
}
|
||||
|
||||
priv fn report(&self, sp: span, kind: ObsoleteSyntax, kind_str: &str,
|
||||
desc: &str) {
|
||||
fn report(&self,
|
||||
sp: span,
|
||||
kind: ObsoleteSyntax,
|
||||
kind_str: &str,
|
||||
desc: &str) {
|
||||
self.span_err(sp, fmt!("obsolete syntax: %s", kind_str));
|
||||
|
||||
if !self.obsolete_set.contains(&kind) {
|
||||
@ -247,7 +250,8 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn token_is_obsolete_ident(&self, ident: &str, token: &Token) -> bool {
|
||||
pub fn token_is_obsolete_ident(&self, ident: &str, token: &Token)
|
||||
-> bool {
|
||||
match *token {
|
||||
token::IDENT(sid, _) => {
|
||||
str::eq_slice(*self.id_to_str(sid), ident)
|
||||
@ -256,11 +260,11 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_obsolete_ident(&self, ident: &str) -> bool {
|
||||
pub fn is_obsolete_ident(&self, ident: &str) -> bool {
|
||||
self.token_is_obsolete_ident(ident, self.token)
|
||||
}
|
||||
|
||||
fn eat_obsolete_ident(&self, ident: &str) -> bool {
|
||||
pub fn eat_obsolete_ident(&self, ident: &str) -> bool {
|
||||
if self.is_obsolete_ident(ident) {
|
||||
self.bump();
|
||||
true
|
||||
@ -269,7 +273,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_obsolete_struct_ctor(&self) -> bool {
|
||||
pub fn try_parse_obsolete_struct_ctor(&self) -> bool {
|
||||
if self.eat_obsolete_ident("new") {
|
||||
self.obsolete(*self.last_span, ObsoleteStructCtor);
|
||||
self.parse_fn_decl();
|
||||
@ -280,7 +284,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_obsolete_with(&self) -> bool {
|
||||
pub fn try_parse_obsolete_with(&self) -> bool {
|
||||
if *self.token == token::COMMA
|
||||
&& self.token_is_obsolete_ident("with",
|
||||
&self.look_ahead(1u)) {
|
||||
@ -295,7 +299,8 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) -> bool {
|
||||
pub fn try_parse_obsolete_priv_section(&self, attrs: &[attribute])
|
||||
-> bool {
|
||||
if self.is_keyword(keywords::Priv) && self.look_ahead(1) == token::LBRACE {
|
||||
self.obsolete(copy *self.span, ObsoletePrivSection);
|
||||
self.eat_keyword(keywords::Priv);
|
||||
|
@ -272,9 +272,9 @@ impl Drop for Parser {
|
||||
fn finalize(&self) {}
|
||||
}
|
||||
|
||||
pub impl Parser {
|
||||
impl Parser {
|
||||
// advance the parser by one token
|
||||
fn bump(&self) {
|
||||
pub fn bump(&self) {
|
||||
*self.last_span = copy *self.span;
|
||||
let next = if *self.buffer_start == *self.buffer_end {
|
||||
self.reader.next_token()
|
||||
@ -288,17 +288,20 @@ pub impl Parser {
|
||||
*self.tokens_consumed += 1u;
|
||||
}
|
||||
// EFFECT: replace the current token and span with the given one
|
||||
fn replace_token(&self, next: token::Token, lo: BytePos, hi: BytePos) {
|
||||
pub fn replace_token(&self,
|
||||
next: token::Token,
|
||||
lo: BytePos,
|
||||
hi: BytePos) {
|
||||
*self.token = next;
|
||||
*self.span = mk_sp(lo, hi);
|
||||
}
|
||||
fn buffer_length(&self) -> int {
|
||||
pub fn buffer_length(&self) -> int {
|
||||
if *self.buffer_start <= *self.buffer_end {
|
||||
return *self.buffer_end - *self.buffer_start;
|
||||
}
|
||||
return (4 - *self.buffer_start) + *self.buffer_end;
|
||||
}
|
||||
fn look_ahead(&self, distance: uint) -> token::Token {
|
||||
pub fn look_ahead(&self, distance: uint) -> token::Token {
|
||||
let dist = distance as int;
|
||||
while self.buffer_length() < dist {
|
||||
self.buffer[*self.buffer_end] = self.reader.next_token();
|
||||
@ -306,49 +309,49 @@ pub impl Parser {
|
||||
}
|
||||
return copy self.buffer[(*self.buffer_start + dist - 1) & 3].tok;
|
||||
}
|
||||
fn fatal(&self, m: &str) -> ! {
|
||||
pub fn fatal(&self, m: &str) -> ! {
|
||||
self.sess.span_diagnostic.span_fatal(*copy self.span, m)
|
||||
}
|
||||
fn span_fatal(&self, sp: span, m: &str) -> ! {
|
||||
pub fn span_fatal(&self, sp: span, m: &str) -> ! {
|
||||
self.sess.span_diagnostic.span_fatal(sp, m)
|
||||
}
|
||||
fn span_note(&self, sp: span, m: &str) {
|
||||
pub fn span_note(&self, sp: span, m: &str) {
|
||||
self.sess.span_diagnostic.span_note(sp, m)
|
||||
}
|
||||
fn bug(&self, m: &str) -> ! {
|
||||
pub fn bug(&self, m: &str) -> ! {
|
||||
self.sess.span_diagnostic.span_bug(*copy self.span, m)
|
||||
}
|
||||
fn warn(&self, m: &str) {
|
||||
pub fn warn(&self, m: &str) {
|
||||
self.sess.span_diagnostic.span_warn(*copy self.span, m)
|
||||
}
|
||||
fn span_err(&self, sp: span, m: &str) {
|
||||
pub fn span_err(&self, sp: span, m: &str) {
|
||||
self.sess.span_diagnostic.span_err(sp, m)
|
||||
}
|
||||
fn abort_if_errors(&self) {
|
||||
pub fn abort_if_errors(&self) {
|
||||
self.sess.span_diagnostic.handler().abort_if_errors();
|
||||
}
|
||||
fn get_id(&self) -> node_id { next_node_id(self.sess) }
|
||||
pub fn get_id(&self) -> node_id { next_node_id(self.sess) }
|
||||
|
||||
fn id_to_str(&self, id: ident) -> @~str {
|
||||
pub fn id_to_str(&self, id: ident) -> @~str {
|
||||
self.sess.interner.get(id)
|
||||
}
|
||||
|
||||
// is this one of the keywords that signals a closure type?
|
||||
fn token_is_closure_keyword(&self, tok: &token::Token) -> bool {
|
||||
pub fn token_is_closure_keyword(&self, tok: &token::Token) -> bool {
|
||||
token::is_keyword(keywords::Pure, tok) ||
|
||||
token::is_keyword(keywords::Unsafe, tok) ||
|
||||
token::is_keyword(keywords::Once, tok) ||
|
||||
token::is_keyword(keywords::Fn, tok)
|
||||
}
|
||||
|
||||
fn token_is_lifetime(&self, tok: &token::Token) -> bool {
|
||||
pub fn token_is_lifetime(&self, tok: &token::Token) -> bool {
|
||||
match *tok {
|
||||
token::LIFETIME(*) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lifetime(&self, tok: &token::Token) -> ast::ident {
|
||||
pub fn get_lifetime(&self, tok: &token::Token) -> ast::ident {
|
||||
match *tok {
|
||||
token::LIFETIME(ref ident) => copy *ident,
|
||||
_ => self.bug("not a lifetime"),
|
||||
@ -356,8 +359,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a ty_bare_fun type:
|
||||
fn parse_ty_bare_fn(&self) -> ty_
|
||||
{
|
||||
pub fn parse_ty_bare_fn(&self) -> ty_ {
|
||||
/*
|
||||
|
||||
extern "ABI" [pure|unsafe] fn <'lt> (S) -> T
|
||||
@ -386,10 +388,10 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a ty_closure type
|
||||
fn parse_ty_closure(&self,
|
||||
sigil: ast::Sigil,
|
||||
region: Option<@ast::Lifetime>)
|
||||
-> ty_ {
|
||||
pub fn parse_ty_closure(&self,
|
||||
sigil: ast::Sigil,
|
||||
region: Option<@ast::Lifetime>)
|
||||
-> ty_ {
|
||||
/*
|
||||
|
||||
(&|~|@) ['r] [pure|unsafe] [once] fn [:Bounds] <'lt> (S) -> T
|
||||
@ -440,7 +442,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// looks like this should be called parse_unsafety
|
||||
fn parse_unsafety(&self) -> purity {
|
||||
pub fn parse_unsafety(&self) -> purity {
|
||||
if self.eat_keyword(keywords::Pure) {
|
||||
self.obsolete(*self.last_span, ObsoletePurity);
|
||||
return impure_fn;
|
||||
@ -452,7 +454,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a function type (following the 'fn')
|
||||
fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec<ast::Lifetime>) {
|
||||
pub fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec<ast::Lifetime>) {
|
||||
/*
|
||||
|
||||
(fn) <'lt> (S) -> T
|
||||
@ -487,7 +489,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse the methods in a trait declaration
|
||||
fn parse_trait_methods(&self) -> ~[trait_method] {
|
||||
pub fn parse_trait_methods(&self) -> ~[trait_method] {
|
||||
do self.parse_unspanned_seq(
|
||||
&token::LBRACE,
|
||||
&token::RBRACE,
|
||||
@ -563,9 +565,8 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// parse a possibly mutable type
|
||||
fn parse_mt(&self) -> mt {
|
||||
pub fn parse_mt(&self) -> mt {
|
||||
let mutbl = self.parse_mutability();
|
||||
let t = self.parse_ty(false);
|
||||
mt { ty: t, mutbl: mutbl }
|
||||
@ -573,7 +574,7 @@ pub impl Parser {
|
||||
|
||||
// parse [mut/const/imm] ID : TY
|
||||
// now used only by obsolete record syntax parser...
|
||||
fn parse_ty_field(&self) -> ty_field {
|
||||
pub fn parse_ty_field(&self) -> ty_field {
|
||||
let lo = self.span.lo;
|
||||
let mutbl = self.parse_mutability();
|
||||
let id = self.parse_ident();
|
||||
@ -590,7 +591,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse optional return type [ -> TY ] in function decl
|
||||
fn parse_ret_ty(&self) -> (ret_style, @Ty) {
|
||||
pub fn parse_ret_ty(&self) -> (ret_style, @Ty) {
|
||||
return if self.eat(&token::RARROW) {
|
||||
let lo = self.span.lo;
|
||||
if self.eat(&token::NOT) {
|
||||
@ -621,7 +622,7 @@ pub impl Parser {
|
||||
// parse a type.
|
||||
// Useless second parameter for compatibility with quasiquote macros.
|
||||
// Bleh!
|
||||
fn parse_ty(&self, _: bool) -> @Ty {
|
||||
pub fn parse_ty(&self, _: bool) -> @Ty {
|
||||
maybe_whole!(self, nt_ty);
|
||||
|
||||
let lo = self.span.lo;
|
||||
@ -722,11 +723,9 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse the type following a @ or a ~
|
||||
fn parse_box_or_uniq_pointee(
|
||||
&self,
|
||||
sigil: ast::Sigil,
|
||||
ctor: &fn(v: mt) -> ty_) -> ty_
|
||||
{
|
||||
pub fn parse_box_or_uniq_pointee(&self,
|
||||
sigil: ast::Sigil,
|
||||
ctor: &fn(v: mt) -> ty_) -> ty_ {
|
||||
// @'foo fn() or @foo/fn() or @fn() are parsed directly as fn types:
|
||||
match *self.token {
|
||||
token::LIFETIME(*) => {
|
||||
@ -765,7 +764,7 @@ pub impl Parser {
|
||||
ctor(mt)
|
||||
}
|
||||
|
||||
fn parse_borrowed_pointee(&self) -> ty_ {
|
||||
pub fn parse_borrowed_pointee(&self) -> ty_ {
|
||||
// look for `&'lt` or `&'foo ` and interpret `foo` as the region name:
|
||||
let opt_lifetime = self.parse_opt_lifetime();
|
||||
|
||||
@ -778,7 +777,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse an optional, obsolete argument mode.
|
||||
fn parse_arg_mode(&self) {
|
||||
pub fn parse_arg_mode(&self) {
|
||||
if self.eat(&token::BINOP(token::MINUS)) {
|
||||
self.obsolete(*self.span, ObsoleteMode);
|
||||
} else if self.eat(&token::ANDAND) {
|
||||
@ -794,7 +793,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_named_argument(&self) -> bool {
|
||||
pub fn is_named_argument(&self) -> bool {
|
||||
let offset = if *self.token == token::BINOP(token::AND) {
|
||||
1
|
||||
} else if *self.token == token::BINOP(token::MINUS) {
|
||||
@ -819,7 +818,7 @@ pub impl Parser {
|
||||
|
||||
// This version of parse arg doesn't necessarily require
|
||||
// identifier names.
|
||||
fn parse_arg_general(&self, require_name: bool) -> arg {
|
||||
pub fn parse_arg_general(&self, require_name: bool) -> arg {
|
||||
let mut is_mutbl = false;
|
||||
let pat = if require_name || self.is_named_argument() {
|
||||
self.parse_arg_mode();
|
||||
@ -844,12 +843,12 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a single function argument
|
||||
fn parse_arg(&self) -> arg_or_capture_item {
|
||||
pub fn parse_arg(&self) -> arg_or_capture_item {
|
||||
either::Left(self.parse_arg_general(true))
|
||||
}
|
||||
|
||||
// parse an argument in a lambda header e.g. |arg, arg|
|
||||
fn parse_fn_block_arg(&self) -> arg_or_capture_item {
|
||||
pub fn parse_fn_block_arg(&self) -> arg_or_capture_item {
|
||||
self.parse_arg_mode();
|
||||
let is_mutbl = self.eat_keyword(keywords::Mut);
|
||||
let pat = self.parse_pat();
|
||||
@ -870,7 +869,7 @@ pub impl Parser {
|
||||
})
|
||||
}
|
||||
|
||||
fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> {
|
||||
pub fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> {
|
||||
if self.eat(&token::BINOP(token::STAR)) {
|
||||
self.obsolete(*self.last_span, ObsoleteFixedLengthVectorType);
|
||||
Some(self.parse_expr())
|
||||
@ -885,7 +884,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// matches token_lit = LIT_INT | ...
|
||||
fn lit_from_token(&self, tok: &token::Token) -> lit_ {
|
||||
pub fn lit_from_token(&self, tok: &token::Token) -> lit_ {
|
||||
match *tok {
|
||||
token::LIT_INT(i, it) => lit_int(i, it),
|
||||
token::LIT_UINT(u, ut) => lit_uint(u, ut),
|
||||
@ -900,7 +899,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// matches lit = true | false | token_lit
|
||||
fn parse_lit(&self) -> lit {
|
||||
pub fn parse_lit(&self) -> lit {
|
||||
let lo = self.span.lo;
|
||||
let lit = if self.eat_keyword(keywords::True) {
|
||||
lit_bool(true)
|
||||
@ -916,7 +915,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// matches '-' lit | lit
|
||||
fn parse_literal_maybe_minus(&self) -> @expr {
|
||||
pub fn parse_literal_maybe_minus(&self) -> @expr {
|
||||
let minus_lo = self.span.lo;
|
||||
let minus_present = self.eat(&token::BINOP(token::MINUS));
|
||||
|
||||
@ -935,7 +934,7 @@ pub impl Parser {
|
||||
|
||||
// parse a path into a vector of idents, whether the path starts
|
||||
// with ::, and a span.
|
||||
fn parse_path(&self) -> (~[ast::ident],bool,span) {
|
||||
pub fn parse_path(&self) -> (~[ast::ident],bool,span) {
|
||||
let lo = self.span.lo;
|
||||
let is_global = self.eat(&token::MOD_SEP);
|
||||
let (ids,span{lo:_,hi,expn_info}) = self.parse_path_non_global();
|
||||
@ -943,7 +942,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a path beginning with an identifier into a vector of idents and a span
|
||||
fn parse_path_non_global(&self) -> (~[ast::ident],span) {
|
||||
pub fn parse_path_non_global(&self) -> (~[ast::ident],span) {
|
||||
let lo = self.span.lo;
|
||||
let mut ids = ~[];
|
||||
// must be at least one to begin:
|
||||
@ -966,8 +965,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a path that doesn't have type parameters attached
|
||||
fn parse_path_without_tps(&self)
|
||||
-> @ast::Path {
|
||||
pub fn parse_path_without_tps(&self) -> @ast::Path {
|
||||
maybe_whole!(self, nt_path);
|
||||
let (ids,is_global,sp) = self.parse_path();
|
||||
@ast::Path { span: sp,
|
||||
@ -980,7 +978,7 @@ pub impl Parser {
|
||||
// parse a path optionally with type parameters. If 'colons'
|
||||
// is true, then type parameters must be preceded by colons,
|
||||
// as in a::t::<t1,t2>
|
||||
fn parse_path_with_tps(&self, colons: bool) -> @ast::Path {
|
||||
pub fn parse_path_with_tps(&self, colons: bool) -> @ast::Path {
|
||||
debug!("parse_path_with_tps(colons=%b)", colons);
|
||||
|
||||
maybe_whole!(self, nt_path);
|
||||
@ -1042,7 +1040,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
/// parses 0 or 1 lifetime
|
||||
fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> {
|
||||
pub fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> {
|
||||
match *self.token {
|
||||
token::LIFETIME(*) => {
|
||||
Some(@self.parse_lifetime())
|
||||
@ -1064,7 +1062,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn token_is_lifetime(&self, tok: &token::Token) -> bool {
|
||||
pub fn token_is_lifetime(&self, tok: &token::Token) -> bool {
|
||||
match *tok {
|
||||
token::LIFETIME(_) => true,
|
||||
_ => false
|
||||
@ -1073,7 +1071,7 @@ pub impl Parser {
|
||||
|
||||
/// Parses a single lifetime
|
||||
// matches lifetime = ( LIFETIME ) | ( IDENT / )
|
||||
fn parse_lifetime(&self) -> ast::Lifetime {
|
||||
pub fn parse_lifetime(&self) -> ast::Lifetime {
|
||||
match *self.token {
|
||||
token::LIFETIME(i) => {
|
||||
let span = copy self.span;
|
||||
@ -1107,7 +1105,7 @@ pub impl Parser {
|
||||
// matches lifetimes = ( lifetime ) | ( lifetime , lifetimes )
|
||||
// actually, it matches the empty one too, but putting that in there
|
||||
// messes up the grammar....
|
||||
fn parse_lifetimes(&self) -> OptVec<ast::Lifetime> {
|
||||
pub fn parse_lifetimes(&self) -> OptVec<ast::Lifetime> {
|
||||
/*!
|
||||
*
|
||||
* Parses zero or more comma separated lifetimes.
|
||||
@ -1139,13 +1137,13 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn token_is_mutability(&self, tok: &token::Token) -> bool {
|
||||
pub fn token_is_mutability(&self, tok: &token::Token) -> bool {
|
||||
token::is_keyword(keywords::Mut, tok) ||
|
||||
token::is_keyword(keywords::Const, tok)
|
||||
}
|
||||
|
||||
// parse mutability declaration (mut/const/imm)
|
||||
fn parse_mutability(&self) -> mutability {
|
||||
pub fn parse_mutability(&self) -> mutability {
|
||||
if self.eat_keyword(keywords::Mut) {
|
||||
m_mutbl
|
||||
} else if self.eat_keyword(keywords::Const) {
|
||||
@ -1156,7 +1154,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse ident COLON expr
|
||||
fn parse_field(&self) -> field {
|
||||
pub fn parse_field(&self) -> field {
|
||||
let lo = self.span.lo;
|
||||
let i = self.parse_ident();
|
||||
self.expect(&token::COLON);
|
||||
@ -1167,7 +1165,7 @@ pub impl Parser {
|
||||
})
|
||||
}
|
||||
|
||||
fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr {
|
||||
pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr {
|
||||
@expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
@ -1176,7 +1174,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr {
|
||||
pub fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr {
|
||||
@expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
@ -1185,7 +1183,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_lit_u32(&self, i: u32) -> @expr {
|
||||
pub fn mk_lit_u32(&self, i: u32) -> @expr {
|
||||
let span = self.span;
|
||||
let lv_lit = @codemap::spanned {
|
||||
node: lit_uint(i as u64, ty_u32),
|
||||
@ -1203,7 +1201,7 @@ pub impl Parser {
|
||||
// at the bottom (top?) of the precedence hierarchy,
|
||||
// parse things like parenthesized exprs,
|
||||
// macros, return, etc.
|
||||
fn parse_bottom_expr(&self) -> @expr {
|
||||
pub fn parse_bottom_expr(&self) -> @expr {
|
||||
maybe_whole_expr!(self);
|
||||
|
||||
let lo = self.span.lo;
|
||||
@ -1414,23 +1412,20 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a block or unsafe block
|
||||
fn parse_block_expr(
|
||||
&self,
|
||||
lo: BytePos,
|
||||
blk_mode: blk_check_mode
|
||||
) -> @expr {
|
||||
pub fn parse_block_expr(&self, lo: BytePos, blk_mode: blk_check_mode)
|
||||
-> @expr {
|
||||
self.expect(&token::LBRACE);
|
||||
let blk = self.parse_block_tail(lo, blk_mode);
|
||||
return self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk));
|
||||
}
|
||||
|
||||
// parse a.b or a(13) or a[4] or just a
|
||||
fn parse_dot_or_call_expr(&self) -> @expr {
|
||||
pub fn parse_dot_or_call_expr(&self) -> @expr {
|
||||
let b = self.parse_bottom_expr();
|
||||
self.parse_dot_or_call_expr_with(b)
|
||||
}
|
||||
|
||||
fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr {
|
||||
pub fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr {
|
||||
let mut e = e0;
|
||||
let lo = e.span.lo;
|
||||
let mut hi;
|
||||
@ -1504,7 +1499,7 @@ pub impl Parser {
|
||||
|
||||
// parse an optional separator followed by a kleene-style
|
||||
// repetition token (+ or *).
|
||||
fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) {
|
||||
pub fn parse_sep_and_zerok(&self) -> (Option<token::Token>, bool) {
|
||||
if *self.token == token::BINOP(token::STAR)
|
||||
|| *self.token == token::BINOP(token::PLUS) {
|
||||
let zerok = *self.token == token::BINOP(token::STAR);
|
||||
@ -1525,7 +1520,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a single token tree from the input.
|
||||
fn parse_token_tree(&self) -> token_tree {
|
||||
pub fn parse_token_tree(&self) -> token_tree {
|
||||
maybe_whole!(deref self, nt_tt);
|
||||
|
||||
// this is the fall-through for the 'match' below.
|
||||
@ -1612,7 +1607,7 @@ pub impl Parser {
|
||||
|
||||
// parse a stream of tokens into a list of token_trees,
|
||||
// up to EOF.
|
||||
fn parse_all_token_trees(&self) -> ~[token_tree] {
|
||||
pub fn parse_all_token_trees(&self) -> ~[token_tree] {
|
||||
let mut tts = ~[];
|
||||
while *self.token != token::EOF {
|
||||
tts.push(self.parse_token_tree());
|
||||
@ -1620,7 +1615,7 @@ pub impl Parser {
|
||||
tts
|
||||
}
|
||||
|
||||
fn parse_matchers(&self) -> ~[matcher] {
|
||||
pub fn parse_matchers(&self) -> ~[matcher] {
|
||||
// unification of matchers and token_trees would vastly improve
|
||||
// the interpolation of matchers
|
||||
maybe_whole!(self, nt_matchers);
|
||||
@ -1642,12 +1637,11 @@ pub impl Parser {
|
||||
// This goofy function is necessary to correctly match parens in matchers.
|
||||
// Otherwise, `$( ( )` would be a valid matcher, and `$( () )` would be
|
||||
// invalid. It's similar to common::parse_seq.
|
||||
fn parse_matcher_subseq(
|
||||
&self,
|
||||
name_idx: @mut uint,
|
||||
bra: token::Token,
|
||||
ket: token::Token
|
||||
) -> ~[matcher] {
|
||||
pub fn parse_matcher_subseq(&self,
|
||||
name_idx: @mut uint,
|
||||
bra: token::Token,
|
||||
ket: token::Token)
|
||||
-> ~[matcher] {
|
||||
let mut ret_val = ~[];
|
||||
let mut lparens = 0u;
|
||||
|
||||
@ -1664,7 +1658,7 @@ pub impl Parser {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
fn parse_matcher(&self, name_idx: @mut uint) -> matcher {
|
||||
pub fn parse_matcher(&self, name_idx: @mut uint) -> matcher {
|
||||
let lo = self.span.lo;
|
||||
|
||||
let m = if *self.token == token::DOLLAR {
|
||||
@ -1699,7 +1693,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a prefix-operator expr
|
||||
fn parse_prefix_expr(&self) -> @expr {
|
||||
pub fn parse_prefix_expr(&self) -> @expr {
|
||||
let lo = self.span.lo;
|
||||
let hi;
|
||||
|
||||
@ -1791,13 +1785,12 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse an expression of binops
|
||||
fn parse_binops(&self) -> @expr {
|
||||
pub fn parse_binops(&self) -> @expr {
|
||||
self.parse_more_binops(self.parse_prefix_expr(), 0)
|
||||
}
|
||||
|
||||
// parse an expression of binops of at least min_prec precedence
|
||||
fn parse_more_binops(&self, lhs: @expr, min_prec: uint) ->
|
||||
@expr {
|
||||
pub fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> @expr {
|
||||
if self.expr_is_complete(lhs) { return lhs; }
|
||||
let peeked = copy *self.token;
|
||||
if peeked == token::BINOP(token::OR) &&
|
||||
@ -1841,7 +1834,7 @@ pub impl Parser {
|
||||
// parse an assignment expression....
|
||||
// actually, this seems to be the main entry point for
|
||||
// parsing an arbitrary expression.
|
||||
fn parse_assign_expr(&self) -> @expr {
|
||||
pub fn parse_assign_expr(&self) -> @expr {
|
||||
let lo = self.span.lo;
|
||||
let lhs = self.parse_binops();
|
||||
match *self.token {
|
||||
@ -1892,7 +1885,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse an 'if' expression ('if' token already eaten)
|
||||
fn parse_if_expr(&self) -> @expr {
|
||||
pub fn parse_if_expr(&self) -> @expr {
|
||||
let lo = self.last_span.lo;
|
||||
let cond = self.parse_expr();
|
||||
let thn = self.parse_block();
|
||||
@ -1907,7 +1900,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// `|args| { ... }` or `{ ...}` like in `do` expressions
|
||||
fn parse_lambda_block_expr(&self) -> @expr {
|
||||
pub fn parse_lambda_block_expr(&self) -> @expr {
|
||||
self.parse_lambda_expr_(
|
||||
|| {
|
||||
match *self.token {
|
||||
@ -1935,7 +1928,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// `|args| expr`
|
||||
fn parse_lambda_expr(&self) -> @expr {
|
||||
pub fn parse_lambda_expr(&self) -> @expr {
|
||||
self.parse_lambda_expr_(|| self.parse_fn_block_decl(),
|
||||
|| self.parse_expr())
|
||||
}
|
||||
@ -1943,11 +1936,10 @@ pub impl Parser {
|
||||
// parse something of the form |args| expr
|
||||
// this is used both in parsing a lambda expr
|
||||
// and in parsing a block expr as e.g. in for...
|
||||
fn parse_lambda_expr_(
|
||||
&self,
|
||||
parse_decl: &fn() -> fn_decl,
|
||||
parse_body: &fn() -> @expr
|
||||
) -> @expr {
|
||||
pub fn parse_lambda_expr_(&self,
|
||||
parse_decl: &fn() -> fn_decl,
|
||||
parse_body: &fn() -> @expr)
|
||||
-> @expr {
|
||||
let lo = self.last_span.lo;
|
||||
let decl = parse_decl();
|
||||
let body = parse_body();
|
||||
@ -1964,7 +1956,7 @@ pub impl Parser {
|
||||
expr_fn_block(decl, fakeblock));
|
||||
}
|
||||
|
||||
fn parse_else_expr(&self) -> @expr {
|
||||
pub fn parse_else_expr(&self) -> @expr {
|
||||
if self.eat_keyword(keywords::If) {
|
||||
return self.parse_if_expr();
|
||||
} else {
|
||||
@ -1976,9 +1968,11 @@ pub impl Parser {
|
||||
// parse a 'for' or 'do'.
|
||||
// the 'for' and 'do' expressions parse as calls, but look like
|
||||
// function calls followed by a closure expression.
|
||||
fn parse_sugary_call_expr(&self, keyword: ~str,
|
||||
sugar: CallSugar,
|
||||
ctor: &fn(v: @expr) -> expr_) -> @expr {
|
||||
pub fn parse_sugary_call_expr(&self,
|
||||
keyword: ~str,
|
||||
sugar: CallSugar,
|
||||
ctor: &fn(v: @expr) -> expr_)
|
||||
-> @expr {
|
||||
let lo = self.last_span;
|
||||
// Parse the callee `foo` in
|
||||
// for foo || {
|
||||
@ -2035,7 +2029,7 @@ pub impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_while_expr(&self) -> @expr {
|
||||
pub fn parse_while_expr(&self) -> @expr {
|
||||
let lo = self.last_span.lo;
|
||||
let cond = self.parse_expr();
|
||||
let body = self.parse_block();
|
||||
@ -2043,7 +2037,7 @@ pub impl Parser {
|
||||
return self.mk_expr(lo, hi, expr_while(cond, body));
|
||||
}
|
||||
|
||||
fn parse_loop_expr(&self, opt_ident: Option<ast::ident>) -> @expr {
|
||||
pub fn parse_loop_expr(&self, opt_ident: Option<ast::ident>) -> @expr {
|
||||
// loop headers look like 'loop {' or 'loop unsafe {'
|
||||
let is_loop_header =
|
||||
*self.token == token::LBRACE
|
||||
@ -2126,7 +2120,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse an expression
|
||||
fn parse_expr(&self) -> @expr {
|
||||
pub fn parse_expr(&self) -> @expr {
|
||||
return self.parse_expr_res(UNRESTRICTED);
|
||||
}
|
||||
|
||||
@ -2257,7 +2251,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a pattern.
|
||||
fn parse_pat(&self) -> @pat {
|
||||
pub fn parse_pat(&self) -> @pat {
|
||||
maybe_whole!(self, nt_pat);
|
||||
|
||||
let lo = self.span.lo;
|
||||
@ -2580,7 +2574,7 @@ pub impl Parser {
|
||||
|
||||
// parse a statement. may include decl.
|
||||
// precondition: any attributes are parsed already
|
||||
fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt {
|
||||
pub fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt {
|
||||
maybe_whole!(self, nt_stmt);
|
||||
|
||||
fn check_expected_item(p: &Parser, current_attrs: &[attribute]) {
|
||||
@ -2674,7 +2668,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a block. No inner attrs are allowed.
|
||||
fn parse_block(&self) -> blk {
|
||||
pub fn parse_block(&self) -> blk {
|
||||
maybe_whole!(self, nt_block);
|
||||
|
||||
let lo = self.span.lo;
|
||||
@ -2924,7 +2918,7 @@ pub impl Parser {
|
||||
// matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > )
|
||||
// | ( < lifetimes , typaramseq ( , )? > )
|
||||
// where typaramseq = ( typaram ) | ( typaram , typaramseq )
|
||||
fn parse_generics(&self) -> ast::Generics {
|
||||
pub fn parse_generics(&self) -> ast::Generics {
|
||||
if self.eat(&token::LT) {
|
||||
let lifetimes = self.parse_lifetimes();
|
||||
let ty_params = self.parse_seq_to_gt(
|
||||
@ -2958,9 +2952,7 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse the argument list and result type of a function declaration
|
||||
fn parse_fn_decl(&self)
|
||||
-> fn_decl
|
||||
{
|
||||
pub fn parse_fn_decl(&self) -> fn_decl {
|
||||
let args_or_capture_items: ~[arg_or_capture_item] =
|
||||
self.parse_unspanned_seq(
|
||||
&token::LPAREN,
|
||||
@ -3398,9 +3390,10 @@ pub impl Parser {
|
||||
}
|
||||
|
||||
// parse a structure field declaration
|
||||
fn parse_single_struct_field(&self,
|
||||
vis: visibility,
|
||||
attrs: ~[attribute]) -> @struct_field {
|
||||
pub fn parse_single_struct_field(&self,
|
||||
vis: visibility,
|
||||
attrs: ~[attribute])
|
||||
-> @struct_field {
|
||||
if self.eat_obsolete_ident("let") {
|
||||
self.obsolete(*self.last_span, ObsoleteLet);
|
||||
}
|
||||
@ -4214,7 +4207,7 @@ pub impl Parser {
|
||||
return iovi_none;
|
||||
}
|
||||
|
||||
fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> {
|
||||
pub fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> {
|
||||
match self.parse_item_or_view_item(attrs, true) {
|
||||
iovi_none =>
|
||||
None,
|
||||
@ -4493,7 +4486,7 @@ pub impl Parser {
|
||||
|
||||
// Parses a source module as a crate. This is the main
|
||||
// entry point for the parser.
|
||||
fn parse_crate_mod(&self) -> @crate {
|
||||
pub fn parse_crate_mod(&self) -> @crate {
|
||||
let lo = self.span.lo;
|
||||
// parse the crate's inner attrs, maybe (oops) one
|
||||
// of the attrs of an item:
|
||||
@ -4507,7 +4500,7 @@ pub impl Parser {
|
||||
config: copy self.cfg })
|
||||
}
|
||||
|
||||
fn parse_str(&self) -> @~str {
|
||||
pub fn parse_str(&self) -> @~str {
|
||||
match *self.token {
|
||||
token::LIT_STR(s) => {
|
||||
self.bump();
|
||||
|
@ -393,21 +393,22 @@ pub struct ident_interner {
|
||||
priv interner: StrInterner,
|
||||
}
|
||||
|
||||
pub impl ident_interner {
|
||||
fn intern(&self, val: &str) -> ast::ident {
|
||||
impl ident_interner {
|
||||
pub fn intern(&self, val: &str) -> ast::ident {
|
||||
ast::ident { repr: self.interner.intern(val), ctxt: 0 }
|
||||
}
|
||||
fn gensym(&self, val: &str) -> ast::ident {
|
||||
pub fn gensym(&self, val: &str) -> ast::ident {
|
||||
ast::ident { repr: self.interner.gensym(val), ctxt: 0 }
|
||||
}
|
||||
fn get(&self, idx: ast::ident) -> @~str {
|
||||
pub fn get(&self, idx: ast::ident) -> @~str {
|
||||
self.interner.get(idx.repr)
|
||||
}
|
||||
fn len(&self) -> uint {
|
||||
pub fn len(&self) -> uint {
|
||||
self.interner.len()
|
||||
}
|
||||
fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q)
|
||||
-> Option<ast::ident> {
|
||||
pub fn find_equiv<Q:Hash +
|
||||
IterBytes +
|
||||
Equiv<@~str>>(&self, val: &Q) -> Option<ast::ident> {
|
||||
match self.interner.find_equiv(val) {
|
||||
Some(v) => Some(ast::ident { repr: v, ctxt: 0 }),
|
||||
None => None,
|
||||
@ -586,8 +587,8 @@ pub mod keywords {
|
||||
Be,
|
||||
}
|
||||
|
||||
pub impl Keyword {
|
||||
fn to_ident(&self) -> ident {
|
||||
impl Keyword {
|
||||
pub fn to_ident(&self) -> ident {
|
||||
match *self {
|
||||
As => ident { repr: 35, ctxt: 0 },
|
||||
Break => ident { repr: 36, ctxt: 0 },
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user