Next: Expressions
Up: Type Analysis
Previous: Method declaration
Statements
If a statement represents a context in which an expression is required to
yield a specific type, Expression.Required must be set to that type.
Computation provided by the type analysis modules will then report an error
if the actual type is not acceptable as the required type.
RULE: Statement ::=
'if' '(' Expression ')' Statement 'else' Statement COMPUTE
Expression.Required=boolType;
END;
RULE: Statement ::= 'if' '(' Expression ')' Statement COMPUTE
Expression.Required=boolType;
END;
RULE: WhileStatement ::= 'while' '(' Expression ')' Statement COMPUTE
Expression.Required=boolType;
END;
RULE: DoStatement ::= 'do' Statement 'while' '(' Expression ')' ';' COMPUTE
Expression.Required=boolType;
END;
RULE: ForTest ::= Expression COMPUTE
Expression.Required=boolType;
END;
RULE: Statement ::= 'throw' Expression ';' COMPUTE
Expression.Required=throwableType;
END;
This macro is defined in definitions 42 and 43.
This macro is invoked in definition 2.
The expression of a return statement must return a value compatible with
the method containing the return statement.
This requires an extra attribute at the appropriate point to specify that
type.
Constructors and class initializers cannot return values, so the void type
is specified in those cases.
Since no other type is acceptable as the void type, this will result in an
error report if a return statement with an expression is used in a
constructor or class initializer.
ATTR ReturnType: DefTableKey;
RULE: Statement ::= 'return' Expression ';' COMPUTE
Expression.Required=
INCLUDING (MethodBody.ReturnType,
ConstructorDeclaration.ReturnType,
ClassInitializer.ReturnType);
END;
RULE: MethodDeclarator ::= MethodIdDef '(' FormalParameters ')' COMPUTE
MethodIdDef.ReturnType=MethodDeclarator.Type;
END;
RULE: MethodDeclaration ::= MethodHeader MethodBody COMPUTE
MethodBody.ReturnType=MethodHeader CONSTITUENT MethodIdDef.ReturnType;
END;
SYMBOL ConstructorDeclaration COMPUTE
SYNT.ReturnType=voidType;
END;
SYMBOL ClassInitializer COMPUTE
SYNT.ReturnType=voidType;
END;
This macro is defined in definitions 42 and 43.
This macro is invoked in definition 2.
The convoluted mechanism for obtaining the method return type is again due
to the obsolete construct discussed in Section 5.2.3.
Next: Expressions
Up: Type Analysis
Previous: Method declaration
2008-09-11