From 20690330c2809c2c89076c989d51a3b43c673909 Mon Sep 17 00:00:00 2001 From: Bharat Raju Date: Mon, 10 Oct 2022 13:01:22 -0400 Subject: [PATCH] Matter Cleanup for Chip Tool Repo (#22762) * Switching templates to generic zap helpers and avoiding helpers which are language specific and hard coded. - The new helpers take the logic into the templates and can be used across different kinds of templates - There are generation changes to structs which have multiple clusters. These now generate CHIP_ERROR per cluster instead of using detail. Need to validate if that is ok. - updating the zap to point to the zap branch which has changes associated with this - Github: ZAP#679 * Updating the zap templates with the updated helpers. Simplifying an overly complicated zap template in the previous commit Github: ZAP#679 * Cleaning up a missed template change Gihub: ZAP#679 * regening after rebase Github: ZAP#679 * Updating the pointer to zap repo Github: ZAP#679 * Moving the handlebar template complexity into the helper: - Get rid of if_is_underlying_zcl_type_signed, if_is_float_or_double_data_type and as_underlying_zcl_type_size. Instead updating the functionality of asTypeMinValue and asTypeMaxValue into as_type_max_value and as_type_min_value - Cleaning up the zap templates reflect the above. - GIthub: ZAP#679 * Cleaning up typos Github: ZAP#679 * Updating zap submodule GIthub: ZAP#679 * updating the zap repo Github: ZAP#679 * bumping the pointer to zap repo Github:ZAP#679 * Updating the za[ repo Github: ZAP#679 * Reverting the formatting on these files Github: ZAP#679 * Updating the zap repo Gihub: ZAP#679 --- .../templates/ComplexArgumentParser-src.zapt | 8 ++++---- .../templates/ComplexArgumentParser.zapt | 8 ++++---- examples/chip-tool/templates/commands.zapt | 18 +++++++++--------- .../templates/logging/DataModelLogger-src.zapt | 6 +++--- .../templates/logging/DataModelLogger.zapt | 6 +++--- .../templates/tests/partials/test_cluster.zapt | 2 +- .../templates/commands.zapt | 14 +++++++------- .../templates/tests/partials/test_cluster.zapt | 2 +- third_party/zap/repo | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/examples/chip-tool/templates/ComplexArgumentParser-src.zapt b/examples/chip-tool/templates/ComplexArgumentParser-src.zapt index 24614f96f4768e..24b617ee1ae798 100644 --- a/examples/chip-tool/templates/ComplexArgumentParser-src.zapt +++ b/examples/chip-tool/templates/ComplexArgumentParser-src.zapt @@ -2,8 +2,8 @@ #include -{{#structs_with_cluster_name}} -CHIP_ERROR ComplexArgumentParser::Setup(const char * label, {{zapTypeToEncodableClusterObjectType name ns=clusterName}} & request, Json::Value & value) +{{#structs_with_clusters groupByStructName=1}} +CHIP_ERROR ComplexArgumentParser::Setup(const char * label, chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::Type & request, Json::Value & value) { VerifyOrReturnError(value.isObject(), CHIP_ERROR_INVALID_ARGUMENT); @@ -38,11 +38,11 @@ CHIP_ERROR ComplexArgumentParser::Setup(const char * label, {{zapTypeToEncodable return CHIP_NO_ERROR; } -void ComplexArgumentParser::Finalize({{zapTypeToEncodableClusterObjectType name ns=clusterName}} & request) +void ComplexArgumentParser::Finalize(chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::Type & request) { {{#zcl_struct_items}} ComplexArgumentParser::Finalize(request.{{asLowerCamelCase label}}); {{/zcl_struct_items}} } -{{/structs_with_cluster_name}} +{{/structs_with_clusters}} diff --git a/examples/chip-tool/templates/ComplexArgumentParser.zapt b/examples/chip-tool/templates/ComplexArgumentParser.zapt index 9ac2c7094c8cd0..e057f0462df0a4 100644 --- a/examples/chip-tool/templates/ComplexArgumentParser.zapt +++ b/examples/chip-tool/templates/ComplexArgumentParser.zapt @@ -5,8 +5,8 @@ #include #include -{{#structs_with_cluster_name}} -static CHIP_ERROR Setup(const char * label, {{zapTypeToEncodableClusterObjectType name ns=clusterName}} & request, Json::Value & value); +{{#structs_with_clusters groupByStructName=1}} +static CHIP_ERROR Setup(const char * label, chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::Type & request, Json::Value & value); -static void Finalize({{zapTypeToEncodableClusterObjectType name ns=clusterName}} & request); -{{/structs_with_cluster_name}} +static void Finalize(chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::Type & request); +{{/structs_with_clusters}} diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index afeaf8333a08c5..8c075485a02ef1 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -25,7 +25,7 @@ class {{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ClusterCommand { public: - {{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): ClusterCommand("{{asDelimitedCommand name}}", credsIssuerConfig){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}} + {{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(CredentialIssuerCommands * credsIssuerConfig): ClusterCommand("{{cleanse_label_as_kebab_case name}}", credsIssuerConfig){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}} { {{#zcl_command_arguments}} {{#if_chip_complex}} @@ -33,7 +33,7 @@ public: {{else if (isString type)}} AddArgument("{{asUpperCamelCase label}}", &mRequest.{{asLowerCamelCase label}}); {{else}} - AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mRequest.{{asLowerCamelCase label}}); + AddArgument("{{asUpperCamelCase label}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, &mRequest.{{asLowerCamelCase label}}); {{/if_chip_complex}} {{/zcl_command_arguments}} ClusterCommand::AddArguments(); @@ -89,7 +89,7 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIss // make_unique(Id, credsIssuerConfig), // {{#zcl_attributes_server}} - make_unique(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{! TODO: Remove after 1.0. See https://github.com/project-chip/connectedhomeip/issues/22341 }} {{#if (isStrEqual (asUpperCamelCase name) "ColorTemperatureMireds")}} make_unique(Id, "color-temperature", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // @@ -103,18 +103,18 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIss {{#zcl_attributes_server}} {{#if isWritable}} {{#if_chip_complex}} - make_unique>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{else if (isString type)}} - make_unique>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{else}} - make_unique>(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique>(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{/if_chip_complex}} {{/if}} {{/zcl_attributes_server}} make_unique(Id, credsIssuerConfig), // {{#zcl_attributes_server}} {{#if isReportable}} - make_unique(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{! TODO: Remove after 1.0. See https://github.com/project-chip/connectedhomeip/issues/22341 }} {{#if (isStrEqual (asUpperCamelCase name) "ColorTemperatureMireds")}} make_unique(Id, "color-temperature", Attributes::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // @@ -130,11 +130,11 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands, CredentialIss // make_unique(Id, credsIssuerConfig), // {{#zcl_events}} - make_unique(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{/zcl_events}} make_unique(Id, credsIssuerConfig), // {{#zcl_events}} - make_unique(Id, "{{asDelimitedCommand (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // + make_unique(Id, "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}", Events::{{asUpperCamelCase name}}::Id, credsIssuerConfig), // {{/zcl_events}} }; diff --git a/examples/chip-tool/templates/logging/DataModelLogger-src.zapt b/examples/chip-tool/templates/logging/DataModelLogger-src.zapt index 474169320f0c29..5bff45c9951f7d 100644 --- a/examples/chip-tool/templates/logging/DataModelLogger-src.zapt +++ b/examples/chip-tool/templates/logging/DataModelLogger-src.zapt @@ -4,8 +4,8 @@ using namespace chip::app::Clusters; -{{#structs_with_cluster_name}} -CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=clusterName isArgument=true}} value) +{{#structs_with_clusters groupByStructName=1}} +CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::DecodableType & value) { DataModelLogger::LogString(label, indent, "{"); {{#zcl_struct_items}} @@ -22,7 +22,7 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, {{zapTyp return CHIP_NO_ERROR; } -{{/structs_with_cluster_name}} +{{/structs_with_clusters}} {{#zcl_clusters}} {{#zcl_events}} diff --git a/examples/chip-tool/templates/logging/DataModelLogger.zapt b/examples/chip-tool/templates/logging/DataModelLogger.zapt index 468f26619d689d..5462c3df3dc229 100644 --- a/examples/chip-tool/templates/logging/DataModelLogger.zapt +++ b/examples/chip-tool/templates/logging/DataModelLogger.zapt @@ -3,9 +3,9 @@ #include #include -{{#structs_with_cluster_name}} -static CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=clusterName isArgument=true}} value); -{{/structs_with_cluster_name}} +{{#structs_with_clusters groupByStructName=1}} +static CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::DecodableType & value); +{{/structs_with_clusters}} {{#zcl_clusters}} {{#zcl_events}} diff --git a/examples/chip-tool/templates/tests/partials/test_cluster.zapt b/examples/chip-tool/templates/tests/partials/test_cluster.zapt index 79fa65337635b5..a968b9f1241839 100644 --- a/examples/chip-tool/templates/tests/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/tests/partials/test_cluster.zapt @@ -12,7 +12,7 @@ public: {{#if (isString type)}} AddArgument("{{name}}", &m{{asUpperCamelCase name}}); {{else}} - AddArgument("{{name}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &m{{asUpperCamelCase name}}); + AddArgument("{{name}}",{{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, &m{{asUpperCamelCase name}}); {{/if}} {{/chip_tests_config}} } diff --git a/examples/darwin-framework-tool/templates/commands.zapt b/examples/darwin-framework-tool/templates/commands.zapt index 881660109af940..31053445a66935 100644 --- a/examples/darwin-framework-tool/templates/commands.zapt +++ b/examples/darwin-framework-tool/templates/commands.zapt @@ -27,7 +27,7 @@ class {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}: public ClusterCommand { public: - {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}(): ClusterCommand("{{asDelimitedCommand name}}"){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}} + {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}(): ClusterCommand("{{cleanse_label_as_kebab_case name}}"){{#zcl_command_arguments}}{{#if_chip_complex}}, mComplex_{{asUpperCamelCase label}}(&mRequest.{{asLowerCamelCase label}}){{/if_chip_complex}}{{/zcl_command_arguments}} { {{#chip_cluster_command_arguments}} {{#if_chip_complex}} @@ -35,7 +35,7 @@ public: {{else if (isString type)}} AddArgument("{{asUpperCamelCase label}}", &mRequest.{{asLowerCamelCase label}}); {{else}} - AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mRequest.{{asLowerCamelCase label}}); + AddArgument("{{asUpperCamelCase label}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, &mRequest.{{asLowerCamelCase label}}); {{/if_chip_complex}} {{/chip_cluster_command_arguments}} ClusterCommand::AddArguments(); @@ -99,7 +99,7 @@ private: class Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ReadAttribute { public: - Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ReadAttribute("{{asDelimitedCommand (asUpperCamelCase name)}}") + Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ReadAttribute("{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}") { } @@ -143,15 +143,15 @@ public: class Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public WriteAttribute { public: - Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): WriteAttribute("{{asDelimitedCommand (asUpperCamelCase name)}}"){{#if_chip_complex}}, mComplex(&mValue){{/if_chip_complex}} + Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): WriteAttribute("{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}"){{#if_chip_complex}}, mComplex(&mValue){{/if_chip_complex}} { - AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}"); + AddArgument("attr-name", "{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}"); {{#if_chip_complex}} AddArgument("attr-value", &mComplex); {{else if (isString type)}} AddArgument("attr-value", &mValue); {{else}} - AddArgument("attr-value", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mValue); + AddArgument("attr-value", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, &mValue); {{/if_chip_complex}} WriteAttribute::AddArguments(); } @@ -206,7 +206,7 @@ private: class SubscribeAttribute{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public SubscribeAttribute { public: - SubscribeAttribute{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): SubscribeAttribute("{{asDelimitedCommand (asUpperCamelCase name)}}") + SubscribeAttribute{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): SubscribeAttribute("{{cleanse_label_as_kebab_case (asUpperCamelCase name)}}") { } diff --git a/examples/darwin-framework-tool/templates/tests/partials/test_cluster.zapt b/examples/darwin-framework-tool/templates/tests/partials/test_cluster.zapt index 81521fe79f07fa..ffed4b28869735 100644 --- a/examples/darwin-framework-tool/templates/tests/partials/test_cluster.zapt +++ b/examples/darwin-framework-tool/templates/tests/partials/test_cluster.zapt @@ -13,7 +13,7 @@ class {{filename}}: public TestCommandBridge {{#if (isString type)}} AddArgument("{{name}}", &m{{asUpperCamelCase name}}); {{else}} - AddArgument("{{name}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &m{{asUpperCamelCase name}}); + AddArgument("{{name}}", {{as_type_min_value type language='c++'}}, {{as_type_max_value type language='c++'}}, &m{{asUpperCamelCase name}}); {{/if}} {{/chip_tests_config}} } diff --git a/third_party/zap/repo b/third_party/zap/repo index d4ce2c13916f1b..8a3a89a5a936f4 160000 --- a/third_party/zap/repo +++ b/third_party/zap/repo @@ -1 +1 @@ -Subproject commit d4ce2c13916f1b1e066c6112dbee3e0dc5f5064f +Subproject commit 8a3a89a5a936f4c9dfd4518eda14ebf95177a7ad