Skip to content

Conversation

@Intuity
Copy link
Owner

@Intuity Intuity commented Sep 18, 2025

Adds __repr__ and __str__ to union to print out all members, also adjusts the formatting of structs to make it easier to follow:

Instruction: 0x12345678 (union):
 |- raw     -> Unsigned Scalar[32]: 0x12345678 (32 bits)
 |- add     -> Add: 0x12345678
                |- [ 1: 0] op    = 0x0
                |- [ 6: 2] tgt   = 0x1E
                |- [11: 7] src_a = 0xC
                |- [16:12] src_b = 0x5
 |- add_imm -> Add: 0x12345678
                |- [ 1: 0] op    = 0x0
                |- [ 6: 2] tgt   = 0x1E
                |- [11: 7] src_a = 0xC
                |- [16:12] src_b = 0x5

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds string representation methods (__repr__ and __str__) to union types and improves the formatting of struct string representations. The changes enhance debugging and display capabilities by providing hierarchical, tree-like output that shows all union members and their values.

  • Adds __str__ and __repr__ methods to union types to display all member fields with proper indentation
  • Updates struct formatting to use tree-like symbols and proper zero-padding for hex values
  • Enhances scalar type string representation with more descriptive naming and formatting

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packtype/types/union.py Implements __str__ and __repr__ methods for union display with tree formatting
packtype/types/scalar.py Updates scalar string representation with descriptive naming and hex formatting
packtype/types/assembly.py Improves struct formatting with tree symbols and proper hex padding
tests/pysyntax/test_union.py Adds test coverage for union string representation
tests/pysyntax/test_struct.py Adds test coverage for updated struct string representation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@OisinRobinson OisinRobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With offline discussion about how the print looks these changes look good to me- Approved.

@Intuity Intuity merged commit 396aa7f into main Sep 18, 2025
6 checks passed
@Intuity Intuity deleted the intuity/union-repr branch September 18, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants