From 1c0ae8dcbec7161566af9ee30acb846d5a9790fa Mon Sep 17 00:00:00 2001 From: RREE Date: Fri, 21 Aug 2026 15:20:59 +0200 Subject: [PATCH] Fix enumeratedValues derivedFrom lookup across sibling fields Read_Field only searched the current field's own (still empty at that point) Enums vector for a derivedFrom match on , never the sibling fields already parsed in the same register. Per the CMSIS-SVD schema, a named enumeratedValues can be shared across fields via derivedFrom, so this raised Constraint_Error on any SVD using that pattern. Espressif's esp32.svd hits this: the RTC watchdog's WDT_STG2/1/0 fields each reference the enumeratedValues named "WDT_STG3" defined on their sibling WDT_STG3 field. Now the lookup also scans Vec (the register's already-parsed fields), so it finds enums defined on siblings, not just ones already appended to the current field. --- src/descriptors-field.adb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/descriptors-field.adb b/src/descriptors-field.adb index 8b22755..516a459 100644 --- a/src/descriptors-field.adb +++ b/src/descriptors-field.adb @@ -156,11 +156,28 @@ package body Descriptors.Field is elsif Tag = "enumeratedValues" then declare - Enum : constant Descriptors.Enumerate.Enumerate_T := - Descriptors.Enumerate.Read_Enumerate - (Child, Result.Enums, Result.Acc = Write_Only); + use Descriptors.Enumerate.Enumerate_Vectors; + + -- A derivedFrom attribute on this element may + -- refer to a named enumeratedValues defined in a + -- sibling field of the same register, not just + -- one already defined within this field, so the + -- lookup vector must include both. + All_Enums : Vector := Result.Enums; begin - Result.Enums.Append (Enum); + for F of Vec loop + for E of F.Enums loop + All_Enums.Append (E); + end loop; + end loop; + + declare + Enum : constant Descriptors.Enumerate.Enumerate_T := + Descriptors.Enumerate.Read_Enumerate + (Child, All_Enums, Result.Acc = Write_Only); + begin + Result.Enums.Append (Enum); + end; end; else