From f12eafb957cbf5f28e5e36b27f9432b5f68e6b8e Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 14 Sep 2021 18:01:24 +0300 Subject: [PATCH] replace sizeof with lengthof --- ast/src/expression/lengthof.rs | 2 +- ast/src/reducer/reconstructing_director.rs | 2 +- compiler/src/expression/expression.rs | 2 +- compiler/src/expression/operator/lengthof.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ast/src/expression/lengthof.rs b/ast/src/expression/lengthof.rs index e5dec13a62..2dcc4175de 100644 --- a/ast/src/expression/lengthof.rs +++ b/ast/src/expression/lengthof.rs @@ -26,7 +26,7 @@ pub struct LengthOfExpression { impl fmt::Display for LengthOfExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "sizeof {}", self.inner) + write!(f, "{}.len()", self.inner) } } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 41133a5359..1bd2567e90 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -57,7 +57,7 @@ impl ReconstructingDirector { Expression::Unary(unary) => Expression::Unary(self.reduce_unary(unary)?), Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(ternary)?), Expression::Cast(cast) => Expression::Cast(self.reduce_cast(cast)?), - Expression::LengthOf(sizeof) => Expression::LengthOf(sizeof.clone()), // Expression::LengthOf(self.reduce_sizeof(sizeof)?), // TODO: add reducer + Expression::LengthOf(lengthof) => Expression::LengthOf(lengthof.clone()), // Expression::LengthOf(self.reduce_lengthof(lengthof)?), // TODO: add reducer Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(array_inline)?), Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(array_init)?), diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 4f9eb24711..1b52608de8 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -99,7 +99,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Expression::Cast(_) => unimplemented!("casts not implemented"), // LengthOf - Expression::LengthOf(sizeof) => self.enforce_sizeof(cs, sizeof, span), + Expression::LengthOf(lengthof) => self.enforce_lengthof(cs, lengthof, span), // Variables Expression::VariableRef(variable_ref) => self.evaluate_ref(variable_ref), diff --git a/compiler/src/expression/operator/lengthof.rs b/compiler/src/expression/operator/lengthof.rs index 440d1020d0..8e4b8dc401 100644 --- a/compiler/src/expression/operator/lengthof.rs +++ b/compiler/src/expression/operator/lengthof.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! Enforces a sizeof operator in a compiled Leo program. +//! Enforces a lengthof operator in a compiled Leo program. use crate::{ program::ConstrainedProgram, @@ -29,7 +29,7 @@ use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce array expressions - pub fn enforce_sizeof>( + pub fn enforce_lengthof>( &mut self, cs: &mut CS, lengthof: &'a LengthOfExpression<'a>,