From 2a7fa6028a4d5f5493143be3fce5a3e91ce0d2da Mon Sep 17 00:00:00 2001 From: Alex Rice Date: Fri, 22 Nov 2024 17:30:12 +0000 Subject: [PATCH] core: add get_type helper to TypedAttribute (#3508) --- xdsl/ir/core.py | 3 +++ xdsl/printer.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/xdsl/ir/core.py b/xdsl/ir/core.py index 698f52e25d..8e4c9b7340 100644 --- a/xdsl/ir/core.py +++ b/xdsl/ir/core.py @@ -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, diff --git a/xdsl/printer.py b/xdsl/printer.py index f9b8bb4ab4..826ed3d05e 100644 --- a/xdsl/printer.py +++ b/xdsl/printer.py @@ -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 @@ -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):