Skip to content

Commit

Permalink
Merge pull request #34 from llogiq/overflower-0.9
Browse files Browse the repository at this point in the history
Overflower 0.9
  • Loading branch information
llogiq committed Oct 24, 2019
2 parents 22cf8ea + 28a490b commit 4a4de86
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 142 deletions.
26 changes: 5 additions & 21 deletions Cargo.toml
@@ -1,21 +1,5 @@
[package]
name = "overflower"
version = "0.4.6"
authors = ["Andre Bogus <bogusandre@gmail.com>"]
license = "Apache-2.0"
repository = "https://github.com/llogiq/overflower"
description = "A compiler plugin to easily select overflow behavior for all integer operations of an item"
readme = "README.md"
keywords = ["arithmetic", "overflow", "plugin"]
categories = ["development-tools"]

[badges]
travis-ci = { repository = "llogiq/overflower" }

[lib]
proc_macro = true

[dependencies]
overflower_support = { version = "0.1.5", path = "support" }
syn = { version = "1.0.1", features = ["extra-traits", "full", "fold", "parsing", "proc-macro"] }
quote = "0.6.9"
[workspace]
members = [
"overflower",
"overflower-plugin",
]
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -17,8 +17,7 @@ To use it, you need the following in your Cargo.toml:

```toml
[dependencies]
overflower = "0.4.6"
overflower_support = "0.1.5"
overflower = "0.9"
```

You may also make it an optional dependency (`overflower = { version = "0.4.6",
Expand Down
21 changes: 21 additions & 0 deletions overflower-plugin/Cargo.toml
@@ -0,0 +1,21 @@
[package]
authors = ["Andre Bogus <bogusandre@gmail.com>"]
categories = ["development-tools"]
description = "A compiler plugin to easily select overflow behavior for all integer operations of an item"
edition = "2018"
license = "Apache-2.0"
name = "overflower-plugin"
readme = "README.md"
repository = "https://github.com/llogiq/overflower"
keywords = ["arithmetic", "overflow", "plugin"]
version = "0.9.0"

[badges]
travis-ci = { repository = "llogiq/overflower" }

[lib]
proc_macro = true

[dependencies]
syn = { version = "1.0.5", features = ["extra-traits", "full", "fold", "parsing", "proc-macro"] }
quote = "1.0.0"
11 changes: 6 additions & 5 deletions src/lib.rs → overflower-plugin/src/lib.rs
Expand Up @@ -56,7 +56,7 @@ impl Overflower {
Overflower::Saturate => "Saturate",
Overflower::Default => "Default"
};
let crate_name = syn::parse_str::<Ident>("overflower_support").unwrap();
let crate_name = syn::parse_str::<Ident>("overflower").unwrap();
let trait_name = syn::parse_str::<Ident>(&(method.split("_").flat_map(|s| {
let mut me = s.chars();
me.next().unwrap().to_uppercase().chain(me)
Expand Down Expand Up @@ -98,6 +98,7 @@ impl Overflower {
let mut args = vec![Expr::Reference(ExprReference {
attrs: vec![],
and_token: Default::default(),
raw: Default::default(),
mutability: Some(Default::default()),
expr: Box::new(self.fold_expr(*left))
}), self.fold_expr(*right)];
Expand Down Expand Up @@ -182,9 +183,9 @@ impl Overflower {
};
if is_abs {
let func = match *self {
Overflower::Wrap => "::overflower_support::AbsWrap::abs_wrap",
Overflower::Panic => "::overflower_support::AbsPanic::abs_panic",
Overflower::Saturate => "::overflower_support::AbsSaturate::abs_saturate",
Overflower::Wrap => "::overflower::AbsWrap::abs_wrap",
Overflower::Panic => "::overflower::AbsPanic::abs_panic",
Overflower::Saturate => "::overflower::AbsSaturate::abs_saturate",
Overflower::Default => return Expr::Call(c),
};
c.func = Box::new(syn::parse_str::<Expr>(func).unwrap());
Expand Down Expand Up @@ -250,7 +251,6 @@ impl Fold for Overflower {
}
match e {
Expr::Box(b) => foldexpr!(self, Expr::Box, b, fold::fold_expr_box),
Expr::InPlace(i) => foldexpr!(self, Expr::InPlace, i, fold::fold_expr_in_place),
Expr::Array(a) => foldexpr!(self, Expr::Array, a, fold::fold_expr_array),
Expr::Call(c) => self.make_call(c),
Expr::MethodCall(c) => foldexpr!(self, Expr::MethodCall, c, fold::fold_expr_method_call),
Expand Down Expand Up @@ -290,6 +290,7 @@ impl Fold for Overflower {
}
}

/// Mark a module or function to control overflow behavior within
#[proc_macro_attribute]
pub fn overflow(attrs: TokenStream, code: TokenStream) -> TokenStream {
let input = parse_macro_input!(code as Item);
Expand Down
27 changes: 27 additions & 0 deletions overflower/Cargo.toml
@@ -0,0 +1,27 @@
[package]
authors = ["Andre Bogus <bogusandre@gmail.com>"]
categories = ["development-tools"]
description = "A bunch of specialized traits + impls to allow automated overflow handling without type inference."
edition = "2018"
keywords = ["arithmetic", "overflow", "nightly"]
license = "Apache-2.0"
name = "overflower"
repository = "https://github.com/llogiq/overflower"
version = "0.9.0"

[features]
# by default, we include the `#[overflow(..)]` attribute macro
default = ["proc_macro"]
# specialization is only available on nightly
specialization = []
# `.abs()` on `Wrapping<i*>` is also only available on nightly, but might be
# stabilized sooner than specialization.
wrapping_int_impl = []
# You can exclude this if you only want to implement the traits for your types.
proc_macro = ["overflower-plugin"]

[dependencies]
overflower-plugin = { path = "../overflower-plugin", optional = true }

[dev-dependencies]
quickcheck = "0.9"

0 comments on commit 4a4de86

Please sign in to comment.