diff options
| author | toolCHAINZ <toolCHAINZ@users.noreply.github.com> | 2023-05-04 21:19:32 -0400 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-05-10 17:45:15 -0400 |
| commit | 3cbd7682c8696a2005b98e3c1b09f3357ced012d (patch) | |
| tree | a80ee5ba13b068e048605215ea4abf07bab1616b /rust/src/types.rs | |
| parent | dfd2b29120baa6d86ab6e76ab5f940dec63ffe37 (diff) | |
Added some stack layout and reference APIs
Diffstat (limited to 'rust/src/types.rs')
| -rw-r--r-- | rust/src/types.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/rust/src/types.rs b/rust/src/types.rs index 23a28631..174dcb14 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -38,6 +38,7 @@ use std::{ hash::{Hash, Hasher}, iter::{zip, IntoIterator}, mem, + mem::ManuallyDrop, os::raw::c_char, ptr, result, slice, sync::Mutex, @@ -1343,6 +1344,64 @@ impl Variable { } } +/////////////// +// NamedVariable + +pub struct NamedTypedVariable { + var: BNVariable, + auto_defined: bool, + type_confidence: u8, + name: *mut std::os::raw::c_char, + ty: *mut BNType, +} + +impl NamedTypedVariable { + pub fn name(&self) -> &str { + unsafe { BnStr::from_raw(self.name).as_str() } + } + + pub fn var(&self) -> Variable { + unsafe { Variable::from_raw(self.var) } + } + + pub fn auto_defined(&self) -> bool { + self.auto_defined + } + + pub fn type_confidence(&self) -> u8 { + self.type_confidence + } + + pub fn var_type(&self) -> Ref<Type> { + unsafe { Ref::new(Type::from_raw(self.ty)) } + } +} + +impl CoreArrayProvider for NamedTypedVariable { + type Raw = BNVariableNameAndType; + type Context = (); +} + +unsafe impl CoreOwnedArrayProvider for NamedTypedVariable { + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { + BNFreeVariableNameAndTypeList(raw, count) + } +} + +unsafe impl<'a> CoreArrayWrapper<'a> for NamedTypedVariable { + type Wrapped = ManuallyDrop<NamedTypedVariable>; + + unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { + ManuallyDrop::new(NamedTypedVariable { + var: raw.var, + ty: raw.type_, + name: raw.name, + auto_defined: raw.autoDefined, + type_confidence: raw.typeConfidence, + }) + } +} + //////////////////////// // EnumerationBuilder |
