From 729bf277aac0296a7bb0ad2ea32a9540190a8594 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 1 Nov 2024 13:40:00 -0700 Subject: [PATCH] Make python methods public rust functions --- crates/clarirs_py/src/ast/base.rs | 6 +- crates/clarirs_py/src/ast/bool.rs | 30 +++---- crates/clarirs_py/src/ast/bv.rs | 122 ++++++++++++++-------------- crates/clarirs_py/src/ast/fp.rs | 22 ++--- crates/clarirs_py/src/ast/string.rs | 18 ++-- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/crates/clarirs_py/src/ast/base.rs b/crates/clarirs_py/src/ast/base.rs index 9e87a2e..2111c22 100644 --- a/crates/clarirs_py/src/ast/base.rs +++ b/crates/clarirs_py/src/ast/base.rs @@ -30,17 +30,17 @@ impl Base { #[pymethods] impl Base { #[getter] - fn name(&self) -> Option<&str> { + pub fn name(&self) -> Option<&str> { self.name.as_deref() } #[getter] - fn _encoded_name(&self) -> Option<&[u8]> { + pub fn _encoded_name(&self) -> Option<&[u8]> { self.encoded_name.as_deref() } #[getter] - fn _errored(&self) -> Py { + pub fn _errored(&self) -> Py { self.errored.clone() } } diff --git a/crates/clarirs_py/src/ast/bool.rs b/crates/clarirs_py/src/ast/bool.rs index c82cee2..03917e6 100644 --- a/crates/clarirs_py/src/ast/bool.rs +++ b/crates/clarirs_py/src/ast/bool.rs @@ -57,17 +57,17 @@ impl Bool { #[pymethods] impl Bool { #[getter] - fn op(&self) -> String { + pub fn op(&self) -> String { self.inner.op().to_opstring() } #[getter] - fn args(&self, py: Python) -> Result, ClaripyError> { + pub fn args(&self, py: Python) -> Result, ClaripyError> { self.inner.op().extract_py_args(py) } #[getter] - fn variables(&self, py: Python) -> Result, ClaripyError> { + pub fn variables(&self, py: Python) -> Result, ClaripyError> { Ok(PyFrozenSet::new_bound( py, self.inner @@ -81,12 +81,12 @@ impl Bool { } #[getter] - fn symbolic(&self) -> bool { + pub fn symbolic(&self) -> bool { self.inner.symbolic() } #[getter] - fn annotations(&self, py: Python) -> PyResult> { + pub fn annotations(&self, py: Python) -> PyResult> { let pickle_loads = py.import_bound("pickle")?.getattr("loads")?; self.inner .get_annotations() @@ -96,28 +96,28 @@ impl Bool { .collect() } - fn hash(&self) -> u64 { + pub fn hash(&self) -> u64 { self.inner.hash() } #[getter] - fn depth(&self) -> u32 { + pub fn depth(&self) -> u32 { self.inner.depth() } - fn is_leaf(&self) -> bool { + pub fn is_leaf(&self) -> bool { self.inner.depth() == 1 } - fn is_true(&self) -> bool { + pub fn is_true(&self) -> bool { self.inner.is_true() } - fn is_false(&self) -> bool { + pub fn is_false(&self) -> bool { self.inner.is_false() } - fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { + pub fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { let pickle_dumps = py.import_bound("pickle")?.getattr("dumps")?; let annotation_bytes = pickle_dumps .call1((&annotation,))? @@ -134,25 +134,25 @@ impl Bool { ) } - fn __invert__(&self, py: Python) -> Result, ClaripyError> { + pub fn __invert__(&self, py: Python) -> Result, ClaripyError> { Bool::new(py, &GLOBAL_CONTEXT.not(&self.inner)?) } - fn __and__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { + pub fn __and__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.and(&self.inner, &>::into(other))?, ) } - fn __or__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { + pub fn __or__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.or(&self.inner, &>::into(other))?, ) } - fn __xor__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { + pub fn __xor__(&self, py: Python, other: CoerceBool) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.xor(&self.inner, &>::into(other))?, diff --git a/crates/clarirs_py/src/ast/bv.rs b/crates/clarirs_py/src/ast/bv.rs index a14134f..f4f64fd 100644 --- a/crates/clarirs_py/src/ast/bv.rs +++ b/crates/clarirs_py/src/ast/bv.rs @@ -57,17 +57,17 @@ impl BV { #[pymethods] impl BV { #[getter] - fn op(&self) -> String { + pub fn op(&self) -> String { self.inner.op().to_opstring() } #[getter] - fn args(&self, py: Python) -> Result, ClaripyError> { + pub fn args(&self, py: Python) -> Result, ClaripyError> { self.inner.op().extract_py_args(py) } #[getter] - fn variables(&self, py: Python) -> Result, ClaripyError> { + pub fn variables(&self, py: Python) -> Result, ClaripyError> { Ok(PyFrozenSet::new_bound( py, self.inner @@ -81,12 +81,12 @@ impl BV { } #[getter] - fn symbolic(&self) -> bool { + pub fn symbolic(&self) -> bool { self.inner.symbolic() } #[getter] - fn annotations(&self, py: Python) -> PyResult> { + pub fn annotations(&self, py: Python) -> PyResult> { let pickle_loads = py.import_bound("pickle")?.getattr("loads")?; self.inner .get_annotations() @@ -96,28 +96,28 @@ impl BV { .collect() } - fn hash(&self) -> u64 { + pub fn hash(&self) -> u64 { self.inner.hash() } #[getter] - fn depth(&self) -> u32 { + pub fn depth(&self) -> u32 { self.inner.depth() } - fn is_leaf(&self) -> bool { + pub fn is_leaf(&self) -> bool { self.inner.depth() == 1 } - fn size(&self) -> usize { + pub fn size(&self) -> usize { self.inner.size() as usize } - fn __len__(&self) -> usize { + pub fn __len__(&self) -> usize { self.size() } - fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { + pub fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { let pickle_dumps = py.import_bound("pickle")?.getattr("dumps")?; let annotation_bytes = pickle_dumps .call1((&annotation,))? @@ -134,62 +134,62 @@ impl BV { ) } - fn __add__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __add__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.add(&self.inner, &>::into(other))?, ) } - fn __radd__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __radd__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__add__(py, other) } - fn __sub__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __sub__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.sub(&self.inner, &>::into(other))?, ) } - fn __rsub__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rsub__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__sub__(py, other) } - fn __mul__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __mul__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.mul(&self.inner, &>::into(other))?, ) } - fn __rmul__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rmul__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__mul__(py, other) } - fn __truediv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __truediv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.udiv(&self.inner, &>::into(other))?, ) } - fn __rtruediv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rtruediv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__truediv__(py, other) } - fn __floordiv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __floordiv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.udiv(&self.inner, &>::into(other))?, ) } - fn __rfloordiv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rfloordiv__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__floordiv__(py, other) } - fn __pow__( + pub fn __pow__( &self, py: Python, other: CoerceBV, @@ -202,7 +202,7 @@ impl BV { ) } - fn __rpow__( + pub fn __rpow__( &self, py: Python, other: CoerceBV, @@ -211,208 +211,208 @@ impl BV { self.__pow__(py, other, _modulo) } - fn __mod__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __mod__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.urem(&self.inner, &>::into(other))?, ) } - fn __rmod__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rmod__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__mod__(py, other) } - fn SDiv(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SDiv(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.sdiv(&self.inner, &>::into(other))?, ) } - fn SMod(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SMod(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.srem(&self.inner, &>::into(other))?, ) } - fn __and__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __and__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.and(&self.inner, &>::into(other))?, ) } - fn __rand__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rand__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__and__(py, other) } - fn __or__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __or__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.or(&self.inner, &>::into(other))?, ) } - fn __ror__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __ror__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__or__(py, other) } - fn __xor__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __xor__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.xor(&self.inner, &>::into(other))?, ) } - fn __rxor__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rxor__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__xor__(py, other) } - fn __lshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __lshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.shl(&self.inner, &>::into(other))?, ) } - fn __rlshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rlshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__lshift__(py, other) } - fn __rshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.ashr(&self.inner, &>::into(other))?, ) } - fn __rrshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __rrshift__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { self.__rshift__(py, other) } - fn LShR(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn LShR(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.lshr(&self.inner, &>::into(other))?, ) } - fn __neg__(&self, py: Python) -> Result, ClaripyError> { + pub fn __neg__(&self, py: Python) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.not(&self.inner)?) } - fn __invert__(&self, py: Python) -> Result, ClaripyError> { + pub fn __invert__(&self, py: Python) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.not(&self.inner)?) } - fn __pos__(self_: Py) -> Result, ClaripyError> { + pub fn __pos__(self_: Py) -> Result, ClaripyError> { Ok(self_) } - fn __abs__(&self, py: Python) -> Result, ClaripyError> { + pub fn __abs__(&self, py: Python) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.abs(&self.inner)?) } - fn __eq__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __eq__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.eq_(&self.inner, &>::into(other))?, ) } - fn __ne__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __ne__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.neq(&self.inner, &>::into(other))?, ) } - fn __lt__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __lt__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ult(&self.inner, &>::into(other))?, ) } - fn __le__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __le__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ule(&self.inner, &>::into(other))?, ) } - fn __gt__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __gt__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ugt(&self.inner, &>::into(other))?, ) } - fn __ge__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn __ge__(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.uge(&self.inner, &>::into(other))?, ) } - fn ULT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn ULT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ult(&self.inner, &>::into(other))?, ) } - fn ULE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn ULE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ule(&self.inner, &>::into(other))?, ) } - fn UGT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn UGT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.ugt(&self.inner, &>::into(other))?, ) } - fn UGE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn UGE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.uge(&self.inner, &>::into(other))?, ) } - fn SLT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SLT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.slt(&self.inner, &>::into(other))?, ) } - fn SLE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SLE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.sle(&self.inner, &>::into(other))?, ) } - fn SGT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SGT(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.sgt(&self.inner, &>::into(other))?, ) } - fn SGE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn SGE(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { Bool::new( py, &GLOBAL_CONTEXT.sge(&self.inner, &>::into(other))?, ) } - fn Extract( + pub fn Extract( &self, py: Python, upper_bound: u32, @@ -424,23 +424,23 @@ impl BV { ) } - fn concat(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { + pub fn concat(&self, py: Python, other: CoerceBV) -> Result, ClaripyError> { BV::new( py, &GLOBAL_CONTEXT.concat(&self.inner, &>::into(other))?, ) } - fn zero_ext(&self, py: Python, amount: u32) -> Result, ClaripyError> { + pub fn zero_ext(&self, py: Python, amount: u32) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.zero_ext(&self.inner, amount)?) } - fn sign_ext(&self, py: Python, amount: u32) -> Result, ClaripyError> { + pub fn sign_ext(&self, py: Python, amount: u32) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.sign_ext(&self.inner, amount)?) } #[getter] - fn reversed(&self, py: Python) -> Result, ClaripyError> { + pub fn reversed(&self, py: Python) -> Result, ClaripyError> { BV::new(py, &GLOBAL_CONTEXT.reverse(&self.inner)?) } } diff --git a/crates/clarirs_py/src/ast/fp.rs b/crates/clarirs_py/src/ast/fp.rs index ac5167f..69d9ce1 100644 --- a/crates/clarirs_py/src/ast/fp.rs +++ b/crates/clarirs_py/src/ast/fp.rs @@ -140,17 +140,17 @@ impl FP { #[pymethods] impl FP { #[getter] - fn op(&self) -> String { + pub fn op(&self) -> String { self.inner.op().to_opstring() } #[getter] - fn args(&self, py: Python) -> Result, ClaripyError> { + pub fn args(&self, py: Python) -> Result, ClaripyError> { self.inner.op().extract_py_args(py) } #[getter] - fn variables(&self, py: Python) -> Result, ClaripyError> { + pub fn variables(&self, py: Python) -> Result, ClaripyError> { Ok(PyFrozenSet::new_bound( py, self.inner @@ -164,12 +164,12 @@ impl FP { } #[getter] - fn symbolic(&self) -> bool { + pub fn symbolic(&self) -> bool { self.inner.symbolic() } #[getter] - fn annotations(&self, py: Python) -> PyResult> { + pub fn annotations(&self, py: Python) -> PyResult> { let pickle_loads = py.import_bound("pickle")?.getattr("loads")?; self.inner .get_annotations() @@ -179,28 +179,28 @@ impl FP { .collect() } - fn hash(&self) -> u64 { + pub fn hash(&self) -> u64 { self.inner.hash() } #[getter] - fn depth(&self) -> u32 { + pub fn depth(&self) -> u32 { self.inner.depth() } - fn is_leaf(&self) -> bool { + pub fn is_leaf(&self) -> bool { self.inner.depth() == 1 } - fn size(&self) -> usize { + pub fn size(&self) -> usize { self.inner.size() as usize } - fn __len__(&self) -> usize { + pub fn __len__(&self) -> usize { self.size() } - fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { + pub fn annotate(&self, py: Python, annotation: Bound) -> Result, ClaripyError> { let pickle_dumps = py.import_bound("pickle")?.getattr("dumps")?; let annotation_bytes = pickle_dumps .call1((&annotation,))? diff --git a/crates/clarirs_py/src/ast/string.rs b/crates/clarirs_py/src/ast/string.rs index 279c0a1..d554ede 100644 --- a/crates/clarirs_py/src/ast/string.rs +++ b/crates/clarirs_py/src/ast/string.rs @@ -54,17 +54,17 @@ impl PyAstString { #[pymethods] impl PyAstString { #[getter] - fn op(&self) -> String { + pub fn op(&self) -> String { self.inner.op().to_opstring() } #[getter] - fn args(&self, py: Python) -> Result, ClaripyError> { + pub fn args(&self, py: Python) -> Result, ClaripyError> { self.inner.op().extract_py_args(py) } #[getter] - fn variables(&self, py: Python) -> Result, ClaripyError> { + pub fn variables(&self, py: Python) -> Result, ClaripyError> { Ok(PyFrozenSet::new_bound( py, self.inner @@ -78,12 +78,12 @@ impl PyAstString { } #[getter] - fn symbolic(&self) -> bool { + pub fn symbolic(&self) -> bool { self.inner.symbolic() } #[getter] - fn annotations(&self, py: Python) -> PyResult> { + pub fn annotations(&self, py: Python) -> PyResult> { let pickle_loads = py.import_bound("pickle")?.getattr("loads")?; self.inner .get_annotations() @@ -93,20 +93,20 @@ impl PyAstString { .collect() } - fn hash(&self) -> u64 { + pub fn hash(&self) -> u64 { self.inner.hash() } #[getter] - fn depth(&self) -> u32 { + pub fn depth(&self) -> u32 { self.inner.depth() } - fn is_leaf(&self) -> bool { + pub fn is_leaf(&self) -> bool { self.inner.depth() == 1 } - fn annotate( + pub fn annotate( &self, py: Python, annotation: Bound,