Skip to content

Commit

Permalink
Be a bit more consistent about type handling in ZAP templates. (#10718)
Browse files Browse the repository at this point in the history
* Instead of checking for "item.type == 'boolean'", which would not
  work right for command args (where the type is "BOOLEAN"), go
  through our normal type-mapping machinery and then use the resulting
  uniform output.

* Add "single" to our atomic type overrides and remove manual handling
  of it in zapTypeToClusterObjectType.  This incidentally fixes all
  the generated accessors for single-typed attributes.

* Fix a debugging exception message to include the value that could not be
  handled in a more-correct way.
  • Loading branch information
bzbarsky-apple authored Oct 21, 2021
1 parent 081436f commit abc069e
Show file tree
Hide file tree
Showing 6 changed files with 485 additions and 489 deletions.
2 changes: 1 addition & 1 deletion src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ function chip_tests_item_parameters(options)
value = new Boolean(value);
break;
default:
throw new Error('Unsupported value: ', value);
throw new Error('Unsupported value: ' + JSON.stringify(value));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/app/zap-templates/common/ClustersHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ function asChipCallback(item)
return { name : 'List', type : null };
}

if (item.type == 'boolean') {
return { name : 'Boolean', type : 'bool' };
}

const basicType = ChipTypesHelper.asBasicType(item.chipType);
switch (basicType) {
case 'int8_t':
Expand All @@ -212,6 +208,8 @@ function asChipCallback(item)
case 'uint32_t':
case 'uint64_t':
return { name : 'Int' + basicType.replace(/[^0-9]/g, '') + 'u', type : basicType };
case 'bool':
return { name : 'Boolean', type : 'bool' };
default:
return { name : 'Unsupported', type : null };
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/common/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function atomicType(arg)
switch (arg.name) {
case 'boolean':
return 'bool';
case 'single':
return 'float';
case 'int40s':
case 'int48s':
case 'int56s':
Expand Down
4 changes: 0 additions & 4 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ function asMEI(prefix, suffix)
*/
async function zapTypeToClusterObjectType(type, isDecodable, options)
{
if (type == 'single') {
return 'float';
}

async function fn(pkgId)
{
const ns = options.hash.ns ? ('chip::app::Clusters::' + asUpperCamelCase(options.hash.ns) + '::') : '';
Expand Down
Loading

0 comments on commit abc069e

Please sign in to comment.