You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2026/08/20 12:02:49 UTC
(plc4x) branch develop updated: fix(codegen/go): keep the operator when a static call takes a unary argument
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 700adc857e fix(codegen/go): keep the operator when a static call takes a unary argument
700adc857e is described below
commit 700adc857e32afb2b22e0d1e7833b86c08907fe5
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Aug 20 14:01:19 2026 +0200
fix(codegen/go): keep the operator when a static call takes a unary argument
An argument written as -1 in an mspec came out of the Go generator as 1. The
static-call renderer unwraps a unary term to reach its operand, because that is
what the branches below know how to handle - readBuffer, _value, _type, parser
arguments - but it dropped the operator on the way, and nothing downstream could
tell the difference.
The umas terminated-string helpers take the length that way: -1 selects
variable-length mode, so losing the sign silently switched them to a one byte
fixed width. Every symbol name in a data dictionary record would have truncated
to a single character and the record stream desynced on the first entry. Java
emits -(1) here and was always right.
The operator is now emitted around the operand, mirroring the operators
toUnaryTermExpression accepts, and an unrecognised one throws rather than
disappearing - which is how this managed to hide.
umas is the only mspec in the repository that passes a unary argument to a static
call, so regenerating touches its three record types and nothing else.
---
.../language/go/GoLanguageTemplateHelper.java | 24 +++++++++++++++++++++-
.../umas/readwrite/model/UmasDatatypeReference.go | 6 ++++--
.../umas/readwrite/model/UmasUDTDefinition.go | 6 ++++--
.../model/UmasUnlocatedVariableReference.go | 6 ++++--
4 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/code-generation/language/go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java b/code-generation/language/go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
index 5c3df6fe06..ef89ca7c5c 100644
--- a/code-generation/language/go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
+++ b/code-generation/language/go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java
@@ -1354,8 +1354,27 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp
if (i > 1) {
sb.append(", ");
}
+ // Unwrapping a unary term reaches its operand, which is what the branches below know how
+ // to render with the STATIC_CALL specific handling. The operator has to be emitted here
+ // instead, or it is simply lost: an argument written as -1 in the mspec came out as 1,
+ // which flipped the umas terminated-string helpers from variable length into a one byte
+ // fixed width. Operators mirror toUnaryTermExpression.
+ String unaryOperator = null;
if (arg instanceof UnaryTerm) {
- arg = ((UnaryTerm) arg).getA();
+ UnaryTerm unaryTerm = (UnaryTerm) arg;
+ unaryOperator = unaryTerm.getOperation();
+ switch (unaryOperator) {
+ case "!":
+ case "-":
+ sb.append(unaryOperator).append("(");
+ break;
+ case "()":
+ sb.append("(");
+ break;
+ default:
+ throw new FreemarkerException("Unsupported unary operation type " + unaryOperator);
+ }
+ arg = unaryTerm.getA();
}
if (arg instanceof VariableLiteral) {
tracer = tracer.dive("VariableLiteral nr." + i);
@@ -1418,6 +1437,9 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp
} else {
throw new FreemarkerException(arg.getClass().getName());
}
+ if (unaryOperator != null) {
+ sb.append(")");
+ }
}
sb.append(")");
return tracer + sb.toString();
diff --git a/plc4go/protocols/umas/readwrite/model/UmasDatatypeReference.go b/plc4go/protocols/umas/readwrite/model/UmasDatatypeReference.go
index 2fe34d6047..368484091b 100644
--- a/plc4go/protocols/umas/readwrite/model/UmasDatatypeReference.go
+++ b/plc4go/protocols/umas/readwrite/model/UmasDatatypeReference.go
@@ -311,7 +311,7 @@ func (m *_UmasDatatypeReference) parse(ctx context.Context, readBuffer utils.Rea
}
m.reservedField0 = reservedField0
- value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, 1)), codegen.WithEncoding("UTF8"))
+ value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, -(1))), codegen.WithEncoding("UTF8"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'value' field"))
}
@@ -361,7 +361,9 @@ func (m *_UmasDatatypeReference) SerializeWithWriteBuffer(ctx context.Context, w
return errors.Wrap(err, "Error serializing 'reserved' field number 1")
}
- if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error { return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), 1) }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
+ if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error {
+ return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), -(1))
+ }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
return errors.Wrap(err, "Error serializing 'value' field")
}
diff --git a/plc4go/protocols/umas/readwrite/model/UmasUDTDefinition.go b/plc4go/protocols/umas/readwrite/model/UmasUDTDefinition.go
index 09ad5253da..159fb4a38f 100644
--- a/plc4go/protocols/umas/readwrite/model/UmasUDTDefinition.go
+++ b/plc4go/protocols/umas/readwrite/model/UmasUDTDefinition.go
@@ -299,7 +299,7 @@ func (m *_UmasUDTDefinition) parse(ctx context.Context, readBuffer utils.ReadBuf
}
m.Unknown4 = unknown4
- value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, 1)), codegen.WithEncoding("UTF8"))
+ value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, -(1))), codegen.WithEncoding("UTF8"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'value' field"))
}
@@ -345,7 +345,9 @@ func (m *_UmasUDTDefinition) SerializeWithWriteBuffer(ctx context.Context, write
return errors.Wrap(err, "Error serializing 'unknown4' field")
}
- if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error { return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), 1) }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
+ if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error {
+ return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), -(1))
+ }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
return errors.Wrap(err, "Error serializing 'value' field")
}
diff --git a/plc4go/protocols/umas/readwrite/model/UmasUnlocatedVariableReference.go b/plc4go/protocols/umas/readwrite/model/UmasUnlocatedVariableReference.go
index 7c189a4788..c320106bd6 100644
--- a/plc4go/protocols/umas/readwrite/model/UmasUnlocatedVariableReference.go
+++ b/plc4go/protocols/umas/readwrite/model/UmasUnlocatedVariableReference.go
@@ -323,7 +323,7 @@ func (m *_UmasUnlocatedVariableReference) parse(ctx context.Context, readBuffer
}
m.Unknown4 = unknown4
- value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, 1)), codegen.WithEncoding("UTF8"))
+ value, err := ReadManualField[string](ctx, "value", readBuffer, EnsureType[string](ParseTerminatedString(ctx, readBuffer, -(1))), codegen.WithEncoding("UTF8"))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'value' field"))
}
@@ -373,7 +373,9 @@ func (m *_UmasUnlocatedVariableReference) SerializeWithWriteBuffer(ctx context.C
return errors.Wrap(err, "Error serializing 'unknown4' field")
}
- if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error { return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), 1) }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
+ if err := WriteManualField[string](ctx, "value", func(ctx context.Context) error {
+ return SerializeTerminatedString(ctx, writeBuffer, m.GetValue(), -(1))
+ }, writeBuffer, codegen.WithEncoding("UTF8")); err != nil {
return errors.Wrap(err, "Error serializing 'value' field")
}