Use rustc traits instead of our own
This commit is contained in:
parent
4d38f8dffb
commit
9c07f424da
3 changed files with 19 additions and 21 deletions
|
|
@ -4,7 +4,7 @@ use syntax::ast::{FloatTy, IntTy, UintTy};
|
|||
use error::{EvalResult, EvalError};
|
||||
use eval_context::EvalContext;
|
||||
use value::PrimVal;
|
||||
use memory::{MemoryPointer, HasDataLayout};
|
||||
use memory::{MemoryPointer, PointerArithmetic};
|
||||
|
||||
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||
pub(super) fn cast_primval(
|
||||
|
|
|
|||
|
|
@ -68,30 +68,30 @@ pub struct MemoryPointer {
|
|||
pub offset: u64,
|
||||
}
|
||||
|
||||
impl MemoryPointer {
|
||||
impl<'tcx> MemoryPointer {
|
||||
pub fn new(alloc_id: AllocId, offset: u64) -> Self {
|
||||
MemoryPointer { alloc_id, offset }
|
||||
}
|
||||
|
||||
pub(crate) fn wrapping_signed_offset<'a, L: HasDataLayout<'a>>(self, i: i64, l: L) -> Self {
|
||||
pub(crate) fn wrapping_signed_offset<L: PointerArithmetic>(self, i: i64, l: L) -> Self {
|
||||
MemoryPointer::new(self.alloc_id, l.wrapping_signed_offset(self.offset, i))
|
||||
}
|
||||
|
||||
pub(crate) fn overflowing_signed_offset<'a, L: HasDataLayout<'a>>(self, i: i128, l: L) -> (Self, bool) {
|
||||
pub(crate) fn overflowing_signed_offset<L: PointerArithmetic>(self, i: i128, l: L) -> (Self, bool) {
|
||||
let (res, over) = l.overflowing_signed_offset(self.offset, i);
|
||||
(MemoryPointer::new(self.alloc_id, res), over)
|
||||
}
|
||||
|
||||
pub(crate) fn signed_offset<'a, 'tcx, L: HasDataLayout<'a>>(self, i: i64, l: L) -> EvalResult<'tcx, Self> {
|
||||
pub(crate) fn signed_offset<L: PointerArithmetic>(self, i: i64, l: L) -> EvalResult<'tcx, Self> {
|
||||
Ok(MemoryPointer::new(self.alloc_id, l.signed_offset(self.offset, i)?))
|
||||
}
|
||||
|
||||
pub(crate) fn overflowing_offset<'a, L: HasDataLayout<'a>>(self, i: u64, l: L) -> (Self, bool) {
|
||||
pub(crate) fn overflowing_offset<L: PointerArithmetic>(self, i: u64, l: L) -> (Self, bool) {
|
||||
let (res, over) = l.overflowing_offset(self.offset, i);
|
||||
(MemoryPointer::new(self.alloc_id, res), over)
|
||||
}
|
||||
|
||||
pub(crate) fn offset<'a, 'tcx, L: HasDataLayout<'a>>(self, i: u64, l: L) -> EvalResult<'tcx, Self> {
|
||||
pub(crate) fn offset<L: PointerArithmetic>(self, i: u64, l: L) -> EvalResult<'tcx, Self> {
|
||||
Ok(MemoryPointer::new(self.alloc_id, l.offset(self.offset, i)?))
|
||||
}
|
||||
}
|
||||
|
|
@ -1183,9 +1183,7 @@ impl<'a, 'tcx> HasMemory<'a, 'tcx> for EvalContext<'a, 'tcx> {
|
|||
// Pointer arithmetic
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub(crate) trait HasDataLayout<'a> : Copy {
|
||||
fn data_layout(self) -> &'a TargetDataLayout;
|
||||
|
||||
pub trait PointerArithmetic : layout::HasDataLayout {
|
||||
// These are not supposed to be overriden.
|
||||
|
||||
//// Trunace the given value to the pointer size; also return whether there was an overflow
|
||||
|
|
@ -1236,17 +1234,17 @@ pub(crate) trait HasDataLayout<'a> : Copy {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> HasDataLayout<'a> for &'a TargetDataLayout {
|
||||
impl<T: layout::HasDataLayout> PointerArithmetic for T {}
|
||||
|
||||
impl<'a, 'tcx> layout::HasDataLayout for &'a Memory<'a, 'tcx> {
|
||||
#[inline]
|
||||
fn data_layout(self) -> &'a TargetDataLayout {
|
||||
self
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
self.layout
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx, T> HasDataLayout<'a> for &'b T
|
||||
where T: HasMemory<'a, 'tcx> {
|
||||
impl<'a, 'tcx> layout::HasDataLayout for &'a EvalContext<'a, 'tcx> {
|
||||
#[inline]
|
||||
fn data_layout(self) -> &'a TargetDataLayout {
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
self.memory().layout
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#![allow(float_cmp)]
|
||||
|
||||
use error::{EvalError, EvalResult};
|
||||
use memory::{Memory, MemoryPointer, HasMemory, HasDataLayout};
|
||||
use memory::{Memory, MemoryPointer, HasMemory, PointerArithmetic};
|
||||
|
||||
pub(super) fn bytes_to_f32(bytes: u128) -> f32 {
|
||||
f32::from_bits(bytes as u32)
|
||||
|
|
@ -59,7 +59,7 @@ impl<'tcx> Pointer {
|
|||
self.primval
|
||||
}
|
||||
|
||||
pub(crate) fn signed_offset<'a, L: HasDataLayout<'a>>(self, i: i64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
pub(crate) fn signed_offset<L: PointerArithmetic>(self, i: i64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
match self.primval {
|
||||
PrimVal::Bytes(b) => {
|
||||
assert_eq!(b as u64 as u128, b);
|
||||
|
|
@ -70,7 +70,7 @@ impl<'tcx> Pointer {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn offset<'a, L: HasDataLayout<'a>>(self, i: u64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
pub(crate) fn offset<L: PointerArithmetic>(self, i: u64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
match self.primval {
|
||||
PrimVal::Bytes(b) => {
|
||||
assert_eq!(b as u64 as u128, b);
|
||||
|
|
@ -81,7 +81,7 @@ impl<'tcx> Pointer {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn wrapping_signed_offset<'a, L: HasDataLayout<'a>>(self, i: i64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
pub(crate) fn wrapping_signed_offset<L: PointerArithmetic>(self, i: i64, layout: L) -> EvalResult<'tcx, Self> {
|
||||
match self.primval {
|
||||
PrimVal::Bytes(b) => {
|
||||
assert_eq!(b as u64 as u128, b);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue