Skip to content

Commit

Permalink
refactor(plc4go/codegen): fixed virtual field implementation
Browse files Browse the repository at this point in the history
+ Added parser arguments as field like in plc4j
+ fixed several bugs in code generation
  • Loading branch information
sruehl committed Feb 14, 2022
1 parent 33e07bd commit e02e64d
Show file tree
Hide file tree
Showing 693 changed files with 10,132 additions and 8,448 deletions.
Expand Up @@ -510,7 +510,7 @@ public boolean isEnumField(Field field) {
if (isSimpleTypeReference(typeReference)) {
return false;
}
TypeDefinition typeDefinition = getTypeDefinitionForTypeReference(typedField.getType());
TypeDefinition typeDefinition = getTypeDefinitionForTypeReference(typeReference);
return typeDefinition instanceof EnumTypeDefinition;
}

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -85,7 +85,7 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if parserArguments?has_conte
<#assign enumValue=helper.toParseExpression(null, parserArguments[discriminatorValueTerm?index].type, discriminatorValueTerm, parserArguments)>
<#assign enumValueWithoutTraces=tracer.removeTraces(enumValue)>
<#assign enumValueTraces=tracer.extractTraces(enumValue)>
${enumTypeTraces}${enumValueTraces}${enumTypeWithoutTraces}_${enumValueWithoutTraces}
${enumTypeTraces}${enumValueTraces}${enumTypeWithoutTraces}_${enumValueWithoutTraces?replace("Get","")?replace("()","")}
<#else>
${helper.toParseExpression(null, parserArguments[discriminatorValueTerm?index].type, discriminatorValueTerm, parserArguments)}
</#if>
Expand Down Expand Up @@ -204,6 +204,18 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if parserArguments?has_conte
}

func ${type.name}Serialize(writeBuffer utils.WriteBuffer, value api.PlcValue<#if parserArguments?has_content>, <#list parserArguments as parserArgument>${parserArgument.name} <#if helper.isComplexTypeReference(parserArgument.type) && !helper.isEnumTypeReference(parserArgument.type)>I</#if>${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}<#sep>, </#sep></#list></#if>) error {
<#if parserArguments?has_content>
m := struct {
<#list parserArguments as parserArgument>
${parserArgument.name?cap_first} <#if helper.isComplexTypeReference(parserArgument.type) && !helper.isEnumTypeReference(parserArgument.type)>I</#if>${helper.getLanguageTypeNameForTypeReference(parserArgument.type)}
</#list>
}{
<#list parserArguments as parserArgument>
${parserArgument.name?cap_first}: ${parserArgument.name},
</#list>
}
_ = m
</#if>
writeBuffer.PushContext("${type.name}")
switch {
<#assign defaultSet=false>
Expand All @@ -221,7 +233,7 @@ func ${type.name}Serialize(writeBuffer utils.WriteBuffer, value api.PlcValue<#if
<#assign enumValue=helper.toParseExpression(null, parserArguments[discriminatorValueTerm?index].type, discriminatorValueTerm, parserArguments)>
<#assign enumValueWithoutTraces=tracer.removeTraces(enumValue)>
<#assign enumValueTraces=tracer.extractTraces(enumValue)>
${enumTypeTraces}${enumValueTraces}${enumTypeWithoutTraces}_${enumValueWithoutTraces}
${enumTypeTraces}${enumValueTraces}${enumTypeWithoutTraces}_${enumValueWithoutTraces?replace("Get","")?replace("()","")}
<#else>
${helper.toParseExpression(null, parserArguments[discriminatorValueTerm?index].type, discriminatorValueTerm, parserArguments)}
</#if>
Expand Down
Expand Up @@ -162,13 +162,13 @@ func Cast${type.name}(structType interface{}) ${type.name} {
return castFunc(structType)
}

func (m ${type.name}) LengthInBits() uint16 {
func (m ${type.name}) GetLengthInBits() uint16 {
<#assign simpleTypeReference = type.type.asSimpleTypeReference().orElseThrow()>
return <#if type.type.isStringTypeReference()>0<#else>${simpleTypeReference.sizeInBits}</#if>
}

func (m ${type.name}) LengthInBytes() uint16 {
return m.LengthInBits() / 8
func (m ${type.name}) GetLengthInBytes() uint16 {
return m.GetLengthInBits() / 8
}

<#if type.type?has_content && helper.isSimpleTypeReference(type.type)>
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -522,10 +522,10 @@
<BACnetApplicationTagDate>
<payload>
<BACnetTagPayloadDate>
<yearMinus1900 dataType="int" bitLength="8">106</yearMinus1900>
<month dataType="int" bitLength="8">9</month>
<dayOfMonth dataType="int" bitLength="8">23</dayOfMonth>
<dayOfWeek dataType="int" bitLength="8">6</dayOfWeek>
<yearMinus1900 dataType="uint" bitLength="8">106</yearMinus1900>
<month dataType="uint" bitLength="8">9</month>
<dayOfMonth dataType="uint" bitLength="8">23</dayOfMonth>
<dayOfWeek dataType="uint" bitLength="8">6</dayOfWeek>
</BACnetTagPayloadDate>
</payload>
</BACnetApplicationTagDate>
Expand All @@ -545,10 +545,10 @@
<BACnetApplicationTagTime>
<payload>
<BACnetTagPayloadTime>
<hour dataType="int" bitLength="8">23</hour>
<minute dataType="int" bitLength="8">9</minute>
<second dataType="int" bitLength="8">54</second>
<fractional dataType="int" bitLength="8">0</fractional>
<hour dataType="uint" bitLength="8">23</hour>
<minute dataType="uint" bitLength="8">9</minute>
<second dataType="uint" bitLength="8">54</second>
<fractional dataType="uint" bitLength="8">0</fractional>
</BACnetTagPayloadTime>
</payload>
</BACnetApplicationTagTime>
Expand Down Expand Up @@ -7767,10 +7767,10 @@ make -f wp.mak clean</value>
<BACnetApplicationTagDate>
<payload>
<BACnetTagPayloadDate>
<yearMinus1900 dataType="int" bitLength="8">106</yearMinus1900>
<month dataType="int" bitLength="8">9</month>
<dayOfMonth dataType="int" bitLength="8">23</dayOfMonth>
<dayOfWeek dataType="int" bitLength="8">-1</dayOfWeek>
<yearMinus1900 dataType="uint" bitLength="8">106</yearMinus1900>
<month dataType="uint" bitLength="8">9</month>
<dayOfMonth dataType="uint" bitLength="8">23</dayOfMonth>
<dayOfWeek dataType="uint" bitLength="8">255</dayOfWeek>
</BACnetTagPayloadDate>
</payload>
</BACnetApplicationTagDate>
Expand All @@ -7790,10 +7790,10 @@ make -f wp.mak clean</value>
<BACnetApplicationTagTime>
<payload>
<BACnetTagPayloadTime>
<hour dataType="int" bitLength="8">23</hour>
<minute dataType="int" bitLength="8">21</minute>
<second dataType="int" bitLength="8">13</second>
<fractional dataType="int" bitLength="8">0</fractional>
<hour dataType="uint" bitLength="8">23</hour>
<minute dataType="uint" bitLength="8">21</minute>
<second dataType="uint" bitLength="8">13</second>
<fractional dataType="uint" bitLength="8">0</fractional>
</BACnetTagPayloadTime>
</payload>
</BACnetApplicationTagTime>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e02e64d

Please sign in to comment.