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 2022/02/25 07:33:05 UTC
[plc4x] branch feature/cleaned-up-type-references updated: fix(codegen): fixed issue with manual arrays
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/cleaned-up-type-references
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/cleaned-up-type-references by this push:
new c84266a fix(codegen): fixed issue with manual arrays
c84266a is described below
commit c84266ab34a793fd1d1df48c0624b5735b227b5c
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Feb 25 08:30:22 2022 +0100
fix(codegen): fixed issue with manual arrays
---
.../src/main/resources/templates/c/pojo-template.c.ftlh | 2 +-
.../src/main/resources/templates/go/model-template.go.ftlh | 8 ++++----
.../src/main/resources/protocols/test/test.mspec | 14 +++++++-------
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh b/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
index 7a60215..ae85b3d 100644
--- a/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
+++ b/code-generation/language-c/src/main/resources/templates/c/pojo-template.c.ftlh
@@ -333,7 +333,7 @@ plc4c_return_code ${helper.getCTypeName(type.name)}_parse(plc4c_spi_read_buffer*
<#if indentContent> </#if> // Padding Field (padding)
<#if indentContent> </#if> {
-<#if indentContent> </#if> int _timesPadding = (int) ((plc4c_spi_read_has_more(readBuffer, ${helper.getNumBits(paddingField.type)})) && (${helper.toParseExpression(baseType, paddingField, paddingField.paddingCondition, parserArguments)}));
+<#if indentContent> </#if> int _timesPadding = (int) ((plc4c_spi_read_has_more(readBuffer, ${helper.getNumBits(simpleTypeReference)})) && (${helper.toParseExpression(baseType, paddingField, paddingField.paddingCondition, parserArguments)}));
<#if indentContent> </#if> while (_timesPadding-- > 0) {
<#if indentContent> </#if> // Just read the padding data and ignore it
<#if indentContent> </#if> ${helper.getLanguageTypeNameForField(field)} _paddingValue = ${helper.getNullValueForTypeReference(simpleTypeReference)};
diff --git a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
index d483270..985f09e 100644
--- a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
+++ b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
@@ -455,7 +455,7 @@ func (m *${type.name}) GetLengthInBitsConditional(lastItem bool) uint16 {
// Manual Array Field (${manualArrayField.name})
${manualArrayField.name} := m.${manualArrayField.name?cap_first}<#-- TODO: ugly workaround for missing static evaluation-->
- lengthInBits += ${helper.toParseExpression(manualArrayField, helper.intTypeReference, manualArrayField.lengthExpression, parserArguments)} * 8
+ lengthInBits += uint16(${helper.toParseExpression(manualArrayField, helper.intTypeReference, manualArrayField.lengthExpression, parserArguments)})
<#break>
<#case "manual">
<#assign manualField = field.asManualField().orElseThrow()>
@@ -625,13 +625,13 @@ func (m *${type.name}) GetParentLengthInBits() uint16 {
<#assign arrayElementType = manualArrayField.type.elementTypeReference>
// Manual Array Field (${manualArrayField.name})
- lengthInBits += ${helper.toParseExpression(manualArrayField, arrayElementType, manualArrayField.lengthExpression, parserArguments)} * 8
+ lengthInBits += uint16(${helper.toParseExpression(manualArrayField, arrayElementType, manualArrayField.lengthExpression, parserArguments)})
<#break>
<#case "manual">
<#assign manualField = field.asManualField().orElseThrow()>
// Manual Field (${manualField.name})
- lengthInBits += ${helper.toParseExpression(manualField, manualField.type, manualField.lengthExpression, parserArguments)} * 8
+ lengthInBits += uint16(${helper.toParseExpression(manualField, manualField.type, manualField.lengthExpression, parserArguments)})
<#break>
<#case "optional">
<#assign optionalField = field.asOptionalField().orElseThrow()>
@@ -987,7 +987,7 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if hasParserArguments>, ${pa
<#if field.isCountArrayField()>
// Count array
_${manualArrayField.name}Count := ${helper.toParseExpression(manualArrayField, helper.intTypeReference, manualArrayField.loopExpression, parserArguments)}
- ${helper.getLanguageTypeNameForField(field)} ${manualArrayField.name} = new ${helper.getLanguageTypeNameForField(field)}[_${manualArrayField.name}Count]
+ ${manualArrayField.name} := make(${helper.getLanguageTypeNameForField(field)}, _${manualArrayField.name}Count)
for i := 0; i < _${manualArrayField.name}Count; i++ {
${manualArrayField.name}[i] = (${helper.getLanguageTypeNameForField(field)}) (${helper.toParseExpression(manualArrayField, arrayElementType, manualArrayField.parseExpression, parserArguments)})
}
diff --git a/code-generation/protocol-test/src/main/resources/protocols/test/test.mspec b/code-generation/protocol-test/src/main/resources/protocols/test/test.mspec
index 20dbda6..213ff13 100644
--- a/code-generation/protocol-test/src/main/resources/protocols/test/test.mspec
+++ b/code-generation/protocol-test/src/main/resources/protocols/test/test.mspec
@@ -151,13 +151,13 @@
]
[type ManualArrayTypeTest
- [manualArray bit bitField count 'true' 'STATIC_CALL("parseBit", readBuffer)' 'STATIC_CALL("serializeBit", writeBuffer, _value)' '1']
- [manualArray byte byteField count 'true' 'STATIC_CALL("parseByte", readBuffer)' 'STATIC_CALL("serializeByte", writeBuffer, _value)' '5']
- [manualArray int 8 intField count 'true' 'STATIC_CALL("parseInt8", readBuffer)' 'STATIC_CALL("serializeInt8", writeBuffer, _value)' '5']
- [manualArray uint 8 uintField count 'true' 'STATIC_CALL("parseUint8", readBuffer)' 'STATIC_CALL("serializeUint8", writeBuffer, _value)' '5']
- [manualArray float 32 floatField count 'true' 'STATIC_CALL("parseFloat", readBuffer)' 'STATIC_CALL("serializeFloat", writeBuffer, _value)' '20']
- [manualArray float 64 doubleField count 'true' 'STATIC_CALL("parseDouble", readBuffer)' 'STATIC_CALL("serializeDouble", writeBuffer, _value)' '40']
- [manualArray string 8 stringField count 'true' 'STATIC_CALL("parseString", readBuffer)' 'STATIC_CALL("serializeString", writeBuffer, _value)' '5']
+ [manualArray bit bitField count '1' 'STATIC_CALL("parseBit", readBuffer)' 'STATIC_CALL("serializeBit", writeBuffer, _value)' '1']
+ [manualArray byte byteField count '1' 'STATIC_CALL("parseByte", readBuffer)' 'STATIC_CALL("serializeByte", writeBuffer, _value)' '5']
+ [manualArray int 8 intField count '1' 'STATIC_CALL("parseInt8", readBuffer)' 'STATIC_CALL("serializeInt8", writeBuffer, _value)' '5']
+ [manualArray uint 8 uintField count '1' 'STATIC_CALL("parseUint8", readBuffer)' 'STATIC_CALL("serializeUint8", writeBuffer, _value)' '5']
+ [manualArray float 32 floatField count '1' 'STATIC_CALL("parseFloat", readBuffer)' 'STATIC_CALL("serializeFloat", writeBuffer, _value)' '20']
+ [manualArray float 64 doubleField count '1' 'STATIC_CALL("parseDouble", readBuffer)' 'STATIC_CALL("serializeDouble", writeBuffer, _value)' '40']
+ [manualArray string 8 stringField count '1' 'STATIC_CALL("parseString", readBuffer)' 'STATIC_CALL("serializeString", writeBuffer, _value)' '5']
]
//TODO: Checksums fields are not supported in C