#770 PLCgen: Introduce declared types.
The desire exists to compute types inside expression context. For this to happen, type information in expressions must be complete enough to do that. Eg, projection on a tuple type should be computable in a simple way, enum literals need to know their enumeration type.
Currently that is not the case (for structures and enumerations in particular here).
Currently:
-
PlcEnumTypeandPlcStructTypeexist. They are aPlcTypeand contain the definition. They do not know their name that is used in the type declaration. Conversion toBoxproduces the definition. -
PlcTypeDeclarationis not a type. It contains a type-def name and the type being used (iePlc{Enum,Struct}Type). It connect the name of the type to its definition. Conversion toBoxcreates a type definition (printing the name, and delegating printing the definition to the type thay have). -
PlcDerivedTypeis a type. It only has name (the type name). Conversion toBoxproduces the name.
Currently, PlcDerivedType is used as type for enumerations and structures. It nicely prints the name of the definition.
For computing types in expressions however, it's completely useless. It doesn't have the associated definition, it doesn't even know if the name represents an enumeration or a structure type.
Instead, Plc{Enum,Struct}Type should be available in the expression. You can derive that information through the type generator, but that is awkward and complicated.
From that idea, this follows:
-
Plc{Enum,Struct}Typeshould be extended with knowledge about their type name, so they can use that as default way to express their type. Full expansion of the their definition becomes a special case in generating type definitions. - Since any type may want to have a type definition, something is needed to express that. This lead to an empty
PlcDerivedTypeinterface. - With types knowing their own type name,
PlcDerivedTypebecomes useless in PLCgen. -
PlcTypeDeclIs solely used to generate the type definition text, but since the types themselves now know both their type name and their definition in such cases,PlcTypeDeclhas no added value any more either.
Steps done in the patch (Each of the 4 steps in one commit.):
- Introduce
PlcDeclaredType, apply it toPlcTypeDecl. - Rework
PlcStructType. - Rework
PlcEnumType - Delete
PlcTypeDecl. (PlcDerivedTypeis still used in function block context, but I expect that to change when improving function blocks handling in expressions and types.)
For 2 and 3 the steps are (and it's likely useful to read the commit in that order):
- Extend the type.
- Drop the useless "type name to definition" method in the
TypeGenerator. - Adapt
DefaultTypeGenerator. Generally it drops the "name to type" map, and the code that generates that. - Extend the writers to print the type definition of the extended type. Mostly copy/paste of
PlcTypeDeclprinting code for the specific extended type. - Fix Unit tests. (Expression generator test.)
Output of the oee.cif.tests doesn't change.
Addresses #770 (closed)