Validate a statement.
(valid-stmt stmt table ienv) → (mv erp new-stmt return-types last-expr-type? new-table)
If validation is successful, we return, besides an updated validation table, also two pieces of type information.
The first piece is the set of types returned by the statement,
via
The second piece of information is as follows.
If the statement is either a (possibly labeled) expression statement,
or is a (possibly labeled) compound one
whose last block item is an expression statement,
the second piece of information is the type of that expression.
If the statement is not an expression or compound,
or it is compound but does not end in an expression statement
(including the case in which the compound statement has no block items),
the second piece of information is
To validate a labeled statement, we validate its label, and then the enclosed statement. We return the union of the return types, and the optional type from the statement. For now we do not check the requirements in [C:6.8.1/2] and [C:6.8.1/3].
To validate a compound statement, we push a new scope for the block, and we validate the list of block items. We pop the scope and we return the same results coming from the validation of the block items.
To validate an expression statement,
we validate the expression if present,
and return its type as the second result;
this is
A selection statement and its sub-statements are blocks [C:6.8.4/3],
so we push and pop scopes accordingly.
We check that the test of
An iteration statement and its sub-statements are blocks [C:6.8.5/5],
so we push and pop scopes accordingly.
We check that the test expression has scalar type.
No type is returned as the
For now we do not check constraints on
the label of a
A
For now we do not check any constraints on assembler statements.