Skip to content

Commit

Permalink
Make our renamed struct/event codegen more backwards compatible.
Browse files Browse the repository at this point in the history
When we just moved all the members to the super-class, it left the subclass in a
situation where none of its properties are available in the release where the
subclass itself is available.

This change restores those properties on the subclasses.

The @dynamic in implementations is needed to avoid compiler errors.
  • Loading branch information
bzbarsky-apple committed Jul 18, 2023
1 parent 1d22ffc commit 0c5bff3
Show file tree
Hide file tree
Showing 4 changed files with 701 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/darwin/Framework/CHIP/templates/MTRStructsObjc-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ NS_ASSUME_NONNULL_BEGIN
{{#*inline "oldNameImpl"}}
{{#if (isSupported cluster struct=structName)}}
@implementation MTR{{cluster}}Cluster{{structName}} : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}
{{#zcl_struct_items}}
{{#if (isSupported ../cluster struct=../structName structField=(asStructPropertyName label))}}
@dynamic {{asStructPropertyName label}};
{{/if}}
{{#if (hasOldName ../cluster struct=../structName structField=(asStructPropertyName label))}}
{{#if (isSupported ../cluster struct=../structName structField=(oldName ../cluster struct=../structName structField=(asStructPropertyName label)))}}
@dynamic {{oldName ../cluster struct=../structName structField=(asStructPropertyName label)}};
{{/if}}
{{/if}}
{{/zcl_struct_items}}
@end
{{/if}}
{{/inline}}
Expand Down Expand Up @@ -139,6 +149,16 @@ NS_ASSUME_NONNULL_BEGIN
{{#if (isSupported cluster event=eventName)}}

@implementation MTR{{cluster}}Cluster{{eventName}}Event : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event
{{#zcl_event_fields}}
{{#if (isSupported ../cluster event=../eventName eventField=(asStructPropertyName name))}}
@dynamic {{asStructPropertyName name}};
{{/if}}
{{#if (hasOldName ../cluster event=../eventName eventField=(asStructPropertyName name))}}
{{#if (isSupported ../cluster event=../eventName eventField=(oldName ../cluster event=../eventName eventField=(asStructPropertyName name)))}}
@dynamic {{oldName ../cluster event=../event eventField=(asStructPropertyName name)}};
{{/if}}
{{/if}}
{{/zcl_event_fields}}
@end
{{/if}}
{{/inline}}
Expand Down
8 changes: 5 additions & 3 deletions src/darwin/Framework/CHIP/templates/MTRStructsObjc.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
{{#if (isSupported (compatClusterNameRemapping parent.name) struct=structName)}}
{{availability (compatClusterNameRemapping parent.name) struct=structName deprecationMessage=(concat "Please use MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true))}}
@interface MTR{{compatClusterNameRemapping parent.name}}Cluster{{structName}} : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}
{{!TODO {{> interfaceDecl cluster=(compatClusterNameRemapping parent.name) struct=structName}}
{{> interfaceDecl cluster=(compatClusterNameRemapping parent.name) struct=structName}}
@end

{{/if}}
{{/inline}}
{{! Takes the old name of the struct, if any, as oldStructName. }}
Expand Down Expand Up @@ -66,15 +67,16 @@ NS_ASSUME_NONNULL_BEGIN
@interface MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event : NSObject <NSCopying>
{{> interfaceDecl cluster=(asUpperCamelCase parent.name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true)}}
@end

{{/if}}
{{! Takes the name of the event to use as eventName. }}
{{#*inline "oldNameDecl"}}
{{#if (isSupported (compatClusterNameRemapping parent.name) event=eventName)}}

{{availability (compatClusterNameRemapping parent.name) event=eventName deprecationMessage=(concat "Please use MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true) "Event")}}
@interface MTR{{compatClusterNameRemapping parent.name}}Cluster{{eventName}}Event : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event
{{!TODO {{> interfaceDecl cluster=(compatClusterNameRemapping parent.name) event=eventName}}
{{> interfaceDecl cluster=(compatClusterNameRemapping parent.name) event=eventName}}
@end

{{/if}}
{{/inline}}
{{! Takes the old name of the event, if any, as oldEventName. }}
Expand Down
Loading

0 comments on commit 0c5bff3

Please sign in to comment.