Skip to content

Commit

Permalink
Merge pull request #1280 from viperproject/improvements
Browse files Browse the repository at this point in the history
Add macros for returning spanned encoding errors
  • Loading branch information
fpoli authored Jan 18, 2023
2 parents f6850c5 + 7b77ac7 commit 01353f4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
30 changes: 0 additions & 30 deletions prusti-viper/src/encoder/errors/encoding_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,3 @@ impl From<SpannedEncodingError> for EncodingError {
EncodingError::Spanned(other)
}
}

#[macro_export]
macro_rules! error_internal {
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::internal($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::internal(format!($($tokens)+)))
};
}

#[macro_export]
macro_rules! error_incorrect {
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::incorrect($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::incorrect(format!($($tokens)+)))
};
}

#[macro_export]
macro_rules! error_unsupported {
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::unsupported($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::unsupported(format!($($tokens)+)))
};
}
53 changes: 53 additions & 0 deletions prusti-viper/src/encoder/errors/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// © 2022, ETH Zurich
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#[macro_export]
macro_rules! error_internal {
($span:expr => $message:expr) => {
return Err($crate::encoder::errors::SpannedEncodingError::internal($message), $span)
};
($span:expr => $($tokens:tt)+) => {
return Err($crate::encoder::errors::SpannedEncodingError::internal(format!($($tokens)+), $span))
};
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::internal($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::internal(format!($($tokens)+)))
};
}

#[macro_export]
macro_rules! error_incorrect {
($span:expr => $message:expr) => {
return Err($crate::encoder::errors::SpannedEncodingError::incorrect($message), $span)
};
($span:expr => $($tokens:tt)+) => {
return Err($crate::encoder::errors::SpannedEncodingError::incorrect(format!($($tokens)+), $span))
};
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::incorrect($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::incorrect(format!($($tokens)+)))
};
}

#[macro_export]
macro_rules! error_unsupported {
($span:expr => $message:expr) => {
return Err($crate::encoder::errors::SpannedEncodingError::unsupported($message), $span)
};
($span:expr => $($tokens:tt)+) => {
return Err($crate::encoder::errors::SpannedEncodingError::unsupported(format!($($tokens)+), $span))
};
($message:expr) => {
return Err($crate::encoder::errors::EncodingError::unsupported($message))
};
($($tokens:tt)+) => {
return Err($crate::encoder::errors::EncodingError::unsupported(format!($($tokens)+)))
};
}
2 changes: 2 additions & 0 deletions prusti-viper/src/encoder/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use self::encoding_error::*;
pub use self::encoding_error_kind::*;
pub use self::with_span::*;
pub use self::position_manager::*;
pub use self::macros::*;
pub use prusti_rustc_interface::errors::MultiSpan;

mod conversions;
Expand All @@ -20,3 +21,4 @@ mod encoding_error;
mod encoding_error_kind;
mod with_span;
mod position_manager;
mod macros;

0 comments on commit 01353f4

Please sign in to comment.