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

Enums that are not used as a type in XML can now suppress codegen intended for DataModel::Decode #29739

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ WeakEnums:
- RadioFaultEnum
- StepMode

EnumsNotUsedInDataModelStruct:
tehampson marked this conversation as resolved.
Show resolved Hide resolved
# List of enums that are not used in a DataModel Struct. By adding an enum
tehampson marked this conversation as resolved.
Show resolved Hide resolved
# to this list you prevent incorrectly assuming from code that you are
# able to use kUnknownEnumValue safely. This happens for derivate clusters
tehampson marked this conversation as resolved.
Show resolved Hide resolved
# such as ModeBase where there are CommonTag, DerivedClusterTags, MfgTags.
- "DishwasherMode::ModeTag"
- "LaundryWasherMode::ModeTag"
- "RefrigeratorAndTemperatureControlledCabinetMode::ModeTag"
- "RvcRunMode::ModeTag"
- "RvcRunMode::StatusCode"
- "RvcCleanMode::ModeTag"
- "RvcCleanMode::StatusCode"

CommandHandlerInterfaceOnlyClusters:
# List of clusters that are implemented entirely with
# CommandHandlerInterface and hence do not need generated command dispatch.
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums-check.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace app {
namespace Clusters {
{{#zcl_clusters}}
{{#zcl_enums}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
{
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
Expand All @@ -33,6 +34,7 @@ static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../n
return static_cast<EnumType>({{first_unused_enum_value mode="first_unused"}});
}
}
{{/unless}}
{{/zcl_enums}}

{{/zcl_clusters}}
Expand Down
7 changes: 7 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ enum class {{asType label}} : {{asUnderlyingZclType name}} {
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}},
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
// All received enum values that are not listed above will be mapped
// to kUnknownEnumValue. This is a helper enum value that should only
// be used by code to process how it handles receiving and unknown
// enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
// kUnknownEnumValue intentionally not defined. This enum is not used
// in a DataModel struct, likely because it is a part of a derivative
tehampson marked this conversation as resolved.
Show resolved Hide resolved
tehampson marked this conversation as resolved.
Show resolved Hide resolved
// cluster. As a result having kUnknownEnumValue in this enum is error
// prone, and was removed.
tehampson marked this conversation as resolved.
Show resolved Hide resolved
{{/unless}}
};
{{#if (isInConfigList label "WeakEnums")}}
#else // CHIP_USE_ENUM_CLASS_FOR_IM_ENUM
Expand Down
63 changes: 28 additions & 35 deletions src/controller/python/chip/clusters/Objects.py

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

Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ class {{asUpperCamelCase name}}(Cluster):
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}}
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
# All received enum values that are not listed above will be mapped
# to kUnknownEnumValue. This is a helper enum value that should only
# be used by code to process how it handles receiving and unknown
# enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
# kUnknownEnumValue intentionally not defined. This enum is not used
# in a DataModel struct, likely because it is a part of a derivative
# cluster. As a result having kUnknownEnumValue in this enum is error
# prone, and was removed.
tehampson marked this conversation as resolved.
Show resolved Hide resolved
{{/unless}}

{{#last}}
{{/last}}
Expand Down
3 changes: 3 additions & 0 deletions src/controller/python/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"templates/chip/helper.js",
"controller/python/templates/helper.js"
],
"resources": {
"config-data": "../../../../src/app/common/templates/config-data.yaml"
},
"override": "../../../../src/app/zap-templates/common/override.js",
"partials": [
{
Expand Down

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

Loading
Loading