Skip to content

Commit

Permalink
Generate Objective C NS_ENUM/NS_OPTIONS for enums and bitmaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Feb 23, 2022
1 parent 7f96a28 commit 43e7c55
Show file tree
Hide file tree
Showing 3 changed files with 1,575 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/darwin/Framework/CHIP/templates/CHIPClustersObjc.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ subscriptionEstablished:(SubscriptionEstablishedHandler _Nullable)subscriptionEs

{{/chip_client_clusters}}

{{#zcl_clusters}}
{{#zcl_enums}}
typedef NS_ENUM(NSInteger, {{enumName ../name label}}) {
{{#zcl_enum_items}}
{{enumName ../../name ../label}}{{asType label}} = {{asHex value 2}},
{{/zcl_enum_items}}
};

{{/zcl_enums}}
{{#zcl_bitmaps}}
typedef NS_OPTIONS(NSUInteger, {{enumName ../name label}}) {
{{#zcl_bitmap_items}}
{{enumName ../../name ../label}}{{asType label}} = {{asHex mask}},
{{/zcl_bitmap_items}}
};

{{/zcl_bitmaps}}
{{/zcl_clusters}}

NS_ASSUME_NONNULL_END

#endif /* CHIP_CLUSTERS_H */
Expand Down
14 changes: 14 additions & 0 deletions src/darwin/Framework/CHIP/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ function commandHasRequiredField(command)
return command.arguments.some(arg => !arg.isOptional);
}

function enumName(clusterName, enumLabel)
{
clusterName = appHelper.asUpperCamelCase(clusterName);
enumLabel = appHelper.asUpperCamelCase(enumLabel);
// Some enum names have one or more copies of the cluster name at the
// beginning.
while (enumLabel.startsWith(clusterName)) {
enumLabel = enumLabel.replace(new RegExp("^" + clusterName), "");
}

return "CHIP" + clusterName + enumLabel;
}

//
// Module exports
//
Expand All @@ -155,3 +168,4 @@ exports.asObjectiveCType = asObjectiveCType;
exports.asStructPropertyName = asStructPropertyName;
exports.asGetterName = asGetterName;
exports.commandHasRequiredField = commandHasRequiredField;
exports.enumName = enumName;
Loading

0 comments on commit 43e7c55

Please sign in to comment.