Skip to content

Refactor Pattern value/format accessors into base class - #258

Open
ddmitv wants to merge 1 commit into
WerWolv:masterfrom
ddmitv:pattern-value-formatting
Open

ddmitv wants to merge 1 commit into
WerWolv:masterfrom
ddmitv:pattern-value-formatting

Conversation

@ddmitv

@ddmitv ddmitv commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Refactors pattern value access and formatting so user [[format]] attribute handling is centralized in Pattern::getFormattedValue() and Pattern::toString(), while per-pattern formatting moves into defaultToDisplayValue() and defaultToString() fallbacks. For accessing pattern's value added getRawValue for pre-[[transform]] access.

Make [[format]] functions to always receive the untransformed value (via getRawValue()) instead of the transformed one for scalar types.
Previously, fn format_field(u32 x) { ... } and fn transform_field(u32 x) { ... } applied on field u32 field [[format("format_field"), transform("transform_field")]] will apply transform_field() before passing the value to format_field(). But this is not the same for pattern types like struct, meaning for pattern values it will not apply transform_field(), and direclty pass pattern's value to format_field function. This change fixes the inconsistent behavior by never applying [[transform]] before [[format]].
I ran tests on the ImHex-Pattern repo with code from this PR and confirmed that existing hexpats do not rely on this behavior.

API changes

  • getValue() const override -> getRawValue() const override + drop transformValue(...).
  • toString() override -> defaultToString() const override.
  • formatDisplayValue() override -> defaultToDisplayValue() const override.
  • callUserFormatFunc(literal, fromCast) -> callUserFormatFunc(fromCast).
  • getValue() and toString() are no longer virtual.

Due to these breaking API changes, the main ImHex repo will not compile because it relied on them. I opened a draft PR for ImHex repo to adapt to these changes when this PR is merged - WerWolv/ImHex#2910

…lue and seperate raw/transformed pattern value accessors

This branch has not been deployed

No deployments
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.

1 participant