Java Reference
In-Depth Information
label =
kind =
iterative
label =
kind =
kind =
label =
null
AST
AST
AST
null
null
other
other
for
if
break
label =
kind =
iterative
AST
L1
for
Figure 9.17: Example of a label list in a Break Statement
allows us to properly analyze do-forever loops that terminate by executing a
break.
As an example, consider the following code fragment:
L1: for (i=0; i < 100; i++)
for (j=0; j < 100; j++)
if (a[i][j] == 0)
break L1;
else ...
The label list in use when the break is analyzed is shown in Figure 9.17. Since
the list contains a node with label =
L1, the break is correct. The for loop labeled
with L1 is marked as terminating normally.
Return Statements
An AST rooted by Returning, as shown in Figure 9.19, represents a return
statement. The field returnVal is null if no value is returned; otherwise it is an
AST representing an expression to be evaluated and returned.
The semantic rules governing a return statement depend on where the
statement appears. A return statement without an expression value may only
appear in a void method (a procedure) or in a constructor. A return statement
with a return value may only appear in a method whose type may be assigned
the return type (this excludes void methods and constructors).
A method declared to return a value (a function) must exit via a return
of a value or by throwing an exception. This requirement can be enforced
Search WWH ::




Custom Search