Skip to content

Commit

Permalink
Drop enum support for larger than 16 bit. (#30984)
Browse files Browse the repository at this point in the history
* Drop enum support for larger than 16 bit.

Spec 7.19.2 Daa Types explicitly says that enumerations may only go up
to enum16 and chip-types.xml agrees with that.

* Fix missing comma

* also remove references of bitmap24. Those were removed from the spec

* Zap regen
  • Loading branch information
andy31415 authored and pull[bot] committed Jan 8, 2024
1 parent 2838d4c commit 1156447
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def toEnumEntryName(enumEntry, enumName):
def toProtobufType(zapType: str) -> str:
""" Convert zap type to protobuf type """
u32Types = [
"uint32", "enum8", "enum16", "enum32", "bitmap8",
"uint32", "enum8", "enum16", "bitmap8",
"bitmap16", "bitmap32", "cluster_id", "attrib_id",
"event_id", "command_id", "endpoint_no", "group_id",
"devtype_id", "fabric_idx", "vendor_id", "status_code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def EndProcessing(self):
if not self._enum.entries:
return

# try to find the best enum size that fits out of enum8, enum32 and enum32
# try to find the best enum size that fits out of enum8 and enum16
# TODO: this is a pure heuristic. XML containing this would be better.
# https://github.com/csa-data-model/projects/issues/345
acceptable = {8, 16}
Expand Down
4 changes: 0 additions & 4 deletions scripts/py_matter_idl/matter_idl/generators/java/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ def FieldToGlobalName(field: Field, context: TypeLookupContext) -> Optional[str]
# non-named enums
'enum8': 'uint8_t',
'enum16': 'uint16_t',
'enum32': 'uint32_t',
'enum64': 'uint64_t',
}


Expand Down Expand Up @@ -320,8 +318,6 @@ def _IsUsingGlobalCallback(field: Field, context: TypeLookupContext):
"int64u",
"enum8",
"enum16",
"enum32",
"enum64",
"bitmap8",
"bitmap16",
"bitmap32",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ def FieldToGlobalName(field: Field, context: TypeLookupContext) -> Optional[str]
# non-named enums
'enum8': 'uint8_t',
'enum16': 'uint16_t',
'enum32': 'uint32_t',
'enum64': 'uint64_t',
}


Expand Down
11 changes: 4 additions & 7 deletions scripts/py_matter_idl/matter_idl/generators/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,10 @@ def is_struct(self) -> bool:
# Data types, held by ZAP in chip-types.xml and generally by the spec.
__CHIP_SIZED_TYPES__ = {
"bitmap16": BasicInteger(idl_name="bitmap16", byte_count=2, is_signed=False),
"bitmap24": BasicInteger(idl_name="bitmap24", byte_count=3, is_signed=False),
"bitmap32": BasicInteger(idl_name="bitmap32", byte_count=4, is_signed=False),
"bitmap64": BasicInteger(idl_name="bitmap64", byte_count=8, is_signed=False),
"bitmap8": BasicInteger(idl_name="bitmap8", byte_count=1, is_signed=False),
"enum16": BasicInteger(idl_name="enum16", byte_count=2, is_signed=False),
"enum24": BasicInteger(idl_name="enum24", byte_count=3, is_signed=False),
"enum32": BasicInteger(idl_name="enum32", byte_count=4, is_signed=False),
"enum8": BasicInteger(idl_name="enum8", byte_count=1, is_signed=False),
"int16s": BasicInteger(idl_name="int16s", byte_count=2, is_signed=True),
"int16u": BasicInteger(idl_name="int16u", byte_count=2, is_signed=False),
Expand Down Expand Up @@ -336,7 +333,7 @@ def is_enum_type(self, name: str):
Handles both standard names (like enum8) as well as enumerations defined
within the current lookup context.
"""
if name.lower() in ["enum8", "enum16", "enum24", "enum32"]:
if name.lower() in ["enum8", "enum16"]:
return True
return any(map(lambda e: e.name == name, self.all_enums))

Expand All @@ -348,7 +345,7 @@ def is_struct_type(self, name: str):

def is_untyped_bitmap_type(self, name: str):
"""Determine if the given type is a untyped bitmap (just an interger size)."""
return name.lower() in {"bitmap8", "bitmap16", "bitmap24", "bitmap32", "bitmap64"}
return name.lower() in {"bitmap8", "bitmap16", "bitmap32", "bitmap64"}

def is_bitmap_type(self, name: str):
"""
Expand Down Expand Up @@ -386,9 +383,9 @@ def ParseDataType(data_type: DataType, lookup: TypeLookupContext) -> Union[Basic
return BasicString(idl_name=lowercase_name, is_binary=False, max_length=data_type.max_length)
elif lowercase_name in ['octet_string', 'long_octet_string']:
return BasicString(idl_name=lowercase_name, is_binary=True, max_length=data_type.max_length)
elif lowercase_name in ['enum8', 'enum16', 'enum24', 'enum32']:
elif lowercase_name in ['enum8', 'enum16']:
return IdlEnumType(idl_name=lowercase_name, base_type=__CHIP_SIZED_TYPES__[lowercase_name])
elif lowercase_name in ['bitmap8', 'bitmap16', 'bitmap24', 'bitmap32', 'bitmap64']:
elif lowercase_name in ['bitmap8', 'bitmap16', 'bitmap32', 'bitmap64']:
return IdlBitmapType(idl_name=lowercase_name, base_type=__CHIP_SIZED_TYPES__[lowercase_name])

int_type = __CHIP_SIZED_TYPES__.get(lowercase_name, None)
Expand Down
6 changes: 3 additions & 3 deletions scripts/py_matter_idl/matter_idl/test_supported_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def testAllTypesSupported(self):
# handled as a non-integer type
"boolean", "single", "double",
# handled as specific bitmaps
"bitmap8", "bitmap16", "bitmap24", "bitmap32", "bitmap64",
# handled as specific enums
"enum8", "enum16", "enum24", "enum32",
"bitmap8", "bitmap16", "bitmap32", "bitmap64",
# handled as specific enums. Note that spec defines enumerations only for 8 and 16
"enum8", "enum16",

# TODO: these may be bugs to fix
"unknown"
Expand Down
1 change: 0 additions & 1 deletion src/app/tests/suites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ src/app/tests/suites/examples/gen_readme_example.sh
| boolean | 1 | BOOLEAN | 0x10 | Boolean | uint8_t |
| bitmap8 | 1 | BITMAP8 | 0x18 | 8-bit bitmap | uint8_t |
| bitmap16 | 2 | BITMAP16 | 0x19 | 16-bit bitmap | uint16_t |
| bitmap24 | 3 | BITMAP24 | 0x1A | 24-bit bitmap | uint32_t |
| bitmap32 | 4 | BITMAP32 | 0x1B | 32-bit bitmap | uint32_t |
| bitmap64 | 8 | BITMAP64 | 0x1F | 64-bit bitmap | uint8_t \* |
| int8u | 1 | INT8U | 0x20 | Unsigned 8-bit integer | uint8_t |
Expand Down
1 change: 0 additions & 1 deletion src/app/zap-templates/zcl/data-model/chip/chip-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ limitations under the License.
<type id="0x10" description="Boolean" name="boolean" size="1" discrete="true" />
<type id="0x18" description="8-bit bitmap" name="bitmap8" size="1" discrete="true" />
<type id="0x19" description="16-bit bitmap" name="bitmap16" size="2" discrete="true" />
<type id="0x1A" description="24-bit bitmap" name="bitmap24" size="3" discrete="true" />
<type id="0x1B" description="32-bit bitmap" name="bitmap32" size="4" discrete="true" />
<type id="0x1F" description="64-bit bitmap" name="bitmap64" size="8" discrete="true" />
<type id="0x20" description="Unsigned 8-bit integer" name="int8u" size="1" analog="true" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1156447

Please sign in to comment.