Skip to content

Commit

Permalink
Fix bitmask code generation (#223)
Browse files Browse the repository at this point in the history
* Refs #19236: fix bitmask code generation

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: bitmask test code

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: update submodule to IDL-Parser v1.7.1

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: enum scope

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: apply review suggestions

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: set bitmask initial value

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

* Refs #19236: apply review suggestion

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>

---------

Signed-off-by: JLBuenoLopez-eProsima <[email protected]>
  • Loading branch information
JLBuenoLopez authored Sep 13, 2023
1 parent bbf3cb1 commit da185d2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) ::= <<
Expand Down Expand Up @@ -626,6 +627,8 @@ $if(member.annotationDefault)$
$elseif(!member.annotationOptional)$
$if(member.typecode.initialValue)$
{$member.typecode.initialValue$}
$elseif(member.typecode.isBitmaskType)$
{0}
$endif$
$endif$
$endif$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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:{ member |
if (rand() % 2 == 1)
{
*topic |= $bitmask.name$Bits::$member.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) ::= <<>>

Expand Down

0 comments on commit da185d2

Please sign in to comment.