Skip to content

Commit

Permalink
Refs #21343. Fixes #150
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware committed Jul 11, 2024
1 parent 03fbf21 commit 190a402
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/main/antlr/com/eprosima/idl/parser/grammar/IDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,13 @@ const_decl [AnnotationDeclaration annotation] returns [Pair<ConstDeclaration, Te
{
if(typecode != null)
{
constDecl = new ConstDeclaration(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), constName, typecode, constValue, tk);
constDecl = new ConstDeclaration(ctx.getScopeFile(), ctx.isInScopedFile(), ctx.getScope(), constName,
typecode, constValue,
typecode.isPrimitive()
&& !typecode.isIsEnumType()
&& !typecode.isIsCharType()
&& !typecode.isIsWCharType()
? ctx.evaluate_literal(constValue) : constValue, tk);
if(constTemplates != null)
{
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/eprosima/idl/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -1469,13 +1469,15 @@ public String evaluate_literal(
{
ConstDeclaration const_decl = (ConstDeclaration)definition;

if (const_decl.getTypeCode().isPrimitive() || const_decl.getTypeCode().isIsStringType() || const_decl.getTypeCode().isIsWStringType())
if ((const_decl.getTypeCode().isPrimitive() && !const_decl.getTypeCode().isIsEnumType())
|| const_decl.getTypeCode().isIsStringType()
|| const_decl.getTypeCode().isIsWStringType())
{
const_str = const_str + ";" + const_decl.getFormatedScopedname() + "=" + const_decl.getValue();
const_str = const_str + ";" + const_decl.getFormatedScopedname() + "=" + const_decl.getEvaluatedValue();

if (const_decl.getScope() == getScope())
{
const_str = const_str + ";" + const_decl.getName() + "=" + const_decl.getValue();
const_str = const_str + ";" + const_decl.getName() + "=" + const_decl.getEvaluatedValue();
}
}
}
Expand All @@ -1492,7 +1494,7 @@ public String evaluate_literal(
}
catch (ScriptException se)
{
throw new ParseException(null, "Error evaluating array dimension: " + aux_str);
throw new ParseException(null, "Error evaluating expression: " + aux_str);
}

return aux_str;
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/eprosima/idl/parser/tree/ConstDeclaration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@

public class ConstDeclaration extends DefinitionContainer implements Definition, Export
{
public ConstDeclaration(String scopeFile, boolean isInScope, String scope, String name, TypeCode typecode, String value, Token token)
public ConstDeclaration(
String scopeFile,
boolean isInScope,
String scope,
String name,
TypeCode typecode,
String value,
String evaluated_value,
Token token)
{
super(scopeFile, isInScope, scope, name, token);

m_typecode = typecode;
m_value = value;
evaluated_value_ =evaluated_value;
// Set as parent to the Typecode.
m_typecode.setParent(this);
}
Expand All @@ -36,6 +45,11 @@ public TypeCode getTypeCode()
return m_typecode;
}

public String getEvaluatedValue()
{
return evaluated_value_;
}

public String getValue()
{
return m_value;
Expand Down Expand Up @@ -99,6 +113,7 @@ public boolean isIsAnnotation()
return false;
}

private String evaluated_value_ = null;
private TypeCode m_typecode = null;
private String m_value = null;
private Object m_parent = null;
Expand Down

0 comments on commit 190a402

Please sign in to comment.