-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Darwin codegen support for global structs and enums. (#34527)
There's a bunch of refactoring of templates to avoid copy/paste for the global case. But the generated output is the same so far, until some ZAP-side changes happen that would let us actually enable the global bits.
- Loading branch information
1 parent
9ef5bbf
commit e58954d
Showing
8 changed files
with
173 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/darwin/Framework/CHIP/templates/partials/enum_decl.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{! Arguments: cluster (might be "Globals", is not case-canonicalized), name, enumLabel }} | ||
{{#*inline "enumDef"}} | ||
typedef NS_ENUM({{asUnderlyingZclType name}}, {{objCEnumName clusterName enumName}}) { | ||
{{#zcl_enum_items}} | ||
{{#if (isSupported ../clusterName enum=../enumName enumValue=(asUpperCamelCase label preserveAcronyms=true))}} | ||
{{objCEnumName ../clusterName ../enumName}}{{asUpperCamelCase label preserveAcronyms=true}} {{availability ../clusterName enum=../enumName enumValue=(asUpperCamelCase label preserveAcronyms=true) deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../cluster preserveAcronyms=true) ../enumLabel) (asUpperCamelCase label preserveAcronyms=true))}} = {{asHex value 2}}, | ||
{{/if}} | ||
{{#*inline "oldNameItemDecl"}} | ||
{{#if oldItemName}} | ||
{{#if (isSupported ../clusterName enum=../enumName enumValue=oldItemName)}} | ||
{{objCEnumName ../clusterName ../enumName}}{{objCEnumItemLabel oldItemName}} {{availability ../clusterName enum=../enumName enumValue=oldItemName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase ../cluster preserveAcronyms=true) ../enumLabel) (asUpperCamelCase label preserveAcronyms=true))}} = {{asHex value 2}}, | ||
{{/if}} | ||
{{/if}} | ||
{{/inline}} | ||
{{> oldNameItemDecl oldItemName=(oldName ../clusterName enum=../enumName enumValue=(asUpperCamelCase label preserveAcronyms=true))}} | ||
{{/zcl_enum_items}} | ||
{{!We had extra "Not Supported" values for DoorLockUserStatus/DoorLockUserType that we have to wedge in here manually for now.}} | ||
{{#if (and (isStrEqual clusterName "DoorLock") | ||
(or (isStrEqual enumName "UserTypeEnum") (isStrEqual enumName "UserStatusEnum")) | ||
(isSupported clusterName enum=enumName enumValue="NotSupported"))}} | ||
{{objCEnumName clusterName enumName}}{{objCEnumItemLabel "NotSupported"}} {{availability clusterName enum=enumName enumValue="NotSupported" deprecationMessage="This value is not part of the specification and will be removed"}} = 0xFF, | ||
{{/if}} | ||
} | ||
{{/inline}} | ||
{{#if (isSupported (asUpperCamelCase cluster preserveAcronyms=true) enum=(asUpperCamelCase enumLabel preserveAcronyms=true))}} | ||
{{> enumDef name=name clusterName=(asUpperCamelCase cluster preserveAcronyms=true) enumName=(asUpperCamelCase enumLabel preserveAcronyms=true)}} {{availability (asUpperCamelCase cluster preserveAcronyms=true) enum=(asUpperCamelCase enumLabel preserveAcronyms=true) deprecationMessage="This enum is unused and will be removed"}}; | ||
{{/if}} | ||
{{! Takes the name of the enum to use as enumName. }} | ||
{{#*inline "oldNameDecl"}} | ||
{{#if (isSupported (compatClusterNameRemapping cluster) enum=enumName)}} | ||
|
||
{{> enumDef name=name clusterName=(compatClusterNameRemapping cluster) enumName=enumName}} {{availability (compatClusterNameRemapping cluster) enum=enumName deprecationMessage=(concat "Please use " (objCEnumName (asUpperCamelCase cluster preserveAcronyms=true) enumLabel))}}; | ||
{{/if}} | ||
{{/inline}} | ||
{{! Takes the old name of the enum, if any, as oldEnumName. }} | ||
{{#*inline "oldNameCheck"}} | ||
{{#if (or oldEnumName | ||
(hasOldName (asUpperCamelCase cluster preserveAcronyms=true)))}} | ||
{{#if oldEnumName}} | ||
{{> oldNameDecl enumName=oldEnumName}} | ||
{{else}} | ||
{{> oldNameDecl enumName=(asUpperCamelCase enumLabel preserveAcronyms=true)}} | ||
{{/if}} | ||
{{/if}} | ||
{{/inline}} | ||
{{> oldNameCheck oldEnumName=(oldName (asUpperCamelCase cluster preserveAcronyms=true) enum=(asUpperCamelCase enumLabel preserveAcronyms=true))}} |
25 changes: 25 additions & 0 deletions
25
src/darwin/Framework/CHIP/templates/partials/struct_interface_decl.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{! Arguments: cluster (might be "Globals", is case-canonicalized already), originalCluster (the name before remapping and whatnot), struct, baseName (might be "" to indicate NSObject), deprecationMessage }} | ||
{{#if (isSupported cluster struct=struct)}} | ||
{{availability cluster struct=struct deprecationMessage=deprecationMessage}} | ||
@interface {{#if (isStrEqual cluster "Globals") ~}} | ||
MTRDataType{{struct}} | ||
{{~else~}} | ||
MTR{{cluster}}Cluster{{struct}} | ||
{{~/if}} : {{#if (isStrEqual baseName "")~}} | ||
NSObject<NSCopying> | ||
{{~else~}} | ||
{{baseName}} | ||
{{~/if}} | ||
{{#zcl_struct_items}} | ||
{{#if (isSupported ../cluster struct=../struct structField=(asStructPropertyName label))}} | ||
{{> struct_field_decl cluster=../cluster type=type label=label}} {{availability ../cluster struct=../struct structField=(asStructPropertyName label) deprecationMessage=(concat "Please use MTR" (asUpperCamelCase ../originalCluster preserveAcronyms=true) "Cluster" (asUpperCamelCase ../name preserveAcronyms=true))}}; | ||
{{/if}} | ||
{{#if (hasOldName ../cluster struct=../struct structField=(asStructPropertyName label))}} | ||
{{#if (isSupported ../cluster struct=../struct structField=(oldName ../cluster struct=../struct structField=(asStructPropertyName label)))}} | ||
{{> struct_field_decl cluster=../cluster type=type label=(oldName ../cluster struct=../struct structField=(asStructPropertyName label))}} {{availability ../cluster struct=../struct structField=(oldName ../cluster struct=../struct structField=(asStructPropertyName label)) deprecationMessage=(concat "Please use " (asStructPropertyName label))}}; | ||
{{/if}} | ||
{{/if}} | ||
{{/zcl_struct_items}} | ||
@end | ||
|
||
{{/if}} |
57 changes: 57 additions & 0 deletions
57
src/darwin/Framework/CHIP/templates/partials/struct_interface_impl.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{! Arguments: cluster (might be "Globals", not case-canonicalized), struct }} | ||
{{! Avoid uppercasing stuff all the time by wrapping the whole thing in an inline that takes cluster, | ||
originalCluster, and struct, where cluster and struct are uppercased }} | ||
{{#*inline "interfaceImpl"}} | ||
{{#if (isSupported cluster struct=struct)}} | ||
@implementation {{asObjectiveCClass struct cluster}} | ||
- (instancetype)init | ||
{ | ||
if (self = [super init]) { | ||
{{#zcl_struct_items}} | ||
{{#if (isSupported ../cluster struct=../struct structField=(asStructPropertyName label))}} | ||
{{>init_struct_member label=label type=type cluster=../originalCluster}} | ||
{{/if}} | ||
{{/zcl_struct_items}} | ||
} | ||
return self; | ||
} | ||
|
||
- (id)copyWithZone:(NSZone * _Nullable)zone | ||
{ | ||
auto other = [[{{asObjectiveCClass struct cluster}} alloc] init]; | ||
|
||
{{#zcl_struct_items}} | ||
{{#if (isSupported ../cluster struct=../struct structField=(asStructPropertyName label))}} | ||
other.{{asStructPropertyName label}} = self.{{asStructPropertyName label}}; | ||
{{/if}} | ||
{{/zcl_struct_items}} | ||
|
||
return other; | ||
} | ||
|
||
- (NSString *)description | ||
{ | ||
NSString *descriptionString = [NSString stringWithFormat:@"<%@: {{#zcl_struct_items~}} | ||
{{~#if (isSupported ../cluster struct=../struct structField=(asStructPropertyName label))~}} | ||
{{~asStructPropertyName label}}:%@; {{!Just here to keep the preceding space}} | ||
{{~/if~}} | ||
{{~/zcl_struct_items}}>", NSStringFromClass([self class]){{#zcl_struct_items~}} | ||
{{~#if (isSupported ../cluster struct=../struct structField=(asStructPropertyName label))~}} | ||
,{{#if isArray}}_{{asStructPropertyName label}}{{else if (isOctetString type)}}[_{{asStructPropertyName label}} base64EncodedStringWithOptions:0]{{else}}_{{asStructPropertyName label}}{{/if}} | ||
{{~/if~}} | ||
{{~/zcl_struct_items}}]; | ||
return descriptionString; | ||
} | ||
{{#zcl_struct_items}} | ||
{{#if (and (hasOldName ../cluster struct=../struct structField=(asStructPropertyName label)) | ||
(isSupported ../cluster struct=../struct structField=(oldName ../cluster struct=../struct structField=(asStructPropertyName label))))}} | ||
|
||
{{> renamed_struct_field_impl cluster=../originalCluster type=type newName=label oldName=(oldName ../cluster struct=../struct structField=(asStructPropertyName label))}} | ||
{{/if}} | ||
{{/zcl_struct_items}} | ||
|
||
@end | ||
|
||
{{/if}} | ||
{{/inline}} | ||
{{> interfaceImpl cluster=(asUpperCamelCase cluster preserveAcronyms=true) originalCluster=cluster struct=(asUpperCamelCase struct preserveAcronyms=true)}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters