Skip to content

Commit

Permalink
Go back to not generating per-cluster types for alias structs for now. (
Browse files Browse the repository at this point in the history
#26958)

This is ending up not working quite right because when structs have struct-typed
(or list-of-struct-typed) fields, the type expectations people have get messed
up.  They're still messed up even after this PR, but at least we're not sort of
promising they won't be messed up.

This reverts #26763 and #26495.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Feb 22, 2024
1 parent 95db04f commit 1479160
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 381 deletions.
8 changes: 8 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

#include <commands/clusters/ComplexArgument.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_impl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_parser_impl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}
8 changes: 8 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
#include <lib/core/CHIPError.h>
#include <app-common/zap-generated/cluster-objects.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_decl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_parser_decl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}
8 changes: 8 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

using namespace chip::app::Clusters;

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_impl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_logger_impl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}

Expand Down
8 changes: 8 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
#include <lib/core/CHIPError.h>
#include <app-common/zap-generated/cluster-objects.h>

{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_decl namespace="detail"}}
{{/if}}
{{/zcl_structs}}

{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_logger_decl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_clusters}}

Expand Down
35 changes: 1 addition & 34 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,7 @@ namespace {{asUpperCamelCase name}} {
namespace Structs {
{{/first}}
{{#if has_more_than_one_cluster}}
namespace {{asUpperCamelCase name}} {

using Fields = Clusters::detail::Structs::{{asUpperCamelCase name}}::Fields;

// This is a struct type shared across multiple clusters. Create a type-safe
// declaration in this cluster namespace (so not just pulling in the shared
// implementation via "using", but make sure we can initialize our
// Type/DecodableType from the generic Type/DecodableType as needed.
struct Type : public Clusters::detail::Structs::{{asUpperCamelCase name}}::Type
{
private:
using Super = Clusters::detail::Structs::{{asUpperCamelCase name}}::Type;
public:
constexpr Type() = default;
constexpr Type(const Super & arg) : Super(arg) {}
constexpr Type(Super && arg) : Super(std::move(arg)) {}
};

{{#if struct_contains_array}}
struct DecodableType : public Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType
{
private:
using Super = Clusters::detail::Structs::{{asUpperCamelCase name}}::DecodableType;
public:
DecodableType() = default;
DecodableType(const Super & arg) : Super(arg) {}
DecodableType(Super && arg) : Super(std::move(arg)) {}
};
{{else}}
using DecodableType = Type;
{{/if}}

} // namespace {{asUpperCamelCase name}}

namespace {{asUpperCamelCase name}} = Clusters::detail::Structs::{{asUpperCamelCase name}};
{{else}}
{{> cluster_objects_struct header=true}}
{{/if}}
Expand Down

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

Loading

0 comments on commit 1479160

Please sign in to comment.