Skip to content

Commit

Permalink
Fix API for TypeObject code generation (#110)
Browse files Browse the repository at this point in the history
* Refs #19595: code style

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19595: return annotation default value

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19595: add Alias API for container types aliased

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19595: fix typos in primitive API

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19595: explictly override

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

---------

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
  • Loading branch information
JLBuenoLopez authored Nov 28, 2023
1 parent e385a8e commit a11f9ca
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/eprosima/idl/parser/tree/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public String getROS2Scopedname()
public boolean addValue(String value)
{
if(m_members.size() != 1)
{
return false;
}

((AnnotationMember)m_members.values().toArray()[0]).setValue(value);

Expand All @@ -125,14 +127,19 @@ public boolean addValue(String attribute, String value)
member.getEnumStringValue();
}
else
{
return false;
}

return true;
}

public String getValue()
{
if(m_members.size() != 1) return null;
if(m_members.size() != 1)
{
return null;
}

return ((AnnotationMember)m_members.values().toArray()[0]).getValue();
}
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,26 @@ public TypeCode getTypecode()

public String getValue()
{
if (m_typecode.isIsType_c()) // Enum
if (m_typecode.isIsEnumType())
{
EnumTypeCode enumTC = (EnumTypeCode)m_typecode;
int idx = 0;
int default_idx = 0;
for (Member m : enumTC.getMembers())
{
if (m.getName().equals(m_value))
{
return Integer.toString(idx);
}
else if (m.isAnnotationDefaultLiteral())
{
default_idx = idx;
}
idx++;
}
return Integer.toString(default_idx);
}
if (m_typecode.isIsType_d()) // String
else if (m_typecode.isIsStringType() || m_typecode.isIsWStringType())
{
if (m_value != null)
{
Expand All @@ -74,6 +80,19 @@ public String getValue()
return m_value.substring(1, m_value.length() - 1);
}
}
if (m_typecode.isIsWStringType())
{
return "L\"\"";
}
return "";
}
else if (m_typecode.isPrimitive())
{
if (m_value != null)
{
return m_value;
}
return m_typecode.getInitialValue();
}
return m_value;
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ public String getSize()
return super.getContentTypeCode().getSize();
}

public String getEvaluatedMaxsize()
{
return super.getContentTypeCode().getEvaluatedMaxsize();
}

public List<String> getDimensions()
{
if (super.getContentTypeCode() instanceof ArrayTypeCode)
Expand All @@ -326,6 +331,16 @@ public List<String> getDimensions()
return null;
}

public List<String> getEvaluatedDimensions()
{
if (super.getContentTypeCode() instanceof ArrayTypeCode)
{
return ((ArrayTypeCode) super.getContentTypeCode()).getEvaluatedDimensions();
}

return null;
}

/*** End of functions that alias has to export because some typecodes have them*/

private String m_name = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public String getIdlTypename()
return st.render();
}

@Override
public String getMaxsize()
{
if (m_maxsize == null)
Expand All @@ -102,6 +103,7 @@ public String getMaxsize()
return m_maxsize;
}

@Override
public String getEvaluatedMaxsize()
{
if (evaluated_maxsize_ == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,25 @@ public boolean isIsInt64Type()
}

@Override
public boolean isIsUint64Tpe()
public boolean isIsUint64Type()
{
return getKind() == Kind.KIND_ULONGLONG;
}

@Override
public boolean isIsFloat32()
public boolean isIsFloat32Type()
{
return getKind() == Kind.KIND_FLOAT;
}

@Override
public boolean isIsFloat64()
public boolean isIsFloat64Type()
{
return getKind() == Kind.KIND_DOUBLE;
}

@Override
public boolean isIsFloat128()
public boolean isIsFloat128Type()
{
return getKind() == Kind.KIND_LONGDOUBLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public String getMaxsize()
return m_maxsize;
}

@Override
public String getEvaluatedMaxsize()
{
if (evaluated_maxsize_ == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public String getIdlTypename()
return getIdlTypenameFromStringTemplate().toString();
}

@Override
public String getMaxsize()
{
if (m_maxsize == null)
Expand All @@ -106,6 +107,7 @@ public String getMaxsize()
return m_maxsize;
}

@Override
public String getEvaluatedMaxsize()
{
if (evaluated_maxsize_ == null)
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public String getMaxsize()
return null;
}

public String getEvaluatedMaxsize()
{
return null;
}

/*!
* @brief This function returns the size of the datatype. By default is null string.
* @return The size of the datatype.
Expand Down Expand Up @@ -267,22 +272,22 @@ public boolean isIsInt64Type()
return false;
}

public boolean isIsUint64Tpe()
public boolean isIsUint64Type()
{
return false;
}

public boolean isIsFloat32()
public boolean isIsFloat32Type()
{
return false;
}

public boolean isIsFloat64()
public boolean isIsFloat64Type()
{
return false;
}

public boolean isIsFloat128()
public boolean isIsFloat128Type()
{
return false;
}
Expand Down

0 comments on commit a11f9ca

Please sign in to comment.