Guy Wiener
This document describes changes that were made in the old core parser to extend its validation features. The main additions are type safety and more detailed report on errors.
The goal of the type safety check was to detect errors in which a value or a variable of one type is assigned to a variable of another type. The core parser is not a run-time environment. So the type checks are only for static values. For example, the original parser allows assigning integer variables to range variables, but we cannot check that the actual value of the integer is within the range! I tried to follow as much as possible the original mechanism and the assumptions the core parser makes. So generally I extended or refined existing checks. The main additional code is lookup operations for finding the original type of variables and parameters. The resulted code is rather “patchy” in some point. A future implementation should integrate typing more strongly, to allow these checks in a less messy way. (See design proposal for more details.)
Added global variable currmodule for the currently parsed module. It is currently assigned only for the purpose of scope in type checking. DO NOT USE for other operations, since it is not set from the yacc itself.
Added file lookup.c, lookup.h for type's lookup functions. The type lookup uses the currmodule global variable as a “scope pointer”.
The isBoolean and isInteger functions were modified to use the type lookup.
Type safety in actual parameters: this is now done through post-parse traversal on the CoreDataStructure. After the entire
data structure is parsed, it is scanned and “ModCombin” modules are checked whether the type of the actual parameters to the modules matches the formal
one. The check is similar to the check that is done for assignments.
Added code: files validate.c and validate.h¸
function CheckActualVsFormalParams() in module.c.
Added a check that in partially synchronized modules, each transition that is declared as synchronizing actually appears in the correct
module combination (right or left).
This is done as a recursive check on each node of the combination.
Also checking that there is no ambiguous transitions (same transition appearing in both synchronized modules) and warning on it.
User friendly error message: I added a global auxiliary. variable ErrMsgBuf to serve for formatting error messages using
sprintf(). Converted most existing error messages to contain more information.
Also added line numbers using yylineno. Since it is not a formal feature of lex and does not work with flex and other parsers, I simply added
one of my own to the lexer. Notice, however, that since some errors can be checked only after the entire module is built, the error line number sometimes
refer to the end of the module.
Added value type check when assigning to an enum.
Added some range checks for range and scalarset types. In case a range or scalarset are given explicitly and the assignment value too, we check that it is within range. Otherwise we cannot solve this without a "runtime mechanism", and we just check that the expression is an integer.
In IsIntegerExpr(): we now check also the case where a scalar or range variable is assigned to another variable of this type.
This required special treatment to find the exact type.
By the way - is this the right semantics? Basically the checks performed by the old parser allows assignment to scalars/ranges from *every* kind of
integer-like value and strongly goes in this line. So I followed this line too. But isn't the correct check be that two variables are of the *exact* same
type? Notice this for the future implementations.
Some more checking: on IsIntExpr() and IsBoolExpr() added special handling for arrays. Also added LookUpTypeNameOfVar() in the lookup.c file for support. This treatment is not needed for defined types - it's already included.
Another added check: when assigning an enum a name, we check the enum’s type. Extended lookup.c for this usage.
Bug fix for the old validation: if a variable is assigned with a set, values of the set are checked recursively to match the type of the variable.
Added type safety by modifying the existing mechanism. Added files for lookup and validation functions. Mainly changed functions are
isIntegerExpr() and isBooleanExpr() and other function regarding assignment checks.
The added type safety includes: checking assigned values types (statically), checking actual versus formal types of module instance parameters and checking
that in a set all values types are legal also (bug fix).
Some checks required post-parsing scanning.
Added verification of synchronized modules declarations: each used transition must appear in the right combination. Also issuing a warning on ambiguous transitions in synchronized modules.
Improved error reporting: added line numbers and some details.