Skip to content

#679 PLCgen: Add constants support

Albert Hofkamp requested to merge 679-add-constants-support into develop

Constants are finally here for PLCgen.

Instead of previous implementations, this one doesn't check everything in the pre-checker.

Here, the target gets queried whether it supports each constant. If the answer is yes, it is kept and transformed. If the answer is no, it gets unfolded to the underlying value. It's nicely flexible in this way and gives a "best effort" towards constants.

Afterwards, I realized there is also a down-side to this. If you introduce constants for something, you don't know if they also actually exist in the generated code for a target. Theoretically you'd have to query the target explicitly for each constant to be sure.
On the other hand, under the assumption that targets are not so crazy to eg reject all even integer values, the problem is probably less bad than it looks at first sight. Therefore I decided to keep it like this for now.

I added the constants cif2plc test-cases too. They seem to produce the expected result, except for S7. The S7 result is understandable but somewhat weird. The pre-checker doesn't allow to keep constants despite the override that is expressed with "keep-constants". I am guessing it's because of the additional check performed in the pre-checker for S7. Very much edge-case though, not anywhere near the high priority changes that must be done. Also haven't decided if it's correct or not.

Addresses #679

Merge request reports