Skip to content

Commit

Permalink
Fix usage of is_plain() with extensibility values (#226)
Browse files Browse the repository at this point in the history
* Refs #18687. Fix is_plain generated code

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #18687. Add '-default_extensibility' option

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #18687. Improve calculation of maxSerializedSize in containers

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #18687. Apply suggestions

Signed-off-by: Ricardo González Moreno <[email protected]>

---------

Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware authored Sep 18, 2023
1 parent da185d2 commit cd5b8fd
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 16 deletions.
34 changes: 34 additions & 0 deletions src/main/java/com/eprosima/fastdds/fastddsgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.eprosima.idl.generator.manager.TemplateManager;
import com.eprosima.idl.parser.grammar.IDLLexer;
import com.eprosima.idl.parser.grammar.IDLParser;
import com.eprosima.idl.parser.tree.Annotation;
import com.eprosima.idl.parser.tree.AnnotationDeclaration;
import com.eprosima.idl.parser.tree.AnnotationMember;
import com.eprosima.idl.parser.tree.Specification;
Expand Down Expand Up @@ -308,6 +309,33 @@ else if (arg.equals("-cs"))
{
m_case_sensitive = true;
}
else if (arg.equals("-de") || arg.equals("-default_extensibility"))
{
if (count < args.length)
{
String extensibility = args[count++];
if (extensibility.equals(Annotation.final_str))
{
TypeCode.default_extensibility = TypeCode.ExtensibilityKind.FINAL;
}
else if (extensibility.equals(Annotation.appendable_str))
{
TypeCode.default_extensibility = TypeCode.ExtensibilityKind.APPENDABLE;
}
else if (extensibility.equals(Annotation.mutable_str))
{
TypeCode.default_extensibility = TypeCode.ExtensibilityKind.MUTABLE;
}
else
{
throw new BadArgumentException("Extensibility value " + extensibility + " is not valid");
}
}
else
{
throw new BadArgumentException("No extensibility value after -default_extensibility argument");
}
}
else // TODO: More options: -rpm, -debug
{
throw new BadArgumentException("Unknown argument " + arg);
Expand Down Expand Up @@ -512,6 +540,12 @@ public static void printHelp()
System.out.println("\t\t-cs: IDL grammar apply case sensitive matching.");
System.out.println("\t\t-test: executes FastDDSGen tests.");
System.out.println("\t\t-python: generates python bindings for the generated types.");
System.out.print("\t\t-default_extensibility | -de <ext>: sets the default extensibility for types without");
System.out.println(" the @extensibility annotation.");
System.out.println("\t\t Values:");
System.out.println("\t\t\t* " + Annotation.final_str);
System.out.println("\t\t\t* " + Annotation.appendable_str + " (default)");
System.out.println("\t\t\t* " + Annotation.mutable_str);
System.out.println("\tand the supported input files are:");
System.out.println("\t* IDL files.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;

public class AliasTypeCode extends com.eprosima.idl.parser.typecode.AliasTypeCode
implements TypeCode
{
Expand All @@ -31,6 +33,14 @@ public long maxSerializedSize(
return ((TypeCode) getTypedefContentTypeCode()).maxSerializedSize(current_alignment);
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
return ((TypeCode) getTypedefContentTypeCode()).maxPlainTypeSerializedSize(current_alignment, align64);
}

public boolean isNotZeroArray()
{
if (super.getContentTypeCode() instanceof ArrayTypeCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;

public class ArrayTypeCode extends com.eprosima.idl.parser.typecode.ArrayTypeCode
implements TypeCode
{
Expand All @@ -37,9 +39,44 @@ public long maxSerializedSize(
size *= Long.parseLong(getDimensions().get(count), 10);
}

for (long count = 0; count < size; ++count)
if (0 < size)
{
current_alignment += ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);

if (1 < size)
{
long element_size_after_first = ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);
current_alignment += element_size_after_first * (size - 1);
}
}

return current_alignment - initial_alignment;
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
long initial_alignment = current_alignment;

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

if (0 < size)
{
current_alignment += ((TypeCode)getContentTypeCode()).maxPlainTypeSerializedSize(
current_alignment, align64);

if (1 < size)
{
long element_size_after_first = ((TypeCode)getContentTypeCode()).maxPlainTypeSerializedSize(
current_alignment, align64);
current_alignment += element_size_after_first * (size - 1);
}
}

return current_alignment - initial_alignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ public BitmaskTypeCode(
@Override
public long maxSerializedSize(
long current_alignment)
{
return maxPlainTypeSerializedSize(current_alignment, 8);
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64)
{
long initial_alignment = current_alignment;
long size = Long.parseLong(getSize(), 10);

current_alignment += size + TypeCode.cdr_alignment(current_alignment, size);
current_alignment += size + TypeCode.cdr_alignment(current_alignment, 4 < size ? align64 : size);

return current_alignment - initial_alignment;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public BitsetTypeCode(
@Override
public long maxSerializedSize(
long current_alignment)
{
return maxPlainTypeSerializedSize(current_alignment, 8);
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64)
{
long initial_alignment = current_alignment;

Expand All @@ -49,7 +57,7 @@ else if (33 > full_bit_size)
}
else
{
current_alignment += 8 + TypeCode.cdr_alignment(current_alignment, 8);
current_alignment += 8 + TypeCode.cdr_alignment(current_alignment, align64);
}

return current_alignment - initial_alignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ public EnumTypeCode(
@Override
public long maxSerializedSize(
long current_alignment)
{
return maxPlainTypeSerializedSize(current_alignment, 8);
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64)
{
long initial_alignment = current_alignment;

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

return current_alignment - initial_alignment;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;

public class MapTypeCode extends com.eprosima.idl.parser.typecode.MapTypeCode
implements TypeCode
{
Expand All @@ -40,13 +42,28 @@ public long maxSerializedSize(

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

for (long count = 0; count < maxsize; ++count)
if (0 < maxsize)
{
current_alignment += ((TypeCode)getKeyTypeCode()).maxSerializedSize(current_alignment);
current_alignment += ((TypeCode)getValueTypeCode()).maxSerializedSize(current_alignment);

if (1 < maxsize)
{
long element_size_after_first = ((TypeCode)getKeyTypeCode()).maxSerializedSize(current_alignment);
element_size_after_first += ((TypeCode)getValueTypeCode()).maxSerializedSize(
current_alignment + element_size_after_first);
current_alignment += element_size_after_first * (maxsize - 1);
}
}

return current_alignment - initial_alignment;
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
throw new RuntimeGenerationException("MapTypeCode::maxPlainTypeSerializedSize(): Maps are not plain types.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,26 @@ public PrimitiveTypeCode(
@Override
public long maxSerializedSize(
long current_alignment)
{
return maxPlainTypeSerializedSize(current_alignment, 8);
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64)
{
long initial_alignment = current_alignment;

switch (getKind())
{
case com.eprosima.idl.parser.typecode.Kind.KIND_LONGDOUBLE:
current_alignment += 16 + TypeCode.cdr_alignment(current_alignment, 8);
current_alignment += 16 + TypeCode.cdr_alignment(current_alignment, align64);
break;
case com.eprosima.idl.parser.typecode.Kind.KIND_DOUBLE:
case com.eprosima.idl.parser.typecode.Kind.KIND_LONGLONG:
case com.eprosima.idl.parser.typecode.Kind.KIND_ULONGLONG:
current_alignment += 8 + TypeCode.cdr_alignment(current_alignment, 8);
current_alignment += 8 + TypeCode.cdr_alignment(current_alignment, align64);
break;
case com.eprosima.idl.parser.typecode.Kind.KIND_LONG:
case com.eprosima.idl.parser.typecode.Kind.KIND_ULONG:
Expand All @@ -61,5 +69,4 @@ public long maxSerializedSize(

return current_alignment - initial_alignment;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;

public class SequenceTypeCode extends com.eprosima.idl.parser.typecode.SequenceTypeCode
implements TypeCode
{
Expand Down Expand Up @@ -48,9 +50,15 @@ public long maxSerializedSize(

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

for (long count = 0; count < maxsize; ++count)
if (0 < maxsize)
{
current_alignment += ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);

if (1 < maxsize)
{
long element_size_after_first = ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);
current_alignment += element_size_after_first * (maxsize - 1);
}
}

if (should_set_and_unset)
Expand All @@ -61,4 +69,12 @@ public long maxSerializedSize(
return current_alignment - initial_alignment;
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
throw new RuntimeGenerationException("MapTypeCode::maxPlainTypeSerializedSize(): Sequences are not plain types.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;

public class SetTypeCode extends com.eprosima.idl.parser.typecode.SetTypeCode
implements TypeCode
{
Expand All @@ -32,12 +34,26 @@ public long maxSerializedSize(

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

for (long count = 0; count < maxsize; ++count)
if (0 < maxsize)
{
current_alignment += ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);

if (1 < maxsize)
{
long element_size_after_first = ((TypeCode)getContentTypeCode()).maxSerializedSize(current_alignment);
current_alignment += element_size_after_first * (maxsize - 1);
}
}

return current_alignment - initial_alignment;
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
throw new RuntimeGenerationException("MapTypeCode::maxPlainTypeSerializedSize(): Sets are not plain types.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.eprosima.fastdds.idl.parser.typecode;

import com.eprosima.idl.parser.exception.RuntimeGenerationException;
import com.eprosima.idl.parser.typecode.Kind;

public class StringTypeCode extends com.eprosima.idl.parser.typecode.StringTypeCode
Expand Down Expand Up @@ -46,4 +47,12 @@ public long maxSerializedSize(
return current_alignment - initial_alignment;
}

@Override
public long maxPlainTypeSerializedSize(
long current_alignment,
long align64) throws RuntimeGenerationException
{
throw new RuntimeGenerationException("StringTypeCode::maxPlainTypeSerializedSize(): Strings are not plain types.");
}

}
Loading

0 comments on commit cd5b8fd

Please sign in to comment.