Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global item support to the python zapxml parser. #34603

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_zapxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,36 @@ def testFabricScopedAndSensitive(self):
qualities=StructQuality.FABRIC_SCOPED)],
)]))

def testGlobalEnum(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
<enum name="One" type="ENUM8">
<item value="3" name="Three" />
</enum>

<enum name="Two" type="ENUM8">
<item value="100" name="Big" />
<item value="2000" name="Bigger" />
</enum>
</configurator>
''')
e1 = Enum(
name='One',
base_type="ENUM8",
entries=[
ConstantEntry(name="Three", code=3),
]
)
e2 = Enum(
name='Two',
base_type="ENUM8",
entries=[
ConstantEntry(name="Big", code=100),
ConstantEntry(name="Bigger", code=2000),
]
)
self.assertEqual(idl, Idl(global_enums=[e1, e2]))

def testEnum(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
Expand Down Expand Up @@ -308,6 +338,28 @@ def testFeatures(self):
Cluster(name='TestFeatures', code=20, bitmaps=[bitmap])
])),

def testGlobalStruct(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
<struct name="SomeStruct" isFabricScoped="true">
<item name="FirstMember" type="int16u" />
<item name="SecondMember" type="int32u" />
</struct>

</configurator>
''')
struct = Struct(
name='SomeStruct',
qualities=StructQuality.FABRIC_SCOPED,
fields=[
Field(data_type=DataType(name='int16u'),
code=0, name='FirstMember'),
Field(data_type=DataType(name='int32u'),
code=1, name='SecondMember')
]
)
self.assertEqual(idl, Idl(global_structs=[struct]))

def testStruct(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
Expand Down
13 changes: 5 additions & 8 deletions scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def FinalizeProcessing(self, idl: Idl):
# - inside a cluster if a code exists
# - inside top level if no codes were associated
if not self._cluster_codes:
LOGGER.error('Struct %s has no cluster codes' % self._struct.name)
idl.global_structs.append(self._struct)
return

for code in self._cluster_codes:
Expand Down Expand Up @@ -270,9 +270,9 @@ def GetNextProcessor(self, name, attrs):

def FinalizeProcessing(self, idl: Idl):
if not self._cluster_codes:
LOGGER.error("Found enum without a cluster code: %s" %
(self._enum.name))
idl.global_enums.append(self._enum)
return

found = set()
for c in idl.clusters:
if c.code in self._cluster_codes:
Expand Down Expand Up @@ -313,14 +313,11 @@ def GetNextProcessor(self, name, attrs):
return BaseHandler(self.context)

def FinalizeProcessing(self, idl: Idl):
# We have two choices of adding an enum:
# We have two choices of adding a bitmap:
# - inside a cluster if a code exists
# - inside top level if a code does not exist
if not self._cluster_codes:
# Log only instead of critical, as not our XML is well formed.
# For example at the time of writing this, SwitchFeature in switch-cluster.xml
# did not have a code associated with it.
LOGGER.error("Bitmap %r has no cluster codes" % self._bitmap)
idl.global_bitmaps.append(self._bitmap)
return

for code in self._cluster_codes:
Expand Down
Loading