From 2217877820a2f72183e2561bde8c10e827f9ab50 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 3 Jan 2023 09:03:49 -0500 Subject: [PATCH] Implement support for renaming fields in Darwin codegen. (#24154) * Implement support for renaming fields in Darwin codegen. This adds support for renaming struct, event, and command fields. Also fixes a bug that was introduced where the getter for newPosition was mis-named. * Add support for renaming structs and events too. * Add support for renaming enums and bitmaps as well. * Add support for renaming enum and bitmap values as well. --- .github/workflows/zap_regeneration.yaml | 2 +- .github/workflows/zap_templates.yaml | 2 +- .../CHIP/templates/MTRBaseClusters.zapt | 62 +++++++++++++---- .../templates/MTRCommandPayloadsObjc-src.zapt | 33 ++++++++- .../templates/MTRCommandPayloadsObjc.zapt | 44 ++++++++++-- .../CHIP/templates/MTRStructsObjc-src.zapt | 66 +++++++++++------- .../CHIP/templates/MTRStructsObjc.zapt | 68 +++++++++++-------- .../CHIP/templates/availability.yaml | 8 +++ .../partials/renamed_struct_field_impl.zapt | 9 +++ .../templates/partials/struct_field_decl.zapt | 3 + .../Framework/CHIP/templates/templates.json | 8 +++ .../CHIP/zap-generated/MTRStructsObjc.h | 10 +-- .../CHIP/zap-generated/MTRStructsObjc.mm | 33 +-------- 13 files changed, 236 insertions(+), 112 deletions(-) create mode 100644 src/darwin/Framework/CHIP/templates/partials/renamed_struct_field_impl.zapt create mode 100644 src/darwin/Framework/CHIP/templates/partials/struct_field_decl.zapt diff --git a/.github/workflows/zap_regeneration.yaml b/.github/workflows/zap_regeneration.yaml index 7db5b259340810..19960d000c4fcb 100644 --- a/.github/workflows/zap_regeneration.yaml +++ b/.github/workflows/zap_regeneration.yaml @@ -28,7 +28,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: connectedhomeip/chip-build:0.6.24 + image: connectedhomeip/chip-build:0.6.25 defaults: run: shell: sh diff --git a/.github/workflows/zap_templates.yaml b/.github/workflows/zap_templates.yaml index d59598bff10781..e35ad0d7495d16 100644 --- a/.github/workflows/zap_templates.yaml +++ b/.github/workflows/zap_templates.yaml @@ -29,7 +29,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: connectedhomeip/chip-build:0.6.24 + image: connectedhomeip/chip-build:0.6.25 defaults: run: shell: sh diff --git a/src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt b/src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt index 930091b1d1f527..433c778543c4dd 100644 --- a/src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRBaseClusters.zapt @@ -82,32 +82,70 @@ subscriptionEstablished:(MTRSubscriptionEstablishedHandler _Nullable)subscriptio {{#zcl_clusters}} {{#zcl_enums}} {{#*inline "enumDef"}} -typedef NS_ENUM({{asUnderlyingZclType name}}, {{objCEnumName clusterName label}}) { +typedef NS_ENUM({{asUnderlyingZclType name}}, {{objCEnumName clusterName enumName}}) { {{#zcl_enum_items}} - {{objCEnumName ../clusterName ../label}}{{objCEnumItemLabel label}} {{availability ../clusterName enum=(asUpperCamelCase ../label preserveAcronyms=true) enumValue=(objCEnumItemLabel label) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex value 2}}, + {{objCEnumName ../clusterName ../enumName}}{{objCEnumItemLabel label}} {{availability ../clusterName enum=../enumName enumValue=(objCEnumItemLabel label) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex value 2}}, + {{#*inline "oldNameItemDecl"}} + {{#if oldItemName}} + {{objCEnumName ../clusterName ../enumName}}{{objCEnumItemLabel oldItemName}} {{availability ../clusterName enum=../enumName enumValue=oldItemName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex value 2}}, + {{/if}} + {{/inline}} + {{> oldNameItemDecl oldItemName=(oldName ../clusterName enum=../enumName enumValue=(objCEnumItemLabel label))}} {{/zcl_enum_items}} } {{/inline}} -{{> enumDef name=name clusterName=(asUpperCamelCase ../name preserveAcronyms=true) label=label}} {{availability (asUpperCamelCase ../name preserveAcronyms=true) enum=(asUpperCamelCase label preserveAcronyms=true)}}; -{{#unless (isStrEqual (asUpperCamelCase ../name preserveAcronyms=true) (compatClusterNameRemapping ../name))}} +{{> enumDef name=name clusterName=(asUpperCamelCase ../name preserveAcronyms=true) enumName=(asUpperCamelCase label preserveAcronyms=true)}} {{availability (asUpperCamelCase ../name preserveAcronyms=true) enum=(asUpperCamelCase label preserveAcronyms=true)}}; +{{! Takes the name of the enum to use as enumName. }} +{{#*inline "oldNameDecl"}} -{{> enumDef name=name clusterName=(compatClusterNameRemapping ../name) label=label}} {{availability (compatClusterNameRemapping ../name) enum=(asUpperCamelCase label preserveAcronyms=true) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../name preserveAcronyms=true) label))}}; -{{/unless}} +{{> enumDef name=name clusterName=(compatClusterNameRemapping ../name) enumName=enumName}} {{availability (compatClusterNameRemapping ../name) enum=enumName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../name preserveAcronyms=true) label))}}; +{{/inline}} +{{! Takes the old name of the enum, if any, as oldEnumName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldEnumName + (hasOldName (asUpperCamelCase ../name preserveAcronyms=true)))}} +{{#if oldEnumName}} +{{> oldNameDecl enumName=oldEnumName}} +{{else}} +{{> oldNameDecl enumName=(asUpperCamelCase label preserveAcronyms=true)}} +{{/if}} +{{/if}} +{{/inline}} +{{> oldNameCheck oldEnumName=(oldName (asUpperCamelCase ../name preserveAcronyms=true) enum=(asUpperCamelCase label preserveAcronyms=true))}} {{/zcl_enums}} {{#zcl_bitmaps}} {{#*inline "bitmapDef"}} -typedef NS_OPTIONS({{asUnderlyingZclType name}}, {{objCEnumName clusterName label}}) { +typedef NS_OPTIONS({{asUnderlyingZclType name}}, {{objCEnumName clusterName bitmapName}}) { {{#zcl_bitmap_items}} - {{objCEnumName ../clusterName ../label}}{{objCEnumItemLabel label}} {{availability ../clusterName bitmap=(asUpperCamelCase ../label preserveAcronyms=true) bitmapValue=(objCEnumItemLabel label) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex mask}}, + {{objCEnumName ../clusterName ../bitmapName}}{{objCEnumItemLabel label}} {{availability ../clusterName bitmap=../bitmapName bitmapValue=(objCEnumItemLabel label) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex mask}}, + {{#*inline "oldNameItemDecl"}} + {{#if oldItemName}} + {{objCEnumName ../clusterName ../bitmapName}}{{objCEnumItemLabel oldItemName}} {{availability ../clusterName bitmap=../enumName bitmapValue=oldItemName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../../name preserveAcronyms=true) ../label) (objCEnumItemLabel label))}} = {{asHex value 2}}, + {{/if}} + {{/inline}} + {{> oldNameItemDecl oldItemName=(oldName ../clusterName bitmap=../bitmapName bitmapValue=(objCEnumItemLabel label))}} {{/zcl_bitmap_items}} } {{/inline}} -{{> bitmapDef name=name clusterName=(asUpperCamelCase ../name preserveAcronyms=true) label=label}} {{availability (asUpperCamelCase ../name preserveAcronyms=true) bitmap=(asUpperCamelCase label preserveAcronyms=true)}}; -{{#unless (isStrEqual (asUpperCamelCase ../name preserveAcronyms=true) (compatClusterNameRemapping ../name))}} +{{> bitmapDef name=name clusterName=(asUpperCamelCase ../name preserveAcronyms=true) bitmapName=(asUpperCamelCase label preserveAcronyms=true)}} {{availability (asUpperCamelCase ../name preserveAcronyms=true) bitmap=(asUpperCamelCase label preserveAcronyms=true)}}; +{{! Takes the name of the bitmap to use as bitmapName. }} +{{#*inline "oldNameDecl"}} -{{> bitmapDef name=name clusterName=(compatClusterNameRemapping ../name) label=label}} {{availability (compatClusterNameRemapping ../name) bitmap=(asUpperCamelCase label preserveAcronyms=true) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../name preserveAcronyms=true) label))}}; -{{/unless}} +{{> bitmapDef name=name clusterName=(compatClusterNameRemapping ../name) bitmapName=bitmapName}} {{availability (compatClusterNameRemapping ../name) bitmap=bitmapName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../name preserveAcronyms=true) label))}}; +{{/inline}} +{{! Takes the old name of the bitmap, if any, as oldBitmapName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldBitmapName + (hasOldName (asUpperCamelCase ../name preserveAcronyms=true)))}} +{{#if oldBitmapName}} +{{> oldNameDecl bitmapName=oldBitmapName}} +{{else}} +{{> oldNameDecl bitmapName=(asUpperCamelCase label preserveAcronyms=true)}} +{{/if}} +{{/if}} +{{/inline}} +{{> oldNameCheck oldBitmapName=(oldName (asUpperCamelCase ../name preserveAcronyms=true) bitmap=(asUpperCamelCase label preserveAcronyms=true))}} {{/zcl_bitmaps}} diff --git a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt index a52a37ccbec471..521a1545088c8a 100644 --- a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc-src.zapt @@ -44,6 +44,13 @@ NS_ASSUME_NONNULL_BEGIN NSString *descriptionString = [NSString stringWithFormat:@"<%@: {{#zcl_command_arguments}}{{asStructPropertyName label}}:%@; {{/zcl_command_arguments}}>", NSStringFromClass([self class]) {{#zcl_command_arguments}},{{#if isArray}}_{{asStructPropertyName label}}{{else if (isOctetString type)}}[_{{asStructPropertyName label}} base64EncodedStringWithOptions:0]{{else}}_{{asStructPropertyName label}}{{/if}}{{/zcl_command_arguments}}]; return descriptionString; } +{{#zcl_command_arguments}} +{{#if (and includeRenamedProperties + (hasOldName ../cluster command=../command commandField=(asStructPropertyName label)))}} + +{{> renamed_struct_field_impl cluster=parent.parent.name type=type newName=label oldName=(oldName ../cluster command=../command commandField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_command_arguments}} @end {{/unless}} @@ -51,19 +58,41 @@ NS_ASSUME_NONNULL_BEGIN {{#*inline "oldNameImpl"}} @implementation MTR{{cluster}}Cluster{{command}}Params +{{#zcl_command_arguments}} +{{#if (hasOldName (asUpperCamelCase parent.parent.name preserveAcronyms=true) command=(asUpperCamelCase parent.name preserveAcronyms=true) commandField=(asStructPropertyName label))}} + +{{> renamed_struct_field_impl cluster=parent.parent.name type=type newName=label oldName=(oldName (asUpperCamelCase parent.parent.name preserveAcronyms=true) command=(asUpperCamelCase parent.name preserveAcronyms=true) commandField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_command_arguments}} @end {{/inline}} {{#if (not (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true)))}} {{> completeImpl cluster=(asUpperCamelCase parent.name preserveAcronyms=true) - command=(asUpperCamelCase name preserveAcronyms=true)}} + command=(asUpperCamelCase name preserveAcronyms=true) + includeRenamedProperties=false}} {{#if (or (not (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))) (not (isStrEqual (asUpperCamelCase name preserveAcronyms=true) (compatCommandNameRemapping parent.name name))))}} {{> oldNameImpl cluster=(compatClusterNameRemapping parent.name) command=(compatCommandNameRemapping parent.name name)}} +{{else if (hasRenamedFields (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}} +{{#*inline "deprecatedImpl"}} + +@implementation MTR{{cluster}}Cluster{{command}}Params (Deprecated) +{{#zcl_command_arguments}} +{{#if (hasOldName ../cluster command=../command commandField=(asStructPropertyName label))}} + +{{> renamed_struct_field_impl cluster=parent.parent.name type=type newName=label oldName=(oldName ../cluster command=../command commandField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_command_arguments}} +@end +{{/inline}} +{{> deprecatedImpl cluster=(asUpperCamelCase parent.name preserveAcronyms=true) + command=(asUpperCamelCase name preserveAcronyms=true)}} {{/if}} {{else}} {{> completeImpl cluster=(compatClusterNameRemapping parent.name) - command=(compatCommandNameRemapping parent.name name)}} + command=(compatCommandNameRemapping parent.name name) + includeRenamedProperties=true}} {{/if}} {{/zcl_commands}} {{/zcl_clusters}} diff --git a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc.zapt b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc.zapt index 1143ec4e55b19c..5951653fec9fc7 100644 --- a/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRCommandPayloadsObjc.zapt @@ -14,9 +14,15 @@ NS_ASSUME_NONNULL_BEGIN @interface MTR{{cluster}}Cluster{{command}}Params : NSObject {{#zcl_command_arguments}} -{{! Override the getter name because some of our properties start with things - like "new" or "init" }} -@property (nonatomic, copy{{#unless (isStrEqual (asGetterName label) (asStructPropertyName label))}}, getter={{asGetterName label}}{{/unless}}) {{asObjectiveCType type parent.parent.name}} {{asStructPropertyName label}} {{availability ../cluster command=../command commandField=(asStructPropertyName label)}}; +{{> struct_field_decl cluster=parent.parent.name type=type label=label}} {{availability ../cluster command=../command commandField=(asStructPropertyName label)}}; +{{#*inline "oldNameFieldDecl"}} + +{{> struct_field_decl cluster=parent.parent.name type=type label=commandField}} {{availability ../cluster command=../command commandField=commandField deprecationMessage=(concat "Please use " (asStructPropertyName label))}}; +{{/inline}} +{{#if (and includeRenamedProperties + (hasOldName ../cluster command=../command commandField=(asStructPropertyName label)))}} +{{> oldNameFieldDecl commandField=(oldName ../cluster command=../command commandField=(asStructPropertyName label))}} +{{/if}} {{/zcl_command_arguments}} {{#if (isStrEqual source "client")}} /** @@ -60,20 +66,48 @@ NS_ASSUME_NONNULL_BEGIN {{availability cluster command=command deprecationMessage=(concat "Please use MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true) "Params")}} @interface MTR{{cluster}}Cluster{{command}}Params : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name}}Params +{{#zcl_command_arguments}} +{{#*inline "oldNameFieldDecl"}} + +{{> struct_field_decl cluster=parent.parent.name type=type label=commandField}} {{availability ../cluster command=../command commandField=commandField deprecationMessage=(concat "Please use " (asStructPropertyName label))}}; +{{/inline}} +{{#if (hasOldName (asUpperCamelCase parent.parent.name preserveAcronyms=true) command=(asUpperCamelCase parent.name preserveAcronyms=true) commandField=(asStructPropertyName label))}} +{{> oldNameFieldDecl commandField=(oldName (asUpperCamelCase parent.parent.name preserveAcronyms=true) command=(asUpperCamelCase parent.name preserveAcronyms=true) commandField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_command_arguments}} @end {{/inline}} {{#if (not (wasRemoved (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true)))}} {{> completeDecl cluster=(asUpperCamelCase parent.name preserveAcronyms=true) - command=(asUpperCamelCase name preserveAcronyms=true)}} + command=(asUpperCamelCase name preserveAcronyms=true) + includeRenamedProperties=false}} {{#if (or (not (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))) (not (isStrEqual (asUpperCamelCase name preserveAcronyms=true) (compatCommandNameRemapping parent.name name))))}} {{> oldNameDecl cluster=(compatClusterNameRemapping parent.name) command=(compatCommandNameRemapping parent.name name)}} +{{else if (hasRenamedFields (asUpperCamelCase parent.name preserveAcronyms=true) command=(asUpperCamelCase name preserveAcronyms=true))}} +{{#*inline "deprecatedDecl"}} + +@interface MTR{{cluster}}Cluster{{command}}Params (Deprecated) +{{#zcl_command_arguments}} +{{#*inline "oldNameFieldDecl"}} + +{{> struct_field_decl cluster=parent.parent.name type=type label=commandField}} {{availability ../cluster command=../command commandField=commandField deprecationMessage=(concat "Please use " (asStructPropertyName label))}}; +{{/inline}} +{{#if (hasOldName ../cluster command=../command commandField=(asStructPropertyName label))}} +{{> oldNameFieldDecl commandField=(oldName ../cluster command=../command commandField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_command_arguments}} +@end +{{/inline}} +{{> deprecatedDecl cluster=(asUpperCamelCase parent.name preserveAcronyms=true) + command=(asUpperCamelCase name preserveAcronyms=true)}} {{/if}} {{else}} {{> completeDecl cluster=(compatClusterNameRemapping parent.name) - command=(compatCommandNameRemapping parent.name name)}} + command=(compatCommandNameRemapping parent.name name) + includeRenamedProperties=true}} {{/if}} {{/zcl_commands}} {{/zcl_clusters}} diff --git a/src/darwin/Framework/CHIP/templates/MTRStructsObjc-src.zapt b/src/darwin/Framework/CHIP/templates/MTRStructsObjc-src.zapt index 625859d94b92dd..37c4f2af35a1c5 100644 --- a/src/darwin/Framework/CHIP/templates/MTRStructsObjc-src.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRStructsObjc-src.zapt @@ -34,23 +34,35 @@ NS_ASSUME_NONNULL_BEGIN NSString *descriptionString = [NSString stringWithFormat:@"<%@: {{#zcl_struct_items}}{{asStructPropertyName label}}:%@; {{/zcl_struct_items}}>", NSStringFromClass([self class]){{#zcl_struct_items}},{{#if isArray}}_{{asStructPropertyName label}}{{else if (isOctetString type)}}[_{{asStructPropertyName label}} base64EncodedStringWithOptions:0]{{else}}_{{asStructPropertyName label}}{{/if}}{{/zcl_struct_items}}]; return descriptionString; } +{{#zcl_struct_items}} +{{#if (hasOldName (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(asStructPropertyName label))}} + +{{> renamed_struct_field_impl cluster=../../name type=type newName=label oldName=(oldName (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(asStructPropertyName label))}} +{{/if}} +{{/zcl_struct_items}} @end {{/inline}} {{> interfaceImpl interfaceName=(concat "MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true))}} -{{!Backwards compat for now: Add a DeviceType thing that is API-compatible with DeviceTypeStruct. }} -{{#if (isStrEqual (asUpperCamelCase parent.name) "Descriptor")}} -{{#if (isStrEqual (asUpperCamelCase name) "DeviceTypeStruct")}} -{{> interfaceImpl interfaceName="MTRDescriptorClusterDeviceType"}} -{{/if}} -{{else}} -{{#unless (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))}} -@implementation MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}} : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}} +{{! Takes the name of the struct to use as structName. }} +{{#*inline "oldNameImpl"}} +@implementation MTR{{compatClusterNameRemapping parent.name}}Cluster{{structName}} : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}} @end -{{/unless}} +{{/inline}} +{{! Takes the old name of the struct, if any, as oldStructName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldStructName + (hasOldName (asUpperCamelCase parent.name preserveAcronyms=true)))}} +{{#if oldStructName}} +{{> oldNameImpl structName=oldStructName}} +{{else}} +{{> oldNameImpl structName=(asUpperCamelCase name preserveAcronyms=true)}} +{{/if}} {{/if}} +{{/inline}} +{{> oldNameCheck oldStructName=(oldName (asUpperCamelCase parent.name preserveAcronyms=true) struct=(asUpperCamelCase name preserveAcronyms=true))}} {{/zcl_structs}} @@ -83,27 +95,31 @@ NS_ASSUME_NONNULL_BEGIN return descriptionString; } -{{#if (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) "Switch")}} -{{#if (isStrEqual (asUpperCamelCase name preserveAcronyms=true) "MultiPressComplete")}} -{{! Workaround for the name being mis-spelled in XML previously }} -- (void)setNewPosition:(NSNumber * _Nonnull)newPosition -{ - self.previousPosition = newPosition; -} - -- (NSNumber * _Nonnull)newPosition -{ - return self.previousPosition; -} +{{#zcl_event_fields}} +{{#if (hasOldName (asUpperCamelCase ../parent.name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name))}} +{{> renamed_struct_field_impl cluster=../parent.name type=type newName=name oldName=(oldName (asUpperCamelCase ../parent.name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name))}} {{/if}} -{{/if}} +{{/zcl_event_fields}} @end -{{#unless (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))}} +{{! Takes the name of the event to use as eventName. }} +{{#*inline "oldNameDecl"}} -@implementation MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}}Event : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event +@implementation MTR{{compatClusterNameRemapping parent.name}}Cluster{{eventName}}Event : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event @end -{{/unless}} +{{/inline}} +{{! Takes the old name of the event, if any, as oldEventName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldEventName + (hasOldName (asUpperCamelCase parent.name preserveAcronyms=true)))}} +{{#if oldEventName}} +{{> oldNameDecl eventName=oldEventName}} +{{else}} +{{> oldNameDecl eventName=(asUpperCamelCase name preserveAcronyms=true)}} +{{/if}} +{{/if}} +{{/inline}} +{{> oldNameCheck oldEventName=(oldName (asUpperCamelCase parent.name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true))}} {{/zcl_events}} diff --git a/src/darwin/Framework/CHIP/templates/MTRStructsObjc.zapt b/src/darwin/Framework/CHIP/templates/MTRStructsObjc.zapt index 4da179e81cf011..81a67ad8b972b7 100644 --- a/src/darwin/Framework/CHIP/templates/MTRStructsObjc.zapt +++ b/src/darwin/Framework/CHIP/templates/MTRStructsObjc.zapt @@ -7,55 +7,67 @@ NS_ASSUME_NONNULL_BEGIN {{#zcl_clusters}} {{#zcl_structs}} {{#*inline "interfaceDecl"}} -{{! Override the getter name because some of our properties start with things - like "new" or "init" }} {{#zcl_struct_items}} -@property (nonatomic, copy{{#unless (isStrEqual (asGetterName label) (asStructPropertyName label))}}, getter={{asGetterName label}}{{/unless}}) {{asObjectiveCType type parent.parent.name}} {{asStructPropertyName label}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) struct=../struct structField=(asStructPropertyName label) deprecationMessage=(concat "Please use MTR" (asUpperCamelCase ../../name preserveAcronyms=true) "Cluster" (asUpperCamelCase ../name preserveAcronyms=true))}}; +{{> struct_field_decl cluster=parent.parent.name type=type label=label}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) struct=../struct structField=(asStructPropertyName label) deprecationMessage=(concat "Please use MTR" (asUpperCamelCase ../../name preserveAcronyms=true) "Cluster" (asUpperCamelCase ../name preserveAcronyms=true))}}; +{{#if (hasOldName (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(asStructPropertyName label))}} +{{> struct_field_decl cluster=../../name type=type label=(oldName (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(asStructPropertyName label))}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(oldName (asUpperCamelCase ../../name preserveAcronyms=true) struct=(asUpperCamelCase ../name preserveAcronyms=true) structField=(asStructPropertyName name)) deprecationMessage=(concat "Please use " (asStructPropertyName name))}}; +{{/if}} {{/zcl_struct_items}} {{/inline}} -{{availability (asUpperCamelCase parent.name preserveAcronyms=true) struct=(asUpperCamelCase name preserveAcronyms=true)}} +{{availability (asUpperCamelCase parent.name preserveAcronyms=true) struct=(asUpperCamelCase name preserveAcronyms=true) deprecationMessage="This struct is unused and will be removed"}} @interface MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}} : NSObject {{> interfaceDecl struct=(asUpperCamelCase name preserveAcronyms=true)}} @end -{{!Backwards compat for now: Add a DeviceType thing that is API-compatible with DeviceTypeStruct. }} -{{#if (isStrEqual (asUpperCamelCase parent.name) "Descriptor")}} -{{#if (isStrEqual (asUpperCamelCase name) "DeviceTypeStruct")}} -{{availability (asUpperCamelCase parent.name preserveAcronyms=true) struct="DeviceType" deprecationMessage="Please use MTRDescriptorClusterDeviceTypeStruct"}} -@interface MTRDescriptorClusterDeviceType : NSObject -{{> interfaceDecl struct="DeviceType"}} +{{! Takes the name of the struct to use as structName. }} +{{#*inline "oldNameDecl"}} +{{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}} @end -{{/if}} +{{/inline}} +{{! Takes the old name of the struct, if any, as oldStructName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldStructName + (hasOldName (asUpperCamelCase parent.name preserveAcronyms=true)))}} +{{#if oldStructName}} +{{> oldNameDecl structName=oldStructName}} {{else}} -{{#unless (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))}} -{{availability (compatClusterNameRemapping parent.name) struct=(asUpperCamelCase name) deprecationMessage=(concat "Please use MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true))}} -@interface MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}} : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name}} -@end -{{/unless}} +{{> oldNameDecl structName=(asUpperCamelCase name preserveAcronyms=true)}} {{/if}} +{{/if}} +{{/inline}} +{{> oldNameCheck oldStructName=(oldName (asUpperCamelCase parent.name preserveAcronyms=true) struct=(asUpperCamelCase name preserveAcronyms=true))}} {{/zcl_structs}} {{#zcl_events}} {{availability (asUpperCamelCase parent.name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true)}} @interface MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event : NSObject {{#zcl_event_fields}} -@property (nonatomic, copy{{#unless (isStrEqual (asGetterName name) (asStructPropertyName name))}}, getter={{asGetterName name}}{{/unless}}) {{asObjectiveCType type parent.parent.name}} {{asStructPropertyName name}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name)}}; -{{#if (isStrEqual (asUpperCamelCase ../parent.name preserveAcronyms=true) "Switch")}} -{{#if (isStrEqual (asUpperCamelCase ../name preserveAcronyms=true) "MultiPressComplete")}} -{{#if (isStrEqual (asStructPropertyName name) "previousPosition")}} -{{! Workaround for the name being mis-spelled in XML previously }} -@property (nonatomic, copy) NSNumber * _Nonnull newPosition {{availability (asUpperCamelCase ../../name preserveAcronyms=true) event=(asUpperCamelCase ../name) eventField="newPosition" deprecationMessage="Please use previousPosition"}}; -{{/if}} -{{/if}} +{{> struct_field_decl cluster=parent.parent.name type=type label=name}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name)}}; +{{#if (hasOldName (asUpperCamelCase ../parent.name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name))}} +{{> struct_field_decl cluster=parent.parent.name type=type label=(oldName (asUpperCamelCase ../parent.name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name))}} {{availability (asUpperCamelCase ../../name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(oldName (asUpperCamelCase ../parent.name preserveAcronyms=true) event=(asUpperCamelCase ../name preserveAcronyms=true) eventField=(asStructPropertyName name)) deprecationMessage=(concat "Please use " (asStructPropertyName name))}}; {{/if}} {{/zcl_event_fields}} @end -{{#unless (isStrEqual (asUpperCamelCase parent.name preserveAcronyms=true) (compatClusterNameRemapping parent.name))}} +{{! Takes the name of the event to use as eventName. }} +{{#*inline "oldNameDecl"}} -{{availability (compatClusterNameRemapping parent.name) event=(asUpperCamelCase name) deprecationMessage=(concat "Please use MTR" (asUpperCamelCase parent.name preserveAcronyms=true) "Cluster" (asUpperCamelCase name preserveAcronyms=true) "Event")}} -@interface MTR{{compatClusterNameRemapping parent.name}}Cluster{{asUpperCamelCase name}}Event : MTR{{asUpperCamelCase parent.name preserveAcronyms=true}}Cluster{{asUpperCamelCase name preserveAcronyms=true}}Event +{{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 @end -{{/unless}} +{{/inline}} +{{! Takes the old name of the event, if any, as oldEventName. }} +{{#*inline "oldNameCheck"}} +{{#if (or oldEventName + (hasOldName (asUpperCamelCase parent.name preserveAcronyms=true)))}} +{{#if oldEventName}} +{{> oldNameDecl eventName=oldEventName}} +{{else}} +{{> oldNameDecl eventName=(asUpperCamelCase name preserveAcronyms=true)}} +{{/if}} +{{/if}} +{{/inline}} +{{> oldNameCheck oldEventName=(oldName (asUpperCamelCase parent.name preserveAcronyms=true) event=(asUpperCamelCase name preserveAcronyms=true))}} {{/zcl_events}} diff --git a/src/darwin/Framework/CHIP/templates/availability.yaml b/src/darwin/Framework/CHIP/templates/availability.yaml index 003b30f58a77e4..e424fccb035c27 100644 --- a/src/darwin/Framework/CHIP/templates/availability.yaml +++ b/src/darwin/Framework/CHIP/templates/availability.yaml @@ -4542,6 +4542,10 @@ attributes: Descriptor: - DeviceTypeList + renames: + structs: + Descriptor: + DeviceTypeStruct: DeviceType - release: "First major API revamp" versions: "future" @@ -5179,3 +5183,7 @@ PIROccupiedToUnoccupiedDelay: PirOccupiedToUnoccupiedDelay PIRUnoccupiedToOccupiedDelay: PirUnoccupiedToOccupiedDelay PIRUnoccupiedToOccupiedThreshold: PirUnoccupiedToOccupiedThreshold + event fields: + Switch: + MultiPressComplete: + previousPosition: newPosition diff --git a/src/darwin/Framework/CHIP/templates/partials/renamed_struct_field_impl.zapt b/src/darwin/Framework/CHIP/templates/partials/renamed_struct_field_impl.zapt new file mode 100644 index 00000000000000..2bd52e82f6701b --- /dev/null +++ b/src/darwin/Framework/CHIP/templates/partials/renamed_struct_field_impl.zapt @@ -0,0 +1,9 @@ +- (void)set{{asUpperCamelCase oldName}}:({{asObjectiveCType type cluster}}){{asStructPropertyName oldName}} +{ + self.{{asStructPropertyName newName}} = {{asStructPropertyName oldName}}; +} + +- ({{asObjectiveCType type cluster}}){{asGetterName oldName}} +{ + return self.{{asStructPropertyName newName}}; +} diff --git a/src/darwin/Framework/CHIP/templates/partials/struct_field_decl.zapt b/src/darwin/Framework/CHIP/templates/partials/struct_field_decl.zapt new file mode 100644 index 00000000000000..c5e398facaaf35 --- /dev/null +++ b/src/darwin/Framework/CHIP/templates/partials/struct_field_decl.zapt @@ -0,0 +1,3 @@ +{{! Override the getter name because some of our properties start with things + like "new" or "init" }} +@property (nonatomic, copy{{#unless (isStrEqual (asGetterName label) (asStructPropertyName label))}}, getter={{asGetterName label}}{{/unless}}) {{asObjectiveCType type cluster}} {{asStructPropertyName label}} {{! Caller provides availability~}} diff --git a/src/darwin/Framework/CHIP/templates/templates.json b/src/darwin/Framework/CHIP/templates/templates.json index 819b0b55022539..6561d17ee5c715 100644 --- a/src/darwin/Framework/CHIP/templates/templates.json +++ b/src/darwin/Framework/CHIP/templates/templates.json @@ -42,6 +42,14 @@ { "name": "attribute_data_callback_name", "path": "partials/attribute_data_callback_name.zapt" + }, + { + "name": "struct_field_decl", + "path": "partials/struct_field_decl.zapt" + }, + { + "name": "renamed_struct_field_impl", + "path": "partials/renamed_struct_field_impl.zapt" } ], "templates": [ diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h index fdb02bf332a5f7..9d30ab4f455605 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.h @@ -39,11 +39,7 @@ API_AVAILABLE(ios(16.2), macos(13.1), watchos(9.2), tvos(16.2)) API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) MTR_NEWLY_DEPRECATED("Please use MTRDescriptorClusterDeviceTypeStruct") -@interface MTRDescriptorClusterDeviceType : NSObject -@property (nonatomic, copy) NSNumber * _Nonnull type API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) - MTR_NEWLY_DEPRECATED("Please use MTRDescriptorClusterDeviceTypeStruct"); -@property (nonatomic, copy) NSNumber * _Nonnull revision API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) - MTR_NEWLY_DEPRECATED("Please use MTRDescriptorClusterDeviceTypeStruct"); +@interface MTRDescriptorClusterDeviceType : MTRDescriptorClusterDeviceTypeStruct @end API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) @@ -495,8 +491,8 @@ API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) @interface MTRSwitchClusterMultiPressCompleteEvent : NSObject @property (nonatomic, copy) NSNumber * _Nonnull previousPosition MTR_NEWLY_AVAILABLE; -@property (nonatomic, copy) NSNumber * _Nonnull newPosition API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) - MTR_NEWLY_DEPRECATED("Please use previousPosition"); +@property (nonatomic, copy, getter=getNewPosition) NSNumber * _Nonnull newPosition API_AVAILABLE( + ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) MTR_NEWLY_DEPRECATED("Please use previousPosition"); @property (nonatomic, copy) NSNumber * _Nonnull totalNumberOfPressesCounted API_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)); @end diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm index 2061188b08017a..0c2cf034b1542f 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRStructsObjc.mm @@ -112,35 +112,7 @@ - (NSString *)description @end -@implementation MTRDescriptorClusterDeviceType -- (instancetype)init -{ - if (self = [super init]) { - - _type = @(0); - - _revision = @(0); - } - return self; -} - -- (id)copyWithZone:(NSZone * _Nullable)zone -{ - auto other = [[MTRDescriptorClusterDeviceType alloc] init]; - - other.type = self.type; - other.revision = self.revision; - - return other; -} - -- (NSString *)description -{ - NSString * descriptionString = - [NSString stringWithFormat:@"<%@: type:%@; revision:%@; >", NSStringFromClass([self class]), _type, _revision]; - return descriptionString; -} - +@implementation MTRDescriptorClusterDeviceType : MTRDescriptorClusterDeviceTypeStruct @end @implementation MTRBindingClusterTargetStruct @@ -2079,11 +2051,10 @@ - (void)setNewPosition:(NSNumber * _Nonnull)newPosition self.previousPosition = newPosition; } -- (NSNumber * _Nonnull)newPosition +- (NSNumber * _Nonnull)getNewPosition { return self.previousPosition; } - @end @implementation MTROperationalCredentialsClusterFabricDescriptor