Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21346] Fix generation for new kind of constants #151

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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