#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:
-
PlcEnumType
andPlcStructType
exist. They are aPlcType
and contain the definition. They do not know their name that is used in the type declaration. Conversion toBox
produces the definition. -
PlcTypeDeclaration
is 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 toBox
creates a type definition (printing the name, and delegating printing the definition to the type thay have). -
PlcDerivedType
is a type. It only has name (the type name). Conversion toBox
produces 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}Type
should 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
PlcDerivedType
interface. - With types knowing their own type name,
PlcDerivedType
becomes useless in PLCgen. -
PlcTypeDecl
Is 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,PlcTypeDecl
has 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
. (PlcDerivedType
is 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
PlcTypeDecl
printing code for the specific extended type. - Fix Unit tests. (Expression generator test.)
Output of the oee.cif.tests
doesn't change.
Addresses #770 (closed)