rename minus -> negate

This commit is contained in:
collin 2020-08-07 15:14:02 -07:00
parent 599c886d23
commit f32ea5b744
7 changed files with 16 additions and 16 deletions

View File

@ -15,7 +15,7 @@ pub struct UnaryExpression<'ast> {
pub span: Span<'ast>,
}
impl<'ast> fmt::Display for UnaryExpression {
impl<'ast> fmt::Display for UnaryExpression<'ast> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", self.operation, self.expression)
}

View File

@ -71,10 +71,10 @@ let_ = { "let " }
// Declared in operations/unary_operation.rs
operation_unary = {
operation_not
| operation_minus
| operation_negate
}
operation_not = { "!" }
operation_minus = { "-" }
operation_negate = { "-" }
// Declared in operations/binary_operation.rs
operation_and = { "&&" }

View File

@ -7,14 +7,14 @@ use std::fmt;
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_unary))]
pub enum UnaryOperation {
Minus(Minus),
Negate(Negate),
Not(Not),
}
impl fmt::Display for UnaryOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
UnaryOperation::Minus(_) => write!(f, "-"),
UnaryOperation::Negate(_) => write!(f, "-"),
UnaryOperation::Not(_) => write!(f, "!"),
}
}
@ -25,5 +25,5 @@ impl fmt::Display for UnaryOperation {
pub struct Not {}
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::operation_minus))]
pub struct Minus {}
#[pest_ast(rule(Rule::operation_negate))]
pub struct Negate {}

View File

@ -6,8 +6,8 @@ pub use self::add::*;
pub mod sub;
pub use self::sub::*;
pub mod minus;
pub use self::minus::*;
pub mod negate;
pub use self::negate::*;
pub mod mul;
pub use self::mul::*;

View File

@ -1,4 +1,4 @@
//! Enforces a unary minus `-` operator in a resolved Leo program.
//! Enforces a unary negate `-` operator in a resolved Leo program.
use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType};
use leo_typed::Span;
@ -8,7 +8,7 @@ use snarkos_models::{
gadgets::r1cs::ConstraintSystem,
};
pub fn enforce_minus<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
pub fn enforce_negate<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
cs: &mut CS,
value: ConstrainedValue<F, G>,
span: Span,

View File

@ -45,11 +45,11 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
}
// Binary operations
Expression::Minus(expression, span) => {
Expression::Negate(expression, span) => {
let resolved_value =
self.enforce_expression(cs, file_scope, function_scope, expected_types, *expression)?;
enforce_minus(cs, resolved_value, span)
enforce_negate(cs, resolved_value, span)
}
Expression::Add(left, right, span) => {
let (resolved_left, resolved_right) = self.enforce_binary_expression(

View File

@ -52,7 +52,7 @@ pub enum Expression {
// Boolean operations
Not(Box<Expression>, Span),
Minus(Box<Expression>, Span),
Negate(Box<Expression>, Span),
Or(Box<Expression>, Box<Expression>, Span),
And(Box<Expression>, Box<Expression>, Span),
Eq(Box<Expression>, Box<Expression>, Span),
@ -140,7 +140,7 @@ impl<'ast> fmt::Display for Expression {
Expression::Integer(ref type_, ref integer, ref _span) => write!(f, "{}{}", integer, type_),
// Number operations
Expression::Minus(ref expression, ref _span) => write!(f, "-{}", expression),
Expression::Negate(ref expression, ref _span) => write!(f, "-{}", expression),
Expression::Add(ref left, ref right, ref _span) => write!(f, "{} + {}", left, right),
Expression::Sub(ref left, ref right, ref _span) => write!(f, "{} - {}", left, right),
Expression::Mul(ref left, ref right, ref _span) => write!(f, "{} * {}", left, right),
@ -435,7 +435,7 @@ impl<'ast> From<UnaryExpression<'ast>> for Expression {
Box::new(Expression::from(*expression.expression)),
Span::from(expression.span),
),
UnaryOperation::Minus(_) => Expression::Minus(
UnaryOperation::Negate(_) => Expression::Negate(
Box::new(Expression::from(*expression.expression)),
Span::from(expression.span),
),