Skip to content

Commit

Permalink
auto merge of #10719 : Kimundi/rust/switch_to_multi_item_macros, r=al…
Browse files Browse the repository at this point in the history
…excrichton

- Removed module reexport workaround for the integer module macros
- Removed legacy reexports of `cmp::{min, max}` in the integer module macros
- Combined a few macros in `vec` into one
- Documented a few issues
  • Loading branch information
bors committed Nov 29, 2013
2 parents dd1184e + 4840064 commit 80991bb
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 256 deletions.
25 changes: 12 additions & 13 deletions src/librustc/middle/trans/foreign.rs
Expand Up @@ -10,32 +10,31 @@


use back::{link};
use std::libc::c_uint;
use lib::llvm::{ValueRef, CallConv, StructRetAttribute};
use lib::llvm::llvm;
use lib::llvm::{ValueRef, CallConv, StructRetAttribute};
use lib;
use middle::trans::machine;
use middle::trans::base;
use middle::trans::base::push_ctxt;
use middle::trans::cabi;
use middle::trans::base;
use middle::trans::build::*;
use middle::trans::builder::noname;
use middle::trans::cabi;
use middle::trans::common::*;
use middle::trans::machine;
use middle::trans::type_::Type;
use middle::trans::type_of::*;
use middle::trans::type_of;
use middle::ty;
use middle::ty::FnSig;

use std::uint;
use middle::ty;
use std::cmp;
use std::libc::c_uint;
use std::vec;
use syntax::abi::{Cdecl, Aapcs, C, AbiSet, Win64};
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System};
use syntax::codemap::Span;
use syntax::parse::token::special_idents;
use syntax::{ast};
use syntax::{attr, ast_map};
use syntax::parse::token::special_idents;
use syntax::abi::{RustIntrinsic, Rust, Stdcall, Fastcall, System,
Cdecl, Aapcs, C, AbiSet, Win64};
use util::ppaux::{Repr, UserString};
use middle::trans::type_::Type;

///////////////////////////////////////////////////////////////////////////
// Type definitions
Expand Down Expand Up @@ -332,7 +331,7 @@ pub fn trans_native_call(bcx: @mut Block,
let llrust_size = machine::llsize_of_store(ccx, llrust_ret_ty);
let llforeign_align = machine::llalign_of_min(ccx, llforeign_ret_ty);
let llrust_align = machine::llalign_of_min(ccx, llrust_ret_ty);
let llalign = uint::min(llforeign_align, llrust_align);
let llalign = cmp::min(llforeign_align, llrust_align);
debug!("llrust_size={:?}", llrust_size);
base::call_memcpy(bcx, llretptr_i8, llscratch_i8,
C_uint(ccx, llrust_size), llalign as u32);
Expand Down
41 changes: 18 additions & 23 deletions src/libstd/fmt/mod.rs
Expand Up @@ -901,7 +901,7 @@ impl<'self> Formatter<'self> {
// case where the maximum length will matter.
let char_len = s.char_len();
if char_len >= max {
let nchars = ::uint::min(max, char_len);
let nchars = ::cmp::min(max, char_len);
self.buf.write(s.slice_chars(0, nchars).as_bytes());
return
}
Expand Down Expand Up @@ -1036,31 +1036,26 @@ pub fn upperhex(buf: &[u8], f: &mut Formatter) {
f.pad_integral(local.slice_to(buf.len()), "0x", true);
}

// FIXME(#4375) shouldn't need an inner module
macro_rules! integer(($signed:ident, $unsigned:ident) => {
mod $signed {
use super::*;

// Signed is special because it actuall emits the negative sign,
// nothing else should do that, however.
impl Signed for $signed {
fn fmt(c: &$signed, f: &mut Formatter) {
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
f.pad_integral(buf, "", *c >= 0);
})
}
// Signed is special because it actuall emits the negative sign,
// nothing else should do that, however.
impl Signed for $signed {
fn fmt(c: &$signed, f: &mut Formatter) {
::$unsigned::to_str_bytes(c.abs() as $unsigned, 10, |buf| {
f.pad_integral(buf, "", *c >= 0);
})
}
int_base!($signed, $unsigned, 2, Binary, "0b")
int_base!($signed, $unsigned, 8, Octal, "0o")
int_base!($signed, $unsigned, 16, LowerHex, "0x")
upper_hex!($signed, $unsigned)

int_base!($unsigned, $unsigned, 2, Binary, "0b")
int_base!($unsigned, $unsigned, 8, Octal, "0o")
int_base!($unsigned, $unsigned, 10, Unsigned, "")
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
upper_hex!($unsigned, $unsigned)
}
int_base!($signed, $unsigned, 2, Binary, "0b")
int_base!($signed, $unsigned, 8, Octal, "0o")
int_base!($signed, $unsigned, 16, LowerHex, "0x")
upper_hex!($signed, $unsigned)

int_base!($unsigned, $unsigned, 2, Binary, "0b")
int_base!($unsigned, $unsigned, 8, Octal, "0o")
int_base!($unsigned, $unsigned, 10, Unsigned, "")
int_base!($unsigned, $unsigned, 16, LowerHex, "0x")
upper_hex!($unsigned, $unsigned)
})

integer!(int, uint)
Expand Down
33 changes: 13 additions & 20 deletions src/libstd/num/f32.rs
Expand Up @@ -11,18 +11,19 @@
//! Operations and constants for `f32`
#[allow(missing_doc)];

use prelude::*;

use cmath::c_float_utils;
use default::Default;
use libc::c_int;
use num::{Zero, One, strconv};
use libc::{c_float, c_int};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num::{Zero, One, strconv};
use num;
use prelude::*;
use to_str;
use unstable::intrinsics;

pub use cmath::c_float_targ_consts::*;

use self::delegated::*;

macro_rules! delegate(
(
$(
Expand All @@ -33,22 +34,14 @@ macro_rules! delegate(
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated {
use cmath::c_float_utils;
use libc::{c_float, c_int};
use unstable::intrinsics;

$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
)*
}
}
)*
)
)

Expand Down
33 changes: 13 additions & 20 deletions src/libstd/num/f64.rs
Expand Up @@ -12,19 +12,20 @@

#[allow(missing_doc)];

use prelude::*;

use cmath::c_double_utils;
use default::Default;
use libc::c_int;
use num::{Zero, One, strconv};
use libc::{c_double, c_int};
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num::{Zero, One, strconv};
use num;
use prelude::*;
use to_str;
use unstable::intrinsics;

pub use cmath::c_double_targ_consts::*;
pub use cmp::{min, max};

use self::delegated::*;

macro_rules! delegate(
(
$(
Expand All @@ -35,22 +36,14 @@ macro_rules! delegate(
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated {
use cmath::c_double_utils;
use libc::{c_double, c_int};
use unstable::intrinsics;

$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
}
)*
}
}
)*
)
)

Expand Down
10 changes: 8 additions & 2 deletions src/libstd/num/i16.rs
Expand Up @@ -10,12 +10,18 @@

//! Operations and constants for `i16`

#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

int_module!(i16, 16)

impl BitCount for i16 {
Expand Down
10 changes: 8 additions & 2 deletions src/libstd/num/i32.rs
Expand Up @@ -10,12 +10,18 @@

//! Operations and constants for `i32`

#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

int_module!(i32, 32)

impl BitCount for i32 {
Expand Down
12 changes: 9 additions & 3 deletions src/libstd/num/i64.rs
Expand Up @@ -10,14 +10,20 @@

//! Operations and constants for `i64`

use num::{BitCount, CheckedAdd, CheckedSub};
#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
#[cfg(target_word_size = "64")]
use num::CheckedMul;
use num::{BitCount, CheckedAdd, CheckedSub};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

int_module!(i64, 64)

impl BitCount for i64 {
Expand Down
10 changes: 8 additions & 2 deletions src/libstd/num/i8.rs
Expand Up @@ -10,12 +10,18 @@

//! Operations and constants for `i8`

#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

int_module!(i8, 8)

impl BitCount for i8 {
Expand Down
14 changes: 8 additions & 6 deletions src/libstd/num/int.rs
Expand Up @@ -12,16 +12,18 @@

#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
use num::{BitCount, CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

#[cfg(target_word_size = "32")] pub static bits: uint = 32;
#[cfg(target_word_size = "64")] pub static bits: uint = 64;

int_module!(int, super::bits)
#[cfg(target_word_size = "32")] int_module!(int, 32)
#[cfg(target_word_size = "64")] int_module!(int, 64)

#[cfg(target_word_size = "32")]
impl BitCount for int {
Expand Down
16 changes: 2 additions & 14 deletions src/libstd/num/int_macros.rs
Expand Up @@ -8,22 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// FIXME(#4375): this shouldn't have to be a nested module named 'generated'

#[macro_escape];
#[doc(hidden)];

macro_rules! int_module (($T:ty, $bits:expr) => (mod generated {

#[allow(non_uppercase_statics)];

use default::Default;
use num::{ToStrRadix, FromStrRadix};
use num::{CheckedDiv, Zero, One, strconv};
use prelude::*;
use str;

pub use cmp::{min, max};
macro_rules! int_module (($T:ty, $bits:expr) => (

pub static bits : uint = $bits;
pub static bytes : uint = ($bits / 8);
Expand Down Expand Up @@ -781,4 +769,4 @@ mod tests {
}
}

}))
))
11 changes: 9 additions & 2 deletions src/libstd/num/u16.rs
Expand Up @@ -10,12 +10,19 @@

//! Operations and constants for `u16`

#[allow(non_uppercase_statics)];

use prelude::*;

use default::Default;
use num::BitCount;
use num::{CheckedAdd, CheckedSub, CheckedMul};
use num::{CheckedDiv, Zero, One, strconv};
use num::{ToStrRadix, FromStrRadix};
use option::{Option, Some, None};
use str;
use unstable::intrinsics;

pub use self::generated::*;

uint_module!(u16, i16, 16)

impl CheckedAdd for u16 {
Expand Down

0 comments on commit 80991bb

Please sign in to comment.