Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "VIATRA2/Examples/VTCL/TypeChecking"
(→Overview: Type checking) |
(→Overview: Type checking) |
||
Line 10: | Line 10: | ||
=== Typed variables within ASM rules === | === Typed variables within ASM rules === | ||
+ | |||
+ | <source lang="text"> | ||
+ | machine typechecking_errors { | ||
+ | rule main() = | ||
+ | let X : datatypes.Integer = 0 in | ||
+ | seq { | ||
+ | // Type error: operation '*' undefined for types ('Integer', 'String') | ||
+ | update X = X * "oops1"; | ||
+ | // Type error: type incompatible assignment: left value is of type 'Integer', right value is of type 'String' | ||
+ | update X = X + "oops2"; | ||
+ | // This is correct | ||
+ | update X = X + 3; | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
=== Typed variables in ASM functions === | === Typed variables in ASM functions === |
Revision as of 10:13, 25 May 2009
Contents
Overview: Type checking
Type checking is introduced to the VTCL language in a backward compatible way. This means that any existing VTCL transformation should compile without modification.
As the main extension of the language, one can add type information to
- all variables defined locally with the let rule
- a parameter of an ASM rule, graph pattern or graph transformation rule
- for the parameters and return values of ASM functions
Then the VIATRA2 parser checks if these variables are used in a type conformant way.
Typed variables within ASM rules
machine typechecking_errors { rule main() = let X : datatypes.Integer = 0 in seq { // Type error: operation '*' undefined for types ('Integer', 'String') update X = X * "oops1"; // Type error: type incompatible assignment: left value is of type 'Integer', right value is of type 'String' update X = X + "oops2"; // This is correct update X = X + 3; } }
Typed variables in ASM functions
Typed variables in graph patterns
Error messages
The following error messages are issued by the type checker
- Operator '-' is undefined for the argument type ('datatypes.String'): issued when checking an ASM term
- Operator '*' is undefined for the argument types ('datatypes.String', 'datatypes.String'): issued when checking an ASM term
- The type 'uml2.metamodel.Classifier' of actual parameter is not compatible with the type 'uml2.metamodel.Class' of symbolic parameter 'C'. See the definition of 'myPattern' : issued when calling a graph pattern using the find construct
- The type 'uml2.metamodel.Classifier' of variable reference is not compatible with the type 'uml2.metamodel.Class' of its definition.: issued in ASM rules or in the body of graph patterns
- Type incompatible assignment: left value is of type 'datatypes.String', right value is of type 'datatypes.Integer' : issued in case of an update rule
- Type incompatible initialization: expecting a term of type 'datatypes.String' instead of 'datatypes.Integer' : issued when initializing an ASM function
--Varro.mit.bme.hu 11:02, 25 May 2009 (UTC)