Skip to content

Prevent code duplication in python codegen

Like just discussed … Related comment: !57 (comment 64151)

E.g. the only difference between cSetCustomArray2DRegData and cSetCustomArray2DReg is:

            (data.is${fesaFieldName_upper}Available()) ? ${regName} = data.${fesaFieldName}.get(fesaDim1, fesaDim2) :
                                        ${regName} = pDevice->${fesaFieldName}.get(fesaDim1, fesaDim2${context});

Currently, that is done in the middle of the generated method.

So an improvement to reduce duplication could be, to just move the initialization/definition of ${regName} up to the head of the code-block, and then use the same template to generate the rest of the code-block.

Another approach could be, to actually call cSetCustomArray2DReg inside cSetCustomArray2DRegData in the generated code and pass ${regName} as a parameter.

Not sure which possibility is the best / possibly I forgot other options we have ... will leave that decision to you @m.marn.