pub struct StructType { /* private fields */ }Expand description
Represents a c-like struct type.
Limitations and warnings on its usage are similar to that in MLIR.
<https://mlir.llvm.org/docs/Dialects/LLVM/#structure-types>
- Anonymous (aka unnamed) structs cannot be recursive.
- Named structs are uniqued only by name, and may be recursive.
- LLVM calls anonymous structs as literal structs and named structs as identified structs.
- Named structs may be opaque, i.e., no body specificed. Recursive types may be created by first creating an opaque struct and later setting its fields (body).
Implementations§
Source§impl StructType
impl StructType
Sourcepub fn get_named(
ctx: &mut Context,
name: Identifier,
fields: Option<Vec<Ptr<TypeObj>>>,
) -> Result<TypePtr<Self>>
pub fn get_named( ctx: &mut Context, name: Identifier, fields: Option<Vec<Ptr<TypeObj>>>, ) -> Result<TypePtr<Self>>
Get or create a named StructType.
If fields is None, it indicates an opaque struct.
A body can be added to opaque structs by calling this again later.
Returns an error if all of the below conditions are true:
a. The name is already registered
b. The body is already set (i.e, the struct is not oqaue)
c. The fields provided here don’t match with the existing body.
Since named structs only rely on the name for uniqueness,
It is not an error to provide fields as None even when
the named struct already exists and has its body set.
Sourcepub fn get_unnamed(
ctx: &mut Context,
fields: Vec<Ptr<TypeObj>>,
) -> TypePtr<Self>
pub fn get_unnamed( ctx: &mut Context, fields: Vec<Ptr<TypeObj>>, ) -> TypePtr<Self>
Get or create a new unnamed (anonymous) struct. These are finalized upon creation, and uniqued based on the fields.
Sourcepub fn get_existing_named(
ctx: &Context,
name: &Identifier,
) -> Option<TypePtr<Self>>
pub fn get_existing_named( ctx: &Context, name: &Identifier, ) -> Option<TypePtr<Self>>
If a named struct already exists, get a pointer to it.
Sourcepub fn get_existing_unnamed(
ctx: &Context,
fields: Vec<Ptr<TypeObj>>,
) -> Option<TypePtr<Self>>
pub fn get_existing_unnamed( ctx: &Context, fields: Vec<Ptr<TypeObj>>, ) -> Option<TypePtr<Self>>
If an unnamed struct already exists, get a pointer to it.
Sourcepub fn name(&self) -> Option<Identifier>
pub fn name(&self) -> Option<Identifier>
Get this struct’s name, if it has one.
Sourcepub fn field_type(&self, field_idx: usize) -> Ptr<TypeObj>
pub fn field_type(&self, field_idx: usize) -> Ptr<TypeObj>
Get type of the idx’th field.
Sourcepub fn num_fields(&self) -> usize
pub fn num_fields(&self) -> usize
Get the number of fields this struct has
Trait Implementations§
Source§impl Debug for StructType
impl Debug for StructType
Source§impl Hash for StructType
impl Hash for StructType
Source§impl Parsable for StructType
impl Parsable for StructType
Source§type Parsed = TypePtr<StructType>
type Parsed = TypePtr<StructType>
Source§fn parse<'a>(
state_stream: &mut StateStream<'a>,
_arg: Self::Arg,
) -> ParseResult<'a, Self::Parsed>where
Self: Sized,
fn parse<'a>(
state_stream: &mut StateStream<'a>,
_arg: Self::Arg,
) -> ParseResult<'a, Self::Parsed>where
Self: Sized,
into on [Parser::parse_stream] to get the final ParseResult.
Use state_stream.state as necessary.Source§fn parser<'a>(
arg: Self::Arg,
) -> Box<dyn Parser<Stream<Stream<Stream<Stream<IteratorStream<CharIterator<'a>>, SourcePosition>>>, State<'a>>, PartialState = (), Output = Self::Parsed> + 'a>
fn parser<'a>( arg: Self::Arg, ) -> Box<dyn Parser<Stream<Stream<Stream<Stream<IteratorStream<CharIterator<'a>>, SourcePosition>>>, State<'a>>, PartialState = (), Output = Self::Parsed> + 'a>
Source§impl PartialEq for StructType
impl PartialEq for StructType
Source§impl Printable for StructType
impl Printable for StructType
Source§impl Type for StructType
impl Type for StructType
Source§fn hash_type(&self) -> TypeValueHash
fn hash_type(&self) -> TypeValueHash
Source§fn get_type_id(&self) -> TypeId
fn get_type_id(&self) -> TypeId
Source§fn get_type_id_static() -> TypeId
fn get_type_id_static() -> TypeId
Source§fn get_self_ptr(&self, ctx: &Context) -> Ptr<Box<dyn Type>>
fn get_self_ptr(&self, ctx: &Context) -> Ptr<Box<dyn Type>>
Source§fn register_instance(t: Self, ctx: &mut Context) -> TypePtr<Self>where
Self: Sized,
fn register_instance(t: Self, ctx: &mut Context) -> TypePtr<Self>where
Self: Sized,
impl Eq for StructType
Auto Trait Implementations§
impl Freeze for StructType
impl !RefUnwindSafe for StructType
impl Send for StructType
impl Sync for StructType
impl Unpin for StructType
impl UnsafeUnpin for StructType
impl !UnwindSafe for StructType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.