General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Type AnalysisError Reporting in Type AnalysisLanguage-dependent error reporting involves checks based on the types associated with program constructs by the computations specified in earlier chapters. For example, object-oriented languages differ in their requirements for overriding methods when extending a class definition. One possibility is to require that the type of each parameter of the overriding method be a supertype of the corresponding parameter type of the overridden method, and that the result type of the overriding method be a subtype of the result type of the overridden method. The type analysis modules will establish the complete signatures of both methods, and the subtype/supertype relation among all type pairs. Thus only the actual check remains to be written. Some errors make it impossible to associate any type with a program construct, and these are reported by the modules. Operations are also made available to support detection of incorrect typing.
Verifying typed identifier usage
An applied occurrence of an identifier that purports to represent a
typed entity inherits the SYMBOL ExpIdUse INHERITS ChkTypedUseId END;
If the identifier `id' at an
Must denote a typed object: `id'
If the identifier `id' at an
Type identifier not allowed: `id'
Verifying type identifier usage
Both defining and applied occurrences of type identifiers can be checked
for validity.
In each case, the value of the
Verifying type consistency within an expression
The
This error reporting can be changed by overriding computations for the
`s'.`xxx'Msg= IF(`s'.`xxx'Err,message(ERROR,"My report",0,COORDREF));
Because
If you wish to override the message in every context,
write the overriding computation as a symbol computation
in the lower context of the override symbol specified above.
In this case, `xxx' would be
SYMBOL OprError COMPUTE SYNT.OprMsg= IF(SYNT.OprErr,message(ERROR,"Invalid operator",0,COORDREF)); END; If you wish to override the message in a few specific contexts, write the overriding computation as a rule computation in the lower context of a symbol inheriting the computational role. In this case, `xxx' would be the symbol on the left-hand side of the rule. Here is an example, changing the standard expression error report to be more specific for function arguments:
RULE: Actual ::= Expr COMPUTE Actual.ExpMsg= IF(Actual.ExpErr,message(ERROR,"Wrong argument type",0,COORDREF)); END;
Support for context checking
As noted in the previous section,
Consider an expression in which a function is applied to arguments (see Functions as typed entities): SYMBOL Expr INHERITS ExpressionSymbol END; SYMBOL Actuals INHERITS OpndExprListRoot END; RULE: Expr ::= Expr '(' Actuals ')' COMPUTE ListContext(Expr[1],,Actuals); Indication(GetInvoker(Expr[2].Type,NoKey)); IF(BadIndication, message(ERROR,"Invalid function",0,COORDREF)); END;
Suppose that, because of a programming error, Now consider the array access expression (see Operators with explicit operands): SYMBOL Subscript INHERITS ExpressionSymbol END; RULE: Expr ::= Expr '[' Subscript ']' COMPUTE DyadicContext(Expr[1],,Expr[2],Subscript); Indication(indexInd), IF(BadOperator, message(ERROR,"Invalid array reference",0,COORDREF)); END;
Suppose that, because of a programming error,
It is sometimes useful to be able to check whether one type is acceptable
as another outside of the situations covered in the previous section.
Let `from' and `to' be definition table keys representing types.
For example, consider a cast involving a reference type in Java. The cast is known to be correct at compile time if a value is being cast to its superclass. If the value is being cast to one of its subclasses, however, a run-time check is required. Thus the compiler must accept such a cast both when the value is acceptable as a value of the cast type and when a value of the cast type is acceptable as a value of the type being cast:
RULE: Expression ::= '(' Expression ')' Expression COMPUTE IF(AND( NOT(IsCoercible(Expression[2].Type,Expression[3].Type)), NOT(IsCoercible(Expression[3].Type,Expression[2].Type))), message(ERROR,"Invalid cast",0,COORDREF)); END;
|