Skip to content

Commit

Permalink
Fixed usage of const as literals (#248)
Browse files Browse the repository at this point in the history
* Refs #13731. Separate literal evaluation and maximum size

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #13731. Fix generation of constants inside modules

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #13731. Update submodule

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

* Refs #13731. Apply suggestion

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>

---------

Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev>
  • Loading branch information
richiware committed Oct 9, 2023
1 parent 187aafd commit 7df0be7
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ $definitions; separator="\n"$
$"\n"$
>>

// TODO name -> module
module(ctx, parent, module, definition_list) ::= <<
namespace $module.name$ {
$definition_list$

$definition_list$

} // namespace $module.name$
>>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ $endif$
>>

module(ctx, parent, module, definition_list) ::= <<
namespace $module.name$ {

$definition_list$

} // namespace $module.name$
>>

definition_list(definitions) ::= <<
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/eprosima/fastdds/idl/grammar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public EnumTypeCode createEnumTypeCode(
public MapTypeCode createMapTypeCode(
String maxsize)
{
return new MapTypeCode(maxsize);
return new MapTypeCode(maxsize, evaluate_literal(maxsize));
}

@Override
Expand All @@ -136,22 +136,22 @@ public PrimitiveTypeCode createPrimitiveTypeCode(
public SequenceTypeCode createSequenceTypeCode(
String maxsize)
{
return new SequenceTypeCode(maxsize);
return new SequenceTypeCode(maxsize, evaluate_literal(maxsize));
}

@Override
public SetTypeCode createSetTypeCode(
String maxsize)
{
return new SetTypeCode(maxsize);
return new SetTypeCode(maxsize, evaluate_literal(maxsize));
}

@Override
public StringTypeCode createStringTypeCode(
int kind,
String maxsize)
{
return new StringTypeCode(kind, maxsize);
return new StringTypeCode(kind, maxsize, evaluate_literal(maxsize));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public long maxSerializedSize(
}

long size = 1;
for (int count = 0; count < getDimensions().size(); ++count)
for (int count = 0; count < getEvaluatedDimensions().size(); ++count)
{
size *= Long.parseLong(getDimensions().get(count), 10);
size *= Long.parseLong(getEvaluatedDimensions().get(count), 10);
}

if (0 < size)
Expand All @@ -61,9 +61,9 @@ public long maxPlainTypeSerializedSize(
long initial_alignment = current_alignment;

long size = 1;
for (int count = 0; count < getDimensions().size(); ++count)
for (int count = 0; count < getEvaluatedDimensions().size(); ++count)
{
size *= Long.parseLong(getDimensions().get(count), 10);
size *= Long.parseLong(getEvaluatedDimensions().get(count), 10);
}

if (0 < size)
Expand All @@ -85,9 +85,9 @@ public long maxPlainTypeSerializedSize(
public boolean isNotZeroArray()
{
long size = 1;
for (int count = 0; count < getDimensions().size(); ++count)
for (int count = 0; count < getEvaluatedDimensions().size(); ++count)
{
size *= Long.parseLong(getDimensions().get(count), 10);
size *= Long.parseLong(getEvaluatedDimensions().get(count), 10);
}
return 0 != size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ public class MapTypeCode extends com.eprosima.idl.parser.typecode.MapTypeCode
implements TypeCode
{
public MapTypeCode(
String maxsize)
String maxsize,
String evaluated_maxsize)
{
super(maxsize);
super(maxsize, evaluated_maxsize);
}

@Override
public long maxSerializedSize(
long current_alignment)
{
long initial_alignment = current_alignment;
long maxsize = Long.parseLong(getMaxsize(), 10);
long maxsize = Long.parseLong(getEvaluatedMaxsize(), 10);


if (!getValueTypeCode().isPrimitive() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class SequenceTypeCode extends com.eprosima.idl.parser.typecode.SequenceT
implements TypeCode
{
public SequenceTypeCode(
String maxsize)
String maxsize,
String evaluated_maxsize)
{
super(maxsize);
super(maxsize, evaluated_maxsize);
}

@Override
Expand All @@ -31,7 +32,7 @@ public long maxSerializedSize(
{
long initial_alignment = current_alignment;
long maxsize = !detect_recursive_
? Long.parseLong(getMaxsize(), 10)
? Long.parseLong(getEvaluatedMaxsize(), 10)
: 0;

boolean should_set_and_unset = !detect_recursive_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ public class SetTypeCode extends com.eprosima.idl.parser.typecode.SetTypeCode
implements TypeCode
{
public SetTypeCode(
String maxsize)
String maxsize,
String evaluated_maxsize)
{
super(maxsize);
super(maxsize, evaluated_maxsize);
}

@Override
public long maxSerializedSize(
long current_alignment)
{
long initial_alignment = current_alignment;
long maxsize = Long.parseLong(getMaxsize(), 10);
long maxsize = Long.parseLong(getEvaluatedMaxsize(), 10);

current_alignment += 4 + TypeCode.cdr_alignment(current_alignment, 4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ public class StringTypeCode extends com.eprosima.idl.parser.typecode.StringTypeC
{
public StringTypeCode(
int kind,
String maxsize)
String maxsize,
String evaluated_maxsize)
{
super(kind, maxsize);
super(kind, maxsize, evaluated_maxsize);
}

@Override
public long maxSerializedSize(
long current_alignment)
{
long initial_alignment = current_alignment;
long maxsize = Long.parseLong(getMaxsize(), 10);
long maxsize = Long.parseLong(getEvaluatedMaxsize(), 10);

switch (getKind())
{
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/dds-types-test

0 comments on commit 7df0be7

Please sign in to comment.