From 365e9ff23985f6aa9e4ecfc4d60aac5cedba0ef8 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Tue, 12 Sep 2023 15:14:22 +0200 Subject: [PATCH 1/7] Refs #19236: fix bitmask code generation Signed-off-by: JLBuenoLopez-eProsima --- .../java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg index abbaf1ab..ca130d9b 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -415,13 +415,14 @@ enum $enum.name$ : uint32_t bitmask_type(ctx, parent, bitmask) ::= << /*! - * @brief This class represents the bitmask $bitmask.name$ defined by the user in the IDL file. + * @brief This enumeration represents the $bitmask.name$ bitflags defined by the user in the IDL file. * @ingroup $ctx.trimfilename$ */ -enum $bitmask.name$$bitmask.boundType$ +enum $bitmask.name$Bits$bitmask.boundType$ { $bitmask.members:{ member | $member.name$ = 0x01ull << $member.position$}; separator=",\n"$ }; +typedef $bitmask.castingType$ $bitmask.name$; >> fwd_decl(ctx, parent, type) ::= << From 7a0b73b82d82f78d70069b8519936df149cbd034 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Tue, 12 Sep 2023 15:15:01 +0200 Subject: [PATCH 2/7] Refs #19236: bitmask test code Signed-off-by: JLBuenoLopez-eProsima --- .../idl/templates/SerializationHeader.stg | 13 ++++++++- .../idl/templates/SerializationSource.stg | 28 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg index 774110f7..0db7af6b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationHeader.stg @@ -70,7 +70,18 @@ enum_type(ctx, parent, enum) ::= <<>> typedef_decl(ctx, parent, typedefs) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +void print$bitmask.name$( + $bitmask.name$* topic); + +void initialize$bitmask.name$( + $bitmask.name$* topic); + +int compare$bitmask.name$( + $bitmask.name$* a, + $bitmask.name$* b); + +>> bitset_type(ctx, parent, bitset) ::= << void print$bitset.name$( diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index 77bae39b..3225cb97 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -148,7 +148,33 @@ int $if(union.hasScope)$$union.scope$::$endif$compare$union.name$( enum_type(ctx, parent, enum) ::= <<>> -bitmask_type(ctx, parent, bitmask) ::= <<>> +bitmask_type(ctx, parent, bitmask) ::= << +void $if(bitmask.hasScope)$$bitmask.scope$::$endif$print$bitmask.name$( + $bitmask.name$* topic) +{ + printf("$bitmask.name$: { \n"); + $bitmask.members:{ it | printf("$it.name$: %s\n", *topic & $it.name$ == $it.name$ ? "true" : "false");}; separator="\n"$ +} + +void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$( + $bitmask.name$* topic) +{ + $bitmask.members:{ it | + if (rand() % 2 == 1) + { + *topic |= $it.name$; + \} + }; separator="\n"$ +} + +int $if(bitmask.hasScope)$$bitmask.scope$::$endif$compare$bitmask.name$( + $bitmask.name$* topic_a, + $bitmask.name$* topic_b) +{ + return *topic_a == *topic_b; +} + +>> typedef_decl(ctx, parent, typedefs) ::= <<>> From d3c59babaec21aa9b436d958d56975b9e10a4ac8 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Tue, 12 Sep 2023 15:16:14 +0200 Subject: [PATCH 3/7] Refs #19236: update submodule to IDL-Parser v1.7.1 Signed-off-by: JLBuenoLopez-eProsima --- build.gradle | 2 +- thirdparty/idl-parser | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c224d3f0..b2246c52 100644 --- a/build.gradle +++ b/build.gradle @@ -91,7 +91,7 @@ repositories { } dependencies { - implementation files('thirdparty/idl-parser/build/libs/idlparser-1.6.0.jar') + implementation files('thirdparty/idl-parser/build/libs/idlparser-1.7.1.jar') testImplementation('org.junit.jupiter:junit-jupiter-api:5.5.2') testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.5.2') } diff --git a/thirdparty/idl-parser b/thirdparty/idl-parser index e88ae80b..0dec761f 160000 --- a/thirdparty/idl-parser +++ b/thirdparty/idl-parser @@ -1 +1 @@ -Subproject commit e88ae80bf1ad5f962731110455d211823e8eb89c +Subproject commit 0dec761fad8e25c48d4a865d8fcb9b9f9429f94e From 90ef7364be87117d704f0ae52526555c8049a2fc Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Tue, 12 Sep 2023 15:38:12 +0200 Subject: [PATCH 4/7] Refs #19236: enum scope Signed-off-by: JLBuenoLopez-eProsima --- .../eprosima/fastdds/idl/templates/SerializationSource.stg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index 3225cb97..dd383abb 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -153,7 +153,7 @@ void $if(bitmask.hasScope)$$bitmask.scope$::$endif$print$bitmask.name$( $bitmask.name$* topic) { printf("$bitmask.name$: { \n"); - $bitmask.members:{ it | printf("$it.name$: %s\n", *topic & $it.name$ == $it.name$ ? "true" : "false");}; separator="\n"$ + $bitmask.members:{ it | printf("$it.name$: %s\n", *topic & $bitmask.name$Bits::$it.name$ == $bitmask.name$Bits::$it.name$ ? "true" : "false");}; separator="\n"$ } void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$( @@ -162,7 +162,7 @@ void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$( $bitmask.members:{ it | if (rand() % 2 == 1) { - *topic |= $it.name$; + *topic |= $bitmask.name$Bits::$it.name$; \} }; separator="\n"$ } From e1193e3571c8b61a7c77cc9de383ca8867dc8d82 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Wed, 13 Sep 2023 08:22:03 +0200 Subject: [PATCH 5/7] Refs #19236: apply review suggestions Signed-off-by: JLBuenoLopez-eProsima --- .../fastdds/idl/templates/SerializationSource.stg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index dd383abb..4512b958 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -152,17 +152,17 @@ bitmask_type(ctx, parent, bitmask) ::= << void $if(bitmask.hasScope)$$bitmask.scope$::$endif$print$bitmask.name$( $bitmask.name$* topic) { - printf("$bitmask.name$: { \n"); - $bitmask.members:{ it | printf("$it.name$: %s\n", *topic & $bitmask.name$Bits::$it.name$ == $bitmask.name$Bits::$it.name$ ? "true" : "false");}; separator="\n"$ + printf("$bitmask.scopedname$: { \n"); + $bitmask.members:{ member | printf("$member.name$: %s\n", *topic & $bitmask.name$Bits::$member.name$ == $bitmask.name$Bits::$member.name$ ? "true" : "false");}; separator="\n"$ } void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$( $bitmask.name$* topic) { - $bitmask.members:{ it | + $bitmask.members:{ member | if (rand() % 2 == 1) { - *topic |= $bitmask.name$Bits::$it.name$; + *topic |= $bitmask.name$Bits::$member.name$; \} }; separator="\n"$ } From 92919e6d3bc2b57aa3b07450697cf42f6a97fccb Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Wed, 13 Sep 2023 08:55:26 +0200 Subject: [PATCH 6/7] Refs #19236: set bitmask initial value Signed-off-by: JLBuenoLopez-eProsima --- .../java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg index ca130d9b..82f0c5bc 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg @@ -627,6 +627,8 @@ $if(member.annotationDefault)$ $elseif(!member.annotationOptional)$ $if(member.typecode.initialValue)$ {$member.typecode.initialValue$} +$elseif(member.typecode.isBitmaskType)$ + {0} $endif$ $endif$ $endif$ From 122aa1b6998097ac0200a598499a61135ee35d19 Mon Sep 17 00:00:00 2001 From: JLBuenoLopez-eProsima Date: Wed, 13 Sep 2023 10:30:51 +0200 Subject: [PATCH 7/7] Refs #19236: apply review suggestion Signed-off-by: JLBuenoLopez-eProsima --- .../com/eprosima/fastdds/idl/templates/SerializationSource.stg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg index 4512b958..84e227a6 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SerializationSource.stg @@ -153,7 +153,7 @@ void $if(bitmask.hasScope)$$bitmask.scope$::$endif$print$bitmask.name$( $bitmask.name$* topic) { printf("$bitmask.scopedname$: { \n"); - $bitmask.members:{ member | printf("$member.name$: %s\n", *topic & $bitmask.name$Bits::$member.name$ == $bitmask.name$Bits::$member.name$ ? "true" : "false");}; separator="\n"$ + $bitmask.members:{ member | printf("$member.name$: %s\n", ((*topic & $bitmask.name$Bits::$member.name$) == $bitmask.name$Bits::$member.name$) ? "true" : "false");}; separator="\n"$ } void $if(bitmask.hasScope)$$bitmask.scope$::$endif$initialize$bitmask.name$(