#188

translator: promote enum underlying types to avoid Go integer overflows

Openxlabwants to merge intofrom

Fixes #133

Problem

CEnumSpec.PromoteType previously hardcoded every C enum's underlying type to int (int32). When a C enum contains unsigned 32-bit constants above math.MaxInt32 (such as 0xFFFFFFFF), mixed signed/large values, or 64-bit constants, Go constant declarations overflow at compile time across eval, expand, and cgo rules.

Changes

  • Range-based enum type promotion (translator/model_enum.go): Track the min/max enumerator values across an enum and promote CEnumSpec.Type to the smallest matching Go integer type:
    • [math.MinInt32, math.MaxInt32] → int32 (preserves existing behavior)
    • [0, math.MaxUint32] with max > math.MaxInt32 → uint32
    • Values outside int32/uint32 within int64 (including mixed negative + 0xFFFFFFFF, < MinInt32, and (MaxUint32, MaxInt64]) → int64
    • Values > math.MaxInt64 → uint64
    • Uses long long / unsigned long long specs for 64-bit enums so Go types remain int64/uint64 regardless of LongIs64Bit, while preserving TypeTips.enum (unsigned) support.
  • Untyped numeric literals & expression validation for ConstRules.enum: expand (translator/helpers.go, translator/ast_walker.go):
    • Strip C integer suffixes (U/L/UL/LL/ULL) without wrapping in uint32(...)/int64(...)/uint64(...) for enum expressions so expanded constants remain untyped and assignable to defined enum types, and fix uppercase 0X/0B numeric parsing.
    • Validate expanded Go expressions with go/parser and go/constant against C's evaluated value, falling back to the C-evaluated value when Go would fail to parse (e.g. C-style casts) or evaluate differently due to C wrap/overflow semantics (e.g. ~0U, 1 << 31).
  • ConstRules.enum: cgo fallback for values > math.MaxInt64 (translator/ast_walker.go):
    • cmd/cgo decodes DWARF enum constants as signed int64, turning values > math.MaxInt64 (e.g. 1ULL << 63, 0xFFFFFFFFFFFFFFFFULL) into negative untyped constants that overflow uint64. Fall back to the evaluated unsigned value for those enumerators so generated cgo bindings compile with the true unsigned value.
  • Tests (translator/enum_test.go, generator/gen_const_test.go):
    • Added boundary/promotion unit tests, expand and cgo translation tests, TypeTips unsigned tests, and end-to-end generator + go build (including real cgo) compilation tests.