Skip to content

#596 PLCgen: differentiate between reading and writing CIF variables.

Albert Hofkamp requested to merge 596-have-read-and-write-exprs into develop

A few shortcuts for simplifying PLC statement construction, and a bigger extension to the expression generator. The latter is explained in more detail below (same as in the commit message).

Reading a value should return a PlcExpression, while writing a value should be a PlcVarExpression. While the difference is small, adding a type parameter for the "value" field in the ExprGenResult class causes havoc throughout the expression code, due to type erasure and my desire not to have to write ExprGenResult<PlcExpression> everywhere so I can have a handful of ExprGenResult<PlcVarExpression>.

In the end I created two specializations of the ExprGenResulr class:

  • ExprValueResult for results that read the expression value, and
  • ExprAddressableResult for results that modify the expression value.
  • ExprGenResult is now a base-class without "value" field, with two derived classes ExprValueResult and ExprAddressableResult.

The ExpressionGenerator external interface now has ExprValueResult convertValue(Expression) instead of the old convertExpr method and ExprAddressableResult convertAdressable(Expression) for the modifiable variant.

  • The ExpressionGenerator.convertAdressable(Expression) variabnt doesn't handle the f().field case, but that is fine as it is not addressable in CIF either.

  • CifDataProvider methods now has "Value" prefixes (for the existing methods) if the data is meant for reading, and additional "Addressable" variants for modifying discrete and continuous variables. For simplicity I assumed derivative are writable, this may have to change at some point.

    DefaultVariableStorage returns the same PLC variables for CIF variables but that is all still testing code currently.

  • ExprGeneratorTest existing runTest is now runValueTest, and an additional runAdddressableTest has been added for testing writing to discrete and continuous variables.

Addresses #596 (closed)

Merge request reports