Skip to content

Commit

Permalink
core: add get_type helper to TypedAttribute (#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarice authored Nov 22, 2024
1 parent beb38f2 commit 2a7fa60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions xdsl/ir/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ class TypedAttribute(ParametrizedAttribute, ABC):
@classmethod
def get_type_index(cls) -> int: ...

def get_type(self) -> Attribute:
return self.parameters[self.get_type_index()]

@staticmethod
def parse_with_type(
parser: AttrParser,
Expand Down
4 changes: 2 additions & 2 deletions xdsl/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def print_attribute(self, attribute: Attribute) -> None:
# boolean shorthands
if (
isinstance(
(ty := attribute.parameters[attribute.get_type_index()]),
(ty := attribute.get_type()),
IntegerType,
)
and ty.width.data == 1
Expand All @@ -542,7 +542,7 @@ def print_attribute(self, attribute: Attribute) -> None:
if isinstance(attribute, TypedAttribute):
attribute.print_without_type(self)
self.print_string(" : ")
self.print_attribute(attribute.parameters[attribute.get_type_index()])
self.print_attribute(attribute.get_type())
return

if isinstance(attribute, StringAttr):
Expand Down

0 comments on commit 2a7fa60

Please sign in to comment.