Skip to content

Commit

Permalink
Implement codegen for global things
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Jul 26, 2024
1 parent 4334e91 commit a320909
Show file tree
Hide file tree
Showing 65 changed files with 4,993 additions and 587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6809,6 +6809,7 @@ internal cluster UnitTesting = 4294048773 {
SimpleBitmap f = 5;
single g = 6;
double h = 7;
optional TestGlobalEnum i = 8;
}

fabric_scoped struct TestFabricScoped {
Expand Down Expand Up @@ -6841,6 +6842,7 @@ internal cluster UnitTesting = 4294048773 {
int8u a = 0;
boolean b = 1;
SimpleStruct c = 2;
optional TestGlobalStruct d = 3;
}

struct NestedStructList {
Expand Down Expand Up @@ -6926,6 +6928,8 @@ internal cluster UnitTesting = 4294048773 {
timedwrite attribute boolean timedWriteBoolean = 48;
attribute boolean generalErrorBoolean = 49;
attribute boolean clusterErrorBoolean = 50;
attribute TestGlobalEnum globalEnum = 51;
attribute TestGlobalStruct globalStruct = 52;
attribute optional boolean unsupported = 255;
attribute nullable boolean nullableBoolean = 16384;
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
Expand Down Expand Up @@ -6961,6 +6965,8 @@ internal cluster UnitTesting = 4294048773 {
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
attribute optional int8u writeOnlyInt8u = 16426;
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
attribute int8u meiInt8u = 4294070017;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down Expand Up @@ -7112,6 +7118,11 @@ internal cluster UnitTesting = 4294048773 {
SimpleEnum arg2 = 1;
}

response struct GlobalEchoResponse = 14 {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestNullableOptionalRequestRequest {
optional nullable int8u arg1 = 0;
}
Expand Down Expand Up @@ -7165,6 +7176,11 @@ internal cluster UnitTesting = 4294048773 {
octet_string payload = 0;
}

request struct GlobalEchoRequestRequest {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -7248,6 +7264,9 @@ internal cluster UnitTesting = 4294048773 {
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command that takes arguments that are global structs/enums and the
response just echoes them back. */
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5458,6 +5458,7 @@ internal cluster UnitTesting = 4294048773 {
SimpleBitmap f = 5;
single g = 6;
double h = 7;
optional TestGlobalEnum i = 8;
}

fabric_scoped struct TestFabricScoped {
Expand Down Expand Up @@ -5490,6 +5491,7 @@ internal cluster UnitTesting = 4294048773 {
int8u a = 0;
boolean b = 1;
SimpleStruct c = 2;
optional TestGlobalStruct d = 3;
}

struct NestedStructList {
Expand Down Expand Up @@ -5575,6 +5577,8 @@ internal cluster UnitTesting = 4294048773 {
timedwrite attribute boolean timedWriteBoolean = 48;
attribute boolean generalErrorBoolean = 49;
attribute boolean clusterErrorBoolean = 50;
attribute TestGlobalEnum globalEnum = 51;
attribute TestGlobalStruct globalStruct = 52;
attribute optional boolean unsupported = 255;
attribute nullable boolean nullableBoolean = 16384;
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
Expand Down Expand Up @@ -5610,6 +5614,8 @@ internal cluster UnitTesting = 4294048773 {
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
attribute optional int8u writeOnlyInt8u = 16426;
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
attribute int8u meiInt8u = 4294070017;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down Expand Up @@ -5761,6 +5767,11 @@ internal cluster UnitTesting = 4294048773 {
SimpleEnum arg2 = 1;
}

response struct GlobalEchoResponse = 14 {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestNullableOptionalRequestRequest {
optional nullable int8u arg1 = 0;
}
Expand Down Expand Up @@ -5814,6 +5825,11 @@ internal cluster UnitTesting = 4294048773 {
octet_string payload = 0;
}

request struct GlobalEchoRequestRequest {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -5897,6 +5913,9 @@ internal cluster UnitTesting = 4294048773 {
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command that takes arguments that are global structs/enums and the
response just echoes them back. */
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down
19 changes: 19 additions & 0 deletions examples/chef/devices/rootnode_contactsensor_27f76aeaf5.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ internal cluster UnitTesting = 4294048773 {
SimpleBitmap f = 5;
single g = 6;
double h = 7;
optional TestGlobalEnum i = 8;
}

fabric_scoped struct TestFabricScoped {
Expand Down Expand Up @@ -1509,6 +1510,7 @@ internal cluster UnitTesting = 4294048773 {
int8u a = 0;
boolean b = 1;
SimpleStruct c = 2;
optional TestGlobalStruct d = 3;
}

struct NestedStructList {
Expand Down Expand Up @@ -1594,6 +1596,8 @@ internal cluster UnitTesting = 4294048773 {
timedwrite attribute boolean timedWriteBoolean = 48;
attribute boolean generalErrorBoolean = 49;
attribute boolean clusterErrorBoolean = 50;
attribute TestGlobalEnum globalEnum = 51;
attribute TestGlobalStruct globalStruct = 52;
attribute optional boolean unsupported = 255;
attribute nullable boolean nullableBoolean = 16384;
attribute nullable Bitmap8MaskMap nullableBitmap8 = 16385;
Expand Down Expand Up @@ -1629,6 +1633,8 @@ internal cluster UnitTesting = 4294048773 {
attribute nullable int16u nullableRangeRestrictedInt16u = 16424;
attribute nullable int16s nullableRangeRestrictedInt16s = 16425;
attribute optional int8u writeOnlyInt8u = 16426;
attribute nullable TestGlobalEnum nullableGlobalEnum = 16435;
attribute nullable TestGlobalStruct nullableGlobalStruct = 16436;
attribute int8u meiInt8u = 4294070017;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down Expand Up @@ -1780,6 +1786,11 @@ internal cluster UnitTesting = 4294048773 {
SimpleEnum arg2 = 1;
}

response struct GlobalEchoResponse = 14 {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestNullableOptionalRequestRequest {
optional nullable int8u arg1 = 0;
}
Expand Down Expand Up @@ -1833,6 +1844,11 @@ internal cluster UnitTesting = 4294048773 {
octet_string payload = 0;
}

request struct GlobalEchoRequestRequest {
TestGlobalStruct field1 = 0;
TestGlobalEnum field2 = 1;
}

request struct TestDifferentVendorMeiRequestRequest {
int8u arg1 = 0;
}
Expand Down Expand Up @@ -1916,6 +1932,9 @@ internal cluster UnitTesting = 4294048773 {
the string back. If the string is large then it would require a session that
supports large payloads. */
command StringEchoRequest(StringEchoRequestRequest): StringEchoResponse = 24;
/** Command that takes arguments that are global structs/enums and the
response just echoes them back. */
command GlobalEchoRequest(GlobalEchoRequestRequest): GlobalEchoResponse = 25;
/** Command having a different MEI vendor ID than the cluster. Also emits TestDifferentVendorMeiEvent. */
command TestDifferentVendorMeiRequest(TestDifferentVendorMeiRequestRequest): TestDifferentVendorMeiResponse = 4294049962;
}
Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_impl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_parser_impl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/ComplexArgumentParser.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_parser_decl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_parser_decl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using namespace chip::app::Clusters;
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_impl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_logger_impl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/logging/DataModelLogger.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_decl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_logger_decl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}

Expand Down
4 changes: 4 additions & 0 deletions src/app/common/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"name": "cluster_enums_enum",
"path": "../../zap-templates/partials/cluster-enums-enum.zapt"
},
{
"name": "cluster_enums_ensure_known_value",
"path": "../../zap-templates/partials/cluster-enums-ensure-known-value.zapt"
},
{
"name": "cluster_objects_field_init",
"path": "../../zap-templates/partials/cluster-objects-field-init.zapt"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{#unless (isInConfigList (concat ns "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{ns}}::{{asType label}} val)
{
using EnumType = {{ns}}::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
33 changes: 5 additions & 28 deletions src/app/zap-templates/templates/app/cluster-enums-check.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,17 @@ namespace app {
namespace Clusters {
{{#zcl_enums}}
{{#if has_more_than_one_cluster}}
{{#unless (isInConfigList (concat "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue(detail::{{asType label}} val)
{
using EnumType = detail::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
{{> cluster_enums_ensure_known_value ns="detail"}}
{{else if has_no_clusters}}
{{> cluster_enums_ensure_known_value ns="Globals"}}

{{/if}}
{{/zcl_enums}}

{{#zcl_clusters}}
{{#zcl_enums}}
{{#unless has_more_than_one_cluster}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
{
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
switch (val) {
{{#zcl_enum_items}}
case EnumType::k{{asUpperCamelCase label}}:
{{/zcl_enum_items}}
return val;
default:
return EnumType::kUnknownEnumValue;
}
}
{{/unless}}
{{> cluster_enums_ensure_known_value ns=(asUpperCamelCase ../name)}}
{{/unless}}
{{/zcl_enums}}

Expand Down
31 changes: 31 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ k{{asUpperCamelCase label}} = {{asHex mask}},

} // namespace detail

namespace Globals {
// Global enums.
{{#zcl_enums}}

{{#if has_no_clusters}}

{{> cluster_enums_enum ns=""}}

{{/if}}
{{/zcl_enums}}

// Global bitmaps.
{{#zcl_bitmaps}}

{{#if has_no_clusters}}
{{! Work around https://github.com/project-chip/zap/issues/1370 and manually filter out built-in bitmap types. }}
{{#if_is_atomic label}}
{{else}}

// Bitmap for {{label}}
enum class {{asType label}} : {{asUnderlyingZclType name}} {
{{#zcl_bitmap_items}}
k{{asUpperCamelCase label}} = {{asHex mask}},
{{/zcl_bitmap_items}}
};

{{/if_is_atomic}}
{{/if}}
{{/zcl_bitmaps}}

} // namespace Globals

{{#zcl_clusters}}
namespace {{asUpperCamelCase name}} {
Expand Down
12 changes: 12 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ namespace Structs {
} // namespace Structs
} // namespace detail

namespace Globals {
// Global structs
namespace Structs {
{{#zcl_structs}}
{{#if has_no_clusters}}
{{> cluster_objects_struct header=false}}

{{/if}}
{{/zcl_structs}}
} // namespace Structs
} // namespace Globals

{{#zcl_clusters}}
namespace {{asUpperCamelCase name}} {
{{#zcl_structs}}
Expand Down
12 changes: 12 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ namespace Structs {
} // namespace detail

namespace Globals {

// Global structs.
namespace Structs {

{{#zcl_structs}}
{{#if has_no_clusters}}
{{> cluster_objects_struct header=true}}

{{/if}}
{{/zcl_structs}}
} // namespace Structs

namespace Attributes {
{{#zcl_attributes_server}}
{{#unless clusterRef}}
Expand Down
Loading

0 comments on commit a320909

Please sign in to comment.