Skip to content

Commit

Permalink
python: add offset and bit_size to Member
Browse files Browse the repository at this point in the history
  • Loading branch information
zolutal committed Jan 14, 2024
1 parent a818a1e commit 4af4a72
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
2 changes: 2 additions & 0 deletions python_stubs/dwat/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class Member:
Base | Const | Volatile | Restrict
]: ...
byte_size: typing.Optional[int]
bit_size: typing.Optional[int]
offset: typing.Optional[str]
name: typing.Optional[str]

class Parameter:
Expand Down
47 changes: 30 additions & 17 deletions src/python/pytypes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use pyo3::prelude::*;

use crate::prelude::*;
use crate::Error;
use super::Dwarf;

#[pyclass]
Expand Down Expand Up @@ -193,13 +194,13 @@ impl Struct {
/// The name of the struct
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// A list of members/fields of this struct
Expand Down Expand Up @@ -237,7 +238,7 @@ impl Array {
/// The size (footprint) of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the array
Expand All @@ -263,13 +264,13 @@ impl Enum {
/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// The name of the enum
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// Retrieves the backing type of the enum
Expand All @@ -288,7 +289,7 @@ impl Pointer {
/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the pointer
Expand Down Expand Up @@ -344,13 +345,13 @@ impl Typedef {
/// The name of the typedef
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the typedef
Expand All @@ -377,13 +378,13 @@ impl Union {
/// The name of the union
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// A list of members of this union
Expand Down Expand Up @@ -421,13 +422,13 @@ impl Base {
/// The name of the base type
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

pub fn __str__(&self) -> PyResult<Option<String>> {
Expand All @@ -448,7 +449,7 @@ impl Const {
/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the const modifier
Expand All @@ -467,7 +468,7 @@ impl Volatile {
/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the volatile modifier
Expand All @@ -486,7 +487,7 @@ impl Restrict {
/// The size of this type in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// Retrieves the backing type of the restrict modifier
Expand Down Expand Up @@ -518,13 +519,25 @@ impl Member {
/// The name of the member
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
attr_getter!(self, name, crate::Error::NameAttributeNotFound)
attr_getter!(self, name, Error::NameAttributeNotFound)
}

/// The size of this member in bytes
#[getter]
pub fn byte_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, byte_size, crate::Error::ByteSizeAttributeNotFound)
attr_getter!(self, byte_size, Error::ByteSizeAttributeNotFound)
}

/// The size of this member in bits (only present for bitfields)
#[getter]
pub fn bit_size(&self) -> PyResult<Option<usize>> {
attr_getter!(self, bit_size, Error::BitSizeAttributeNotFound)
}

/// The offset of this member from the start of the data type
#[getter]
pub fn offset(&self) -> PyResult<Option<usize>> {
attr_getter!(self, offset, Error::MemberLocationAttributeNotFound)
}

/// Retrieves the backing type of the member
Expand Down

0 comments on commit 4af4a72

Please sign in to comment.