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/07/28 12:46:40 UTC
[plc4x] 02/03: fix(codegen/plc4go): fixed issue with unnecessary casting when using bitwise operators
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
commit 514e03b25d75702bfe8a4a57f4bfa1550d741571
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jul 28 14:27:32 2022 +0200
fix(codegen/plc4go): fixed issue with unnecessary casting when using bitwise operators
---
.../plc4x/language/go/GoLanguageTemplateHelper.java | 10 ++++++++++
plc4go/protocols/cbus/readwrite/model/CALReplyLong.go | 4 ++--
.../cbus/readwrite/model/CBusPointToPointCommand.go | 4 ++--
plc4go/protocols/cbus/readwrite/model/EncodedReply.go | 16 ++++++++--------
.../model/MeasurementDataChannelMeasurementData.go | 4 ++--
.../readwrite/model/MonitoredSALLongFormSmartMode.go | 4 ++--
6 files changed, 26 insertions(+), 16 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 f8fe2106f..181c4264e 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
@@ -633,6 +633,16 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp
String aExpression = toExpression(field, null, a, parserArguments, serializerArguments, serialize, suppressPointerAccessOverride);
String bExpression = toExpression(field, null, b, parserArguments, serializerArguments, serialize, suppressPointerAccessOverride);
return tracer + "bool((" + aExpression + ") " + operation + " (" + bExpression + "))";
+ case ">>":
+ case "<<":
+ case "|":
+ case "&":
+ tracer = tracer.dive("bitwise");
+ // We don't want casts here
+ return tracer +
+ toExpression(field, fieldType, a, parserArguments, serializerArguments, serialize, false) +
+ operation + " " +
+ toExpression(field, fieldType, b, parserArguments, serializerArguments, serialize, false);
default:
tracer = tracer.dive("default");
if (fieldType instanceof StringTypeReference) {
diff --git a/plc4go/protocols/cbus/readwrite/model/CALReplyLong.go b/plc4go/protocols/cbus/readwrite/model/CALReplyLong.go
index 040b94740..40264fdfb 100644
--- a/plc4go/protocols/cbus/readwrite/model/CALReplyLong.go
+++ b/plc4go/protocols/cbus/readwrite/model/CALReplyLong.go
@@ -133,7 +133,7 @@ func (m *_CALReplyLong) GetIsUnitAddress() bool {
_ = reservedByte
replyNetwork := m.ReplyNetwork
_ = replyNetwork
- return bool(bool(((m.GetTerminatingByte()) & (0xff)) == (0x00)))
+ return bool(bool((m.GetTerminatingByte() & 0xff) == (0x00)))
}
///////////////////////
@@ -246,7 +246,7 @@ func CALReplyLongParse(readBuffer utils.ReadBuffer, cBusOptions CBusOptions, req
readBuffer.Reset(currentPos)
// Virtual field
- _isUnitAddress := bool(((terminatingByte) & (0xff)) == (0x00))
+ _isUnitAddress := bool((terminatingByte & 0xff) == (0x00))
isUnitAddress := bool(_isUnitAddress)
_ = isUnitAddress
diff --git a/plc4go/protocols/cbus/readwrite/model/CBusPointToPointCommand.go b/plc4go/protocols/cbus/readwrite/model/CBusPointToPointCommand.go
index c72d7f3d0..8a586a9fe 100644
--- a/plc4go/protocols/cbus/readwrite/model/CBusPointToPointCommand.go
+++ b/plc4go/protocols/cbus/readwrite/model/CBusPointToPointCommand.go
@@ -98,7 +98,7 @@ func (m *_CBusPointToPointCommand) GetCalData() CALData {
///////////////////////
func (m *_CBusPointToPointCommand) GetIsDirect() bool {
- return bool(bool(((m.GetBridgeAddressCountPeek()) & (0x00FF)) == (0x0000)))
+ return bool(bool((m.GetBridgeAddressCountPeek() & 0x00FF) == (0x0000)))
}
///////////////////////
@@ -160,7 +160,7 @@ func CBusPointToPointCommandParse(readBuffer utils.ReadBuffer, cBusOptions CBusO
readBuffer.Reset(currentPos)
// Virtual field
- _isDirect := bool(((bridgeAddressCountPeek) & (0x00FF)) == (0x0000))
+ _isDirect := bool((bridgeAddressCountPeek & 0x00FF) == (0x0000))
isDirect := bool(_isDirect)
_ = isDirect
diff --git a/plc4go/protocols/cbus/readwrite/model/EncodedReply.go b/plc4go/protocols/cbus/readwrite/model/EncodedReply.go
index 5b9e212e6..53b59b2a3 100644
--- a/plc4go/protocols/cbus/readwrite/model/EncodedReply.go
+++ b/plc4go/protocols/cbus/readwrite/model/EncodedReply.go
@@ -98,19 +98,19 @@ func (m *_EncodedReply) GetPeekedByte() byte {
///////////////////////
func (m *_EncodedReply) GetIsMonitoredSAL() bool {
- return bool(bool(((m.GetPeekedByte()) & (0x3F)) == (0x05)))
+ return bool(bool((m.GetPeekedByte() & 0x3F) == (0x05)))
}
func (m *_EncodedReply) GetIsCalCommand() bool {
- return bool(bool(bool(((m.GetPeekedByte())&(0x3F)) == (0x06))) || bool(m.RequestContext.GetSendCalCommandBefore()))
+ return bool(bool(bool((m.GetPeekedByte()&0x3F) == (0x06))) || bool(m.RequestContext.GetSendCalCommandBefore()))
}
func (m *_EncodedReply) GetIsStandardFormatStatus() bool {
- return bool(bool(bool(((m.GetPeekedByte())&(0xC0)) == (0xC0))) && bool(!(m.CBusOptions.GetExstat())))
+ return bool(bool(bool((m.GetPeekedByte()&0xC0) == (0xC0))) && bool(!(m.CBusOptions.GetExstat())))
}
func (m *_EncodedReply) GetIsExtendedFormatStatus() bool {
- return bool(bool(bool(((m.GetPeekedByte())&(0xE0)) == (0xE0))) && bool(bool(bool(m.CBusOptions.GetExstat()) || bool(m.RequestContext.GetSendStatusRequestLevelBefore()))))
+ return bool(bool(bool((m.GetPeekedByte()&0xE0) == (0xE0))) && bool(bool(bool(m.CBusOptions.GetExstat()) || bool(m.RequestContext.GetSendStatusRequestLevelBefore()))))
}
///////////////////////
@@ -175,22 +175,22 @@ func EncodedReplyParse(readBuffer utils.ReadBuffer, cBusOptions CBusOptions, req
readBuffer.Reset(currentPos)
// Virtual field
- _isMonitoredSAL := bool(((peekedByte) & (0x3F)) == (0x05))
+ _isMonitoredSAL := bool((peekedByte & 0x3F) == (0x05))
isMonitoredSAL := bool(_isMonitoredSAL)
_ = isMonitoredSAL
// Virtual field
- _isCalCommand := bool(bool(((peekedByte)&(0x3F)) == (0x06))) || bool(requestContext.GetSendCalCommandBefore())
+ _isCalCommand := bool(bool((peekedByte&0x3F) == (0x06))) || bool(requestContext.GetSendCalCommandBefore())
isCalCommand := bool(_isCalCommand)
_ = isCalCommand
// Virtual field
- _isStandardFormatStatus := bool(bool(((peekedByte)&(0xC0)) == (0xC0))) && bool(!(cBusOptions.GetExstat()))
+ _isStandardFormatStatus := bool(bool((peekedByte&0xC0) == (0xC0))) && bool(!(cBusOptions.GetExstat()))
isStandardFormatStatus := bool(_isStandardFormatStatus)
_ = isStandardFormatStatus
// Virtual field
- _isExtendedFormatStatus := bool(bool(((peekedByte)&(0xE0)) == (0xE0))) && bool(bool(bool(cBusOptions.GetExstat()) || bool(requestContext.GetSendStatusRequestLevelBefore())))
+ _isExtendedFormatStatus := bool(bool((peekedByte&0xE0) == (0xE0))) && bool(bool(bool(cBusOptions.GetExstat()) || bool(requestContext.GetSendStatusRequestLevelBefore())))
isExtendedFormatStatus := bool(_isExtendedFormatStatus)
_ = isExtendedFormatStatus
diff --git a/plc4go/protocols/cbus/readwrite/model/MeasurementDataChannelMeasurementData.go b/plc4go/protocols/cbus/readwrite/model/MeasurementDataChannelMeasurementData.go
index d76919c82..68c55e7a5 100644
--- a/plc4go/protocols/cbus/readwrite/model/MeasurementDataChannelMeasurementData.go
+++ b/plc4go/protocols/cbus/readwrite/model/MeasurementDataChannelMeasurementData.go
@@ -124,7 +124,7 @@ func (m *_MeasurementDataChannelMeasurementData) GetLsb() uint8 {
///////////////////////
func (m *_MeasurementDataChannelMeasurementData) GetRawValue() uint16 {
- return uint16(uint16(uint16(m.GetMsb())<<uint16(uint16(8))) | uint16(m.GetLsb()))
+ return uint16(m.GetMsb()<<uint16(8) | m.GetLsb())
}
func (m *_MeasurementDataChannelMeasurementData) GetValue() float64 {
@@ -260,7 +260,7 @@ func MeasurementDataChannelMeasurementDataParse(readBuffer utils.ReadBuffer) (Me
lsb := _lsb
// Virtual field
- _rawValue := uint16(uint16(msb)<<uint16(uint16(8))) | uint16(lsb)
+ _rawValue := msb<<uint16(8) | lsb
rawValue := uint16(_rawValue)
_ = rawValue
diff --git a/plc4go/protocols/cbus/readwrite/model/MonitoredSALLongFormSmartMode.go b/plc4go/protocols/cbus/readwrite/model/MonitoredSALLongFormSmartMode.go
index e9c74c200..76e974282 100644
--- a/plc4go/protocols/cbus/readwrite/model/MonitoredSALLongFormSmartMode.go
+++ b/plc4go/protocols/cbus/readwrite/model/MonitoredSALLongFormSmartMode.go
@@ -141,7 +141,7 @@ func (m *_MonitoredSALLongFormSmartMode) GetIsUnitAddress() bool {
_ = replyNetwork
salData := m.SalData
_ = salData
- return bool(bool(((m.GetTerminatingByte()) & (0xff)) == (0x00)))
+ return bool(bool((m.GetTerminatingByte() & 0xff) == (0x00)))
}
///////////////////////
@@ -260,7 +260,7 @@ func MonitoredSALLongFormSmartModeParse(readBuffer utils.ReadBuffer, cBusOptions
readBuffer.Reset(currentPos)
// Virtual field
- _isUnitAddress := bool(((terminatingByte) & (0xff)) == (0x00))
+ _isUnitAddress := bool((terminatingByte & 0xff) == (0x00))
isUnitAddress := bool(_isUnitAddress)
_ = isUnitAddress