Skip to content

Commit

Permalink
Fix Darwin name determination for global structs and enums.
Browse files Browse the repository at this point in the history
The naming pattern is a bit different from cluster-specific ones.
  • Loading branch information
bzbarsky-apple committed Jul 26, 2024
1 parent 50afd74 commit 96f0a9f
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ async function asObjectiveCClass(type, cluster, options) {
}

if (isStruct) {
const structObj = await zclQuery.selectStructByName(
this.global.db,
type,
pkgIds
);
if (structObj.structClusterCount == 0) {
// This is a global struct.
return `${
options.hash.structTypePrefix || 'MTR'
}DataType${appHelper.asUpperCamelCase(type)}`;
}

if (options.hash.compatRemapClusterName) {
cluster = compatClusterNameRemapping.call(this, cluster, { hash: {} });
// If we are generating the "use the old name" API, here, and using the
Expand All @@ -265,7 +277,9 @@ async function asObjectiveCClass(type, cluster, options) {
});
}
// Use a custom prefix if specified, otherwise default to "MTR" for backwards compat.
return `${options.hash.structTypePrefix || "MTR"}${cluster}Cluster${appHelper.asUpperCamelCase(type)}`;
return `${
options.hash.structTypePrefix || 'MTR'
}${cluster}Cluster${appHelper.asUpperCamelCase(type)}`;
}

return 'NSNumber';
Expand Down Expand Up @@ -339,6 +353,12 @@ function commandHasRequiredField(command) {
* "Enum" bits on the enum names while we're here.
*/
function objCEnumName(clusterName, enumLabel, options) {
if (clusterName == 'Globals') {
// For global enums, just use "MTRDataType" followed by the label, without
// stripping "Enum" off the end or doing any other processing.
return 'MTRDataType' + enumLabel;
}

clusterName = appHelper.asUpperCamelCase(clusterName, {
hash: { preserveAcronyms: options.hash.preserveAcronyms },
});
Expand Down

0 comments on commit 96f0a9f

Please sign in to comment.