Java Reference
In-Depth Information
Chapter4
TypeChecking
4.1 Introduction
Type checking, or more formally semantic analysis, is the final step in the analysis phase. It
is the compiler's last chance to collect information necessary to begin the synthesis phase.
Semantic analysis includes the following:
Determining the types of all names and expressions.
Type checking: insuring that all expressions are properly typed, for example, that the
operands of an operator have the proper types.
A certain amount of storage analysis, for example determining the amount of storage
that is required in the current stack frame to store a local variable (one word for int s,
two words for long is This information is used to allocate locations (at offsets from
the base of the current stack frame) for parameters and local variables.
A certain amount of AST tree rewriting, usually to make implicit constructs more
explicit.
Semantic analysis of j-- programs involves all of the following operations.
Like Java, j-- is strictly-typed ; that is, we want to determine the types of all names
and expressions at compile time.
A j-- program must be well-typed; that is, the operands to all operations must have
appropriate types.
All j-- local variables (including formal parameters) must be allocated storage and
assigned locations within a method's stack frame.
The AST for j-- requires a certain amount of sub-tree rewriting. For example, field
references using simple names must be rewritten as explicit field selection operations.
And declared variable initializations must be rewritten as explicit assignment state-
ments.
4.2 j--Types
4.2.1 Introduction toj--Types
A type in j-- is either a primitive type or a reference type.
127
 
Search WWH ::




Custom Search