You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Christofer Dutz <ch...@c-ware.de> on 2020/06/15 09:39:30 UTC
Changes to the code generation
Hi all,
the last few days and especially during the weekend I worked hard on the freemarker based code generation.
After making the code-generation a lot better for C I extracted common code into a new BaseFreemarkerLanguageTemplateHelper class which is now the base of the Java and the C code generation helper. It generally contains methods for type, checks and generic operations (Like listing up the names of all types referenced in a given definition … It resolves the types of expressions etc.)
I completely overworked the discriminator code … you can now use as many discriminator fields as you like. And you no longer need to use these strange discriminatorValuex[0] expressions, which you actually have no reference to where they come from. Now everything is typesafe and should be a lot cleaner.
As an example the S7 mspec changed from:
[discriminatedType 'S7Payload' [uint 8 'messageType', S7Parameter 'parameter']
[typeSwitch 'parameter.discriminatorValues[0]', 'messageType'
['0x04','0x03' S7PayloadReadVarResponse
[array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems' ['lastItem']]
]
['0x05','0x01' S7PayloadWriteVarRequest
[array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)' ['lastItem']]
]
['0x05','0x03' S7PayloadWriteVarResponse
[array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
]
['0x00','0x07' S7PayloadUserData
[array S7PayloadUserDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterUserData).items)' ['CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuFunctionType']]
]
]
]
To:
[discriminatedType 'S7Payload' [uint 8 'messageType', S7Parameter 'parameter']
[typeSwitch 'parameter.parameterType', 'messageType'
['0x04','0x03' S7PayloadReadVarResponse
[array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems' ['lastItem']]
]
['0x05','0x01' S7PayloadWriteVarRequest
[array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)' ['lastItem']]
]
['0x05','0x03' S7PayloadWriteVarResponse
[array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
]
['0x00','0x07' S7PayloadUserData
[array S7PayloadUserDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterUserData).items)' ['CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuFunctionType']]
]
]
]
Which is quite a bit more intuitive, I think.
Also I had to extend the code generation plugin a bit … so we need to re-release that before we’re able to release something that contains my current changes.
As the changes also affect mspec files, I would really like to merge things from my current “feature/c-code-generation-tagged-unions” back to develop.
Feedback greatly appreciated.
Chris