replace sizeof with lengthof

This commit is contained in:
damirka 2021-09-14 18:01:24 +03:00
parent 4f41f09ef2
commit f12eafb957
4 changed files with 5 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -57,7 +57,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
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)?),

View File

@ -99,7 +99,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> 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),

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! 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<F>> ConstrainedProgram<'a, F, G> {
/// Enforce array expressions
pub fn enforce_sizeof<CS: ConstraintSystem<F>>(
pub fn enforce_lengthof<CS: ConstraintSystem<F>>(
&mut self,
cs: &mut CS,
lengthof: &'a LengthOfExpression<'a>,