Skip to content

Commit 8e4ff10

Browse files
Take into consideration transitive dependencies, not just root struct fields (#1501)
* Take into consideration transitive dependencies, not just root struct * Apply changes addressing comments in PR * Added 2 new args in previous commit: <arg name="arg7" type="DoubleNestedStructList" /> <arg name="arg8" type="DeepNestedStructList" /> * Calculate struct_has_fabric_sensitive_fields only at the top level, not transitively * Add test for struct_contains_array * Apply suggestions from code review Co-authored-by: Boris Zbarsky <[email protected]> * Fixup references after applying suggestions from code review --------- Co-authored-by: Boris Zbarsky <[email protected]>
1 parent 6fa3da2 commit 8e4ff10

File tree

7 files changed

+58
-26
lines changed

7 files changed

+58
-26
lines changed

src-electron/db/db-mapping.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ exports.map = {
378378
isNullable: dbApi.fromDbBool(x.IS_NULLABLE),
379379
isOptional: dbApi.fromDbBool(x.IS_OPTIONAL),
380380
isFabricSensitive: dbApi.fromDbBool(x.IS_FABRIC_SENSITIVE),
381-
dataTypeReference: x.TYPE,
382-
dataTypeReferenceName: x.DATA_TYPE_REF_NAME,
381+
dataTypeReference: x.DATA_TYPE_REF,
383382
discriminatorName: x.DISCRIMINATOR_NAME
384383
}
385384
},

src-electron/db/query-zcl.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ async function selectStructsWithItemsImpl(db, packageIds, clusterId) {
342342
SI.IS_WRITABLE AS ITEM_IS_WRITABLE,
343343
SI.IS_NULLABLE AS ITEM_IS_NULLABLE,
344344
SI.IS_OPTIONAL AS ITEM_IS_OPTIONAL,
345-
SI.IS_FABRIC_SENSITIVE AS ITEM_IS_FABRIC_SENSITIVE
345+
SI.IS_FABRIC_SENSITIVE AS ITEM_IS_FABRIC_SENSITIVE,
346+
SI.DATA_TYPE_REF AS ITEM_DATA_TYPE_REF
346347
FROM
347348
STRUCT AS S
348349
INNER JOIN
@@ -374,7 +375,8 @@ async function selectStructsWithItemsImpl(db, packageIds, clusterId) {
374375
SI.IS_WRITABLE AS ITEM_IS_WRITABLE,
375376
SI.IS_NULLABLE AS ITEM_IS_NULLABLE,
376377
SI.IS_OPTIONAL AS ITEM_IS_OPTIONAL,
377-
SI.IS_FABRIC_SENSITIVE AS ITEM_IS_FABRIC_SENSITIVE
378+
SI.IS_FABRIC_SENSITIVE AS ITEM_IS_FABRIC_SENSITIVE,
379+
SI.DATA_TYPE_REF AS ITEM_DATA_TYPE_REF
378380
FROM
379381
STRUCT AS S
380382
INNER JOIN
@@ -428,7 +430,8 @@ async function selectStructsWithItemsImpl(db, packageIds, clusterId) {
428430
isWritable: dbApi.fromDbBool(value.ITEM_IS_WRITABLE),
429431
isNullable: dbApi.fromDbBool(value.ITEM_IS_NULLABLE),
430432
isOptional: dbApi.fromDbBool(value.ITEM_IS_OPTIONAL),
431-
isFabricSensitive: dbApi.fromDbBool(value.ITEM_IS_FABRIC_SENSITIVE)
433+
isFabricSensitive: dbApi.fromDbBool(value.ITEM_IS_FABRIC_SENSITIVE),
434+
dataTypeReference: value.ITEM_DATA_TYPE_REF
432435
})
433436
objectToActOn.itemCnt++
434437
return acc
@@ -449,8 +452,7 @@ async function selectAllStructItemsById(db, id) {
449452
SELECT
450453
STRUCT_ITEM.FIELD_IDENTIFIER,
451454
STRUCT_ITEM.NAME,
452-
(SELECT DATA_TYPE.NAME FROM DATA_TYPE WHERE DATA_TYPE.DATA_TYPE_ID = STRUCT_ITEM.DATA_TYPE_REF) AS TYPE,
453-
DATA_TYPE.NAME AS DATA_TYPE_REF_NAME,
455+
DATA_TYPE.NAME AS TYPE,
454456
DISCRIMINATOR.NAME AS DISCRIMINATOR_NAME,
455457
STRUCT_ITEM.STRUCT_REF,
456458
STRUCT_ITEM.IS_ARRAY,
@@ -460,7 +462,8 @@ SELECT
460462
STRUCT_ITEM.IS_WRITABLE,
461463
STRUCT_ITEM.IS_NULLABLE,
462464
STRUCT_ITEM.IS_OPTIONAL,
463-
STRUCT_ITEM.IS_FABRIC_SENSITIVE
465+
STRUCT_ITEM.IS_FABRIC_SENSITIVE,
466+
STRUCT_ITEM.DATA_TYPE_REF
464467
FROM
465468
STRUCT_ITEM
466469
INNER JOIN
@@ -498,19 +501,19 @@ async function selectAllStructItemsByStructName(
498501
let clusterJoinQuery = ''
499502
let clusterWhereQuery = ''
500503
if (clusterName) {
501-
clusterJoinQuery = `
504+
clusterJoinQuery = `
502505
INNER JOIN
503506
DATA_TYPE_CLUSTER
504507
ON
505508
DATA_TYPE_CLUSTER.DATA_TYPE_REF = DT.DATA_TYPE_ID
506509
INNER JOIN
507510
CLUSTER
508511
ON
509-
DATA_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
512+
DATA_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
510513
`
511-
clusterWhereQuery = `
514+
clusterWhereQuery = `
512515
AND
513-
CLUSTER.NAME = "${clusterName}"
516+
CLUSTER.NAME = "${clusterName}"
514517
`
515518
}
516519
return dbApi
@@ -531,7 +534,8 @@ SELECT
531534
SI.IS_WRITABLE,
532535
SI.IS_NULLABLE,
533536
SI.IS_OPTIONAL,
534-
SI.IS_FABRIC_SENSITIVE
537+
SI.IS_FABRIC_SENSITIVE,
538+
SI.DATA_TYPE_REF
535539
FROM
536540
STRUCT_ITEM AS SI
537541
INNER JOIN

src-electron/generator/helper-zcl.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,37 @@ async function zcl_structs(options) {
144144
)
145145
}
146146
structs = await zclUtil.sortStructsByDependency(structs)
147-
structs.forEach((st) => {
147+
for (const st of structs) {
148148
st.struct_contains_array = false
149149
st.struct_has_fabric_sensitive_fields = false
150150
st.has_no_clusters = st.struct_cluster_count < 1
151151
st.has_one_cluster = st.struct_cluster_count == 1
152152
st.has_more_than_one_cluster = st.struct_cluster_count > 1
153-
st.items.forEach((i) => {
154-
if (i.isArray) {
155-
st.struct_contains_array = true
153+
const checkForArraysTransitively = async (items) => {
154+
let promises = []
155+
for (const i of items) {
156+
if (i.isArray) {
157+
st.struct_contains_array = true
158+
}
159+
if (!st.struct_contains_array) {
160+
promises.push(
161+
queryZcl
162+
.selectAllStructItemsById(this.global.db, i.dataTypeReference)
163+
.then(checkForArraysTransitively)
164+
)
165+
}
166+
}
167+
if (promises.length != 0) {
168+
await Promise.all(promises)
156169
}
170+
}
171+
for (const i of st.items) {
157172
if (i.isFabricSensitive) {
158173
st.struct_has_fabric_sensitive_fields = true
159174
}
160-
})
161-
})
175+
}
176+
await checkForArraysTransitively(st.items)
177+
}
162178
if (checkForDoubleNestedArray) {
163179
// If this is set to true in a template, then we populate the
164180
// struct_contains_nested_array variable with true
@@ -169,10 +185,9 @@ async function zcl_structs(options) {
169185
for (const i of st.items) {
170186
if (i.isArray) {
171187
// Found an array. Now let's check if it points to a struct that also contains an array.
172-
let sis = await queryZcl.selectAllStructItemsByStructName(
188+
let sis = await queryZcl.selectAllStructItemsById(
173189
this.global.db,
174-
i.type,
175-
packageIds
190+
i.dataTypeReference
176191
)
177192
if (sis.length > 0) {
178193
for (const ss of sis) {

test/gen-matter-3-1.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ test(
476476
expect(ept).toContain(
477477
'TargetStruct item 4 from Binding cluster: FabricIndex'
478478
)
479+
480+
expect(ept).toContain('Struct with array: NestedStructList')
481+
expect(ept).toContain('Struct with array: DoubleNestedStructList')
479482
},
480483
testUtil.timeout.long()
481484
)

test/gen-template/matter3/miscellaneous_helper_tests.zapt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ TargetStruct item {{index}} from Access Control cluster: {{name}}
2828

2929
{{#zcl_struct_items_by_struct_and_cluster_name "TargetStruct" "Binding"}}
3030
TargetStruct item {{index}} from Binding cluster: {{name}}
31-
{{/zcl_struct_items_by_struct_and_cluster_name}}
31+
{{/zcl_struct_items_by_struct_and_cluster_name}}
32+
33+
{{#zcl_structs}}
34+
{{#if struct_contains_array}} Struct with array: {{name}}
35+
{{/if}}
36+
{{/zcl_structs}}

test/test-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ exports.totalDotDotEnumItems = 637
189189

190190
exports.totalMatterClusters = 72
191191
exports.totalMatterDeviceTypes = 119
192-
exports.totalMatterCommandArgs = 595
192+
exports.totalMatterCommandArgs = 597
193193
exports.totalMatterCommands = 248
194194
exports.totalMatterAttributes = 784
195195
exports.totalMatterTags = 17

zcl-builtin/matter/data-model/chip/test-cluster.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ limitations under the License.
8383
<item name="a" type="NestedStructList" array="true" optional="false"/>
8484
</struct>
8585

86+
<struct name="DeepNestedStructList">
87+
<cluster code="0xFFF1FC05"/>
88+
<item name="a" type="NestedStructList" optional="false"/>
89+
</struct>
8690

8791
<struct name="NullablesAndOptionalsStruct">
8892
<cluster code="0xFFF1FC05"/>
@@ -127,15 +131,15 @@ limitations under the License.
127131
<field mask="0x04" name="MaskVal3" />
128132
<field mask="0x40000000" name="MaskVal4" />
129133
</bitmap>
130-
134+
131135
<bitmap name="Bitmap64MaskMap" type="BITMAP64">
132136
<cluster code="0xFFF1FC05" />
133137
<field mask="0x01" name="MaskVal1" />
134138
<field mask="0x02" name="MaskVal2" />
135139
<field mask="0x04" name="MaskVal3" />
136140
<field mask="0x4000000000000000" name="MaskVal4" />
137141
</bitmap>
138-
142+
139143
<cluster>
140144
<domain>CHIP</domain>
141145
<name>Unit Testing</name>
@@ -287,6 +291,8 @@ limitations under the License.
287291
<arg name="arg4" type="BOOLEAN" array="true"/>
288292
<arg name="arg5" type="SimpleEnum"/>
289293
<arg name="arg6" type="BOOLEAN"/>
294+
<arg name="arg7" type="DoubleNestedStructList" />
295+
<arg name="arg8" type="DeepNestedStructList" />
290296
</command>
291297

292298
<command source="client" code="0x07" name="TestStructArgumentRequest"

0 commit comments

Comments
 (0)