From 427d5874c103380f07583dc3be2382e33f019f91 Mon Sep 17 00:00:00 2001 From: Johannes Wolf Date: Fri, 19 Jul 2024 12:54:11 +0200 Subject: [PATCH 1/2] generator: Remove use of is*Set() in is*Used() --- compiler/extensions/cpp/freemarker/CompoundField.inc.ftl | 2 +- compiler/extensions/java/freemarker/Structure.java.ftl | 2 +- compiler/extensions/python/freemarker/Structure.py.ftl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/extensions/cpp/freemarker/CompoundField.inc.ftl b/compiler/extensions/cpp/freemarker/CompoundField.inc.ftl index c21d0aedd..203a0c83f 100644 --- a/compiler/extensions/cpp/freemarker/CompoundField.inc.ftl +++ b/compiler/extensions/cpp/freemarker/CompoundField.inc.ftl @@ -182,7 +182,7 @@ ${I}} <#macro field_optional_condition field> - <#if field.optional.clause??>${field.optional.clause}<#else>${field.optional.isSetIndicatorName}()<#t> + <#if field.optional.clause??>${field.optional.clause}<#else><@field_member_name field/>.hasValue()<#t> <#macro compound_write_field field compoundName indent packed=false> diff --git a/compiler/extensions/java/freemarker/Structure.java.ftl b/compiler/extensions/java/freemarker/Structure.java.ftl index db213c721..6a18ec7a9 100644 --- a/compiler/extensions/java/freemarker/Structure.java.ftl +++ b/compiler/extensions/java/freemarker/Structure.java.ftl @@ -314,7 +314,7 @@ public class ${name} implements <#rt> public boolean ${field.optional.isUsedIndicatorName}() { - return <#if field.optional.clause??>(${field.optional.clause});<#else>${field.optional.isSetIndicatorName}(); + return <#if field.optional.clause??>(${field.optional.clause});<#else>(<@field_member_name field/> != null); } <#if withWriterCode> diff --git a/compiler/extensions/python/freemarker/Structure.py.ftl b/compiler/extensions/python/freemarker/Structure.py.ftl index da1019096..6138e3c63 100644 --- a/compiler/extensions/python/freemarker/Structure.py.ftl +++ b/compiler/extensions/python/freemarker/Structure.py.ftl @@ -301,7 +301,7 @@ ${I}<#rt> """ - return <#if field.optional.clause??>${field.optional.clause}<#else>self.${field.optional.isSetIndicatorName}() + return <#if field.optional.clause??>${field.optional.clause}<#else>not self.<@field_member_name field/> is None <#if withWriterCode> def ${field.optional.isSetIndicatorName}(self) -> bool: From 27dde883cda1dfdd2c59e084d9aa6131760975ff Mon Sep 17 00:00:00 2001 From: Johannes Wolf Date: Fri, 19 Jul 2024 13:37:39 +0200 Subject: [PATCH 2/2] test: Add test for optional field wo/ writer code --- test/arguments/without_writer_code/zs/without_writer_code.zs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/arguments/without_writer_code/zs/without_writer_code.zs b/test/arguments/without_writer_code/zs/without_writer_code.zs index 8a179945c..849a3f434 100644 --- a/test/arguments/without_writer_code/zs/without_writer_code.zs +++ b/test/arguments/without_writer_code/zs/without_writer_code.zs @@ -18,6 +18,11 @@ union ExtraParamUnion uint32 value32; }; +struct ItemWithOptionalField +{ + optional uint16 opt; +}; + struct Item(ItemType itemType) { uint16 param;