Xeeynamo / sotn-decomp

Decompilation of Castlevania: Symphony of the Night (PSX+Saturn)
https://sotn.xee.dev/
GNU Affero General Public License v3.0
508 stars 55 forks source link

PrimitiveType Lint #1845

Closed hohle closed 2 weeks ago

hohle commented 2 weeks ago

Adds a line transformer to sotn-lint for replacing integers with the appropriate PrimitiveType enum when the variable is named prim and the field being accessed or mutated is named type.

The regex for matching statements with enum fields and some binary operation has been moved out to be shared by EnumLineTransformer which can find and replace traditional incrementing enums, as well as the existing BitFlagLingTransformer, which finds and replaces flag-type enums.

hohle commented 2 weeks ago

I've changed the type of the type field to PrimitiveType for Primitive, FakePrimitive, and AxePrimitive with a fixed size of 8-bits. This makes the values more discoverable and works with PS1 and PSP toolchains, however, this may be treated as signed, when those structs previously (and POLY_GT4 currently) defined the field as a u8.

This changes has been reverted because modern compilers don't like taking references to bitfields, even when they are aligned on byte boundaries. It's possible that we could get away with using PrimitiveType for the field type, but I don't think the C standard gives any guarantees regarding the size, so we would need additional assertions to ensure alignment doesn't break.