Skip to content

#679 PLCgen: Refactor "DeclaredType*" to "DerivedType*"

Albert Hofkamp requested to merge 679-declaredtype-to-derivedtype into develop

I had a closer look at PlcDerivedType inherited from cif2plc, and found it was only used in a unit test. That makes merging DeclaredTypes with DerivedTypes much more feasible than expected. The latter is a proper PlcType, so eliminating declared types is the best direction.

  • Readable by commits.
  • PlcDerivedType is now an abstract class, much like the PlcDeclaredType interface was.
  • I made the error of keeping the existing hashCode methods of the enum and struct types (they check the details of the types, so equality is very unlikely to ever find an equal type with different details). Fixed that in the last commit.

Checks done:

# Search for 'declare' case insensitively does not hit 'declared types' related text.
$ ag declare
src/org/eclipse/escet/cif/plcgen/generators/NameGenerator.java
105:     * Declare the names in the provided collection as unavailable in the PLC code.
111:     * @param names Names to declare as unavailable in the PLC code.

src/org/eclipse/escet/cif/plcgen/generators/PlcCodeStorage.java
323:     * @param derivedTypeDatas Types to declare with their direct child dependencies. Child dependencies are assumed to

src/org/eclipse/escet/cif/plcgen/generators/prechecks/VarContOnlyTimers.java
137:            violations.add(contVar, "Continuous variable has its derivative declared through one or more equations, "

src/org/eclipse/escet/cif/plcgen/writers/S7Writer.java
401:        // There are variables "dummyVar[1,5]" declared as reserved words in S7, for this purpose. The DINT type is

src/org/eclipse/escet/cif/plcgen/writers/tc6_xml_v201.xsd
780:					<xsd:documentation>Reference to a user defined datatype or POU. Variable declarations use this type to declare e.g. function block instances.</xsd:documentation>

# Search for 'instanceof plcderiv' case insensitively finds 2 cases.
# - First case finds the declared type child dependencies in field types of a struct
# - Second case dispatches derived types to a separate text conversion. This caused nonreachable code, which was removed.
$ ag "instanceof plcderiv"                                    
src/org/eclipse/escet/cif/plcgen/generators/DefaultTypeGenerator.java
173:            if (fieldType instanceof PlcDerivedType childDeclType) {

src/org/eclipse/escet/cif/plcgen/writers/Writer.java
339:        } else if (type instanceof PlcDerivedType derType) {

End-user visible change:

  • Fixed that any_derived is an S7 keyword rather than and_derived.

Addressess #679

Edited by Dennis Hendriks

Merge request reports

Loading