langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
author jjg
Tue, 25 Sep 2012 13:06:58 -0700
changeset 14049 3207422a0f9b
parent 13689 4d519199a6aa
child 14058 c7ec7facdd20
permissions -rw-r--r--
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac Reviewed-by: mcimadamore, jjg Contributed-by: vicenterz@yahoo.es
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
//todo: one might eliminate uninits.andSets when monotonic
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
    30
import java.util.HashMap;
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
    31
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.tree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.tree.JCTree.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import static com.sun.tools.javac.code.Flags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9601
diff changeset
    41
import static com.sun.tools.javac.code.Flags.BLOCK;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import static com.sun.tools.javac.code.TypeTags.*;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 9601
diff changeset
    44
import static com.sun.tools.javac.tree.JCTree.Tag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    46
/** This pass implements dataflow analysis for Java programs though
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    47
 *  different AST visitor steps. Liveness analysis (see AliveAlanyzer) checks that
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    48
 *  every statement is reachable. Exception analysis (see FlowAnalyzer) ensures that
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    49
 *  every checked exception that is thrown is declared or caught.  Definite assignment analysis
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    50
 *  (see AssignAnalyzer) ensures that each variable is assigned when used.  Definite
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    51
 *  unassignment analysis (see AssignAnalyzer) in ensures that no final variable
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    52
 *  is assigned more than once. Finally, local variable capture analysis (see CaptureAnalyzer)
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    53
 *  determines that local variables accessed within the scope of an inner class are
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
    54
 *  either final or effectively-final.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 9300
diff changeset
    56
 *  <p>The JLS has a number of problems in the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  specification of these flow analysis problems. This implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  attempts to address those issues.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  <p>First, there is no accommodation for a finally clause that cannot
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  complete normally. For liveness analysis, an intervening finally
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  clause can cause a break, continue, or return not to reach its
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  target.  For exception analysis, an intervening finally clause can
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  cause any exception to be "caught".  For DA/DU analysis, the finally
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  clause can prevent a transfer of control from propagating DA/DU
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  state to the target.  In addition, code in the finally clause can
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *  affect the DA/DU status of variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *  <p>For try statements, we introduce the idea of a variable being
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *  definitely unassigned "everywhere" in a block.  A variable V is
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  "unassigned everywhere" in a block iff it is unassigned at the
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *  beginning of the block and there is no reachable assignment to V
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *  in the block.  An assignment V=e is reachable iff V is not DA
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  after e.  Then we can say that V is DU at the beginning of the
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *  catch block iff V is DU everywhere in the try block.  Similarly, V
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *  is DU at the beginning of the finally block iff V is DU everywhere
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *  in the try block and in every catch block.  Specifically, the
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 *  following bullet is added to 16.2.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *      V is <em>unassigned everywhere</em> in a block if it is
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *      unassigned before the block and there is no reachable
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *      assignment to V within the block.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 *  <p>In 16.2.15, the third bullet (and all of its sub-bullets) for all
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *  try blocks is changed to
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *      V is definitely unassigned before a catch block iff V is
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 *      definitely unassigned everywhere in the try block.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 *  <p>The last bullet (and all of its sub-bullets) for try blocks that
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 *  have a finally block is changed to
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 *      V is definitely unassigned before the finally block iff
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 *      V is definitely unassigned everywhere in the try block
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 *      and everywhere in each catch block of the try statement.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 *  <p>In addition,
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 *      V is definitely assigned at the end of a constructor iff
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 *      V is definitely assigned after the block that is the body
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 *      of the constructor and V is definitely assigned at every
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 *      return that can return from the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 *  <p>In addition, each continue statement with the loop as its target
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 *  is treated as a jump to the end of the loop body, and "intervening"
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 *  finally clauses are treated as follows: V is DA "due to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 *  continue" iff V is DA before the continue statement or V is DA at
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 *  the end of any intervening finally block.  V is DU "due to the
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 *  continue" iff any intervening finally cannot complete normally or V
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 *  is DU at the end of every intervening finally block.  This "due to
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 *  the continue" concept is then used in the spec for the loops.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 *  <p>Similarly, break statements must consider intervening finally
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 *  blocks.  For liveness analysis, a break statement for which any
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
 *  intervening finally cannot complete normally is not considered to
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
 *  cause the target statement to be able to complete normally. Then
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
 *  we say V is DA "due to the break" iff V is DA before the break or
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
 *  V is DA at the end of any intervening finally block.  V is DU "due
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
 *  to the break" iff any intervening finally cannot complete normally
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 *  or V is DU at the break and at the end of every intervening
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 *  finally block.  (I suspect this latter condition can be
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 *  simplified.)  This "due to the break" is then used in the spec for
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 *  all statements that can be "broken".
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 *  <p>The return statement is treated similarly.  V is DA "due to a
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
 *  return statement" iff V is DA before the return statement or V is
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 *  DA at the end of any intervening finally block.  Note that we
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 *  don't have to worry about the return expression because this
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 *  concept is only used for construcrors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 9300
diff changeset
   131
 *  <p>There is no spec in the JLS for when a variable is definitely
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 *  assigned at the end of a constructor, which is needed for final
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
 *  fields (8.3.1.2).  We implement the rule that V is DA at the end
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
 *  of the constructor iff it is DA and the end of the body of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
 *  constructor and V is DA "due to" every return of the constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
 *  <p>Intervening finally blocks similarly affect exception analysis.  An
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
 *  intervening finally that cannot complete normally allows us to ignore
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
 *  an otherwise uncaught exception.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
 *  <p>To implement the semantics of intervening finally clauses, all
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
 *  nonlocal transfers (break, continue, return, throw, method call that
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
 *  can throw a checked exception, and a constructor invocation that can
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
 *  thrown a checked exception) are recorded in a queue, and removed
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
 *  from the queue when we complete processing the target of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
 *  nonlocal transfer.  This allows us to modify the queue in accordance
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
 *  with the above rules when we encounter a finally clause.  The only
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
 *  exception to this [no pun intended] is that checked exceptions that
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
 *  are known to be caught or declared to be caught in the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
 *  method are not recorded in the queue, but instead are recorded in a
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
 *  global variable "Set<Type> thrown" that records the type of all
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
 *  exceptions that can be thrown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
 *  <p>Other minor issues the treatment of members of other classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
 *  (always considered DA except that within an anonymous class
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
 *  constructor, where DA status from the enclosing scope is
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
 *  preserved), treatment of the case expression (V is DA before the
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
 *  case expression iff V is DA after the switch expression),
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
 *  treatment of variables declared in a switch block (the implied
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
 *  DA/DU status after the switch expression is DU and not DA for
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
 *  variables defined in a switch block), the treatment of boolean ?:
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
 *  expressions (The JLS rules only handle b and c non-boolean; the
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
 *  new rule is that if b and c are boolean valued, then V is
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
 *  (un)assigned after a?b:c when true/false iff V is (un)assigned
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
 *  after b when true/false and V is (un)assigned after c when
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
 *  true/false).
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
 *  <p>There is the remaining question of what syntactic forms constitute a
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
 *  reference to a variable.  It is conventional to allow this.x on the
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
 *  left-hand-side to initialize a final instance field named x, yet
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
 *  this.x isn't considered a "use" when appearing on a right-hand-side
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
 *  in most implementations.  Should parentheses affect what is
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
 *  considered a variable reference?  The simplest rule would be to
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
 *  allow unqualified forms only, parentheses optional, and phase out
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
 *  support for assigning to a final field via this.x.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
   177
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
   178
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
 */
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   182
public class Flow {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    protected static final Context.Key<Flow> flowKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        new Context.Key<Flow>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   186
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    private final Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    private final Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    private final Check chk;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    private       TreeMaker make;
6156
e15c221efaac 6970833: Try-with-resource implementation throws an NPE during Flow analysis
mcimadamore
parents: 6151
diff changeset
   192
    private final Resolve rs;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   193
    private final JCDiagnostic.Factory diags;
6156
e15c221efaac 6970833: Try-with-resource implementation throws an NPE during Flow analysis
mcimadamore
parents: 6151
diff changeset
   194
    private Env<AttrContext> attrEnv;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    private       Lint lint;
8849
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
   196
    private final boolean allowImprovedRethrowAnalysis;
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
   197
    private final boolean allowImprovedCatchAnalysis;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   198
    private final boolean allowEffectivelyFinalInInnerClasses;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    public static Flow instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        Flow instance = context.get(flowKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            instance = new Flow(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   207
    public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   208
        new AliveAnalyzer().analyzeTree(env, make);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   209
        new AssignAnalyzer().analyzeTree(env, make);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   210
        new FlowAnalyzer().analyzeTree(env, make);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   211
        new CaptureAnalyzer().analyzeTree(env, make);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   212
    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   213
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   214
    /**
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   215
     * Definite assignment scan mode
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   216
     */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   217
    enum FlowKind {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   218
        /**
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   219
         * This is the normal DA/DU analysis mode
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   220
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   221
        NORMAL("var.might.already.be.assigned", false),
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   222
        /**
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   223
         * This is the speculative DA/DU analysis mode used to speculatively
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   224
         * derive assertions within loop bodies
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   225
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   226
        SPECULATIVE_LOOP("var.might.be.assigned.in.loop", true);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   227
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   228
        String errKey;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   229
        boolean isFinal;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   230
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   231
        FlowKind(String errKey, boolean isFinal) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   232
            this.errKey = errKey;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   233
            this.isFinal = isFinal;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   234
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   235
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   236
        boolean isFinal() {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   237
            return isFinal;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   238
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   239
    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   240
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    protected Flow(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        context.put(flowKey, this);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   243
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        types = Types.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        chk = Check.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        lint = Lint.instance(context);
6156
e15c221efaac 6970833: Try-with-resource implementation throws an NPE during Flow analysis
mcimadamore
parents: 6151
diff changeset
   249
        rs = Resolve.instance(context);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   250
        diags = JCDiagnostic.Factory.instance(context);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
   251
        Source source = Source.instance(context);
8849
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
   252
        allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis();
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
   253
        allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis();
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   254
        Options options = Options.instance(context);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   255
        allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses() &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   256
                options.isSet("allowEffectivelyFinalInInnerClasses"); //pre-lambda guard
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   259
    /**
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   260
     * Base visitor class for all visitors implementing dataflow analysis logic.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   261
     * This class define the shared logic for handling jumps (break/continue statements).
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     */
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   263
    static abstract class BaseAnalyzer<P extends BaseAnalyzer.PendingExit> extends TreeScanner {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   265
        enum JumpKind {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   266
            BREAK(JCTree.Tag.BREAK) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   267
                @Override
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   268
                JCTree getTarget(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   269
                    return ((JCBreak)tree).target;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   270
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   271
            },
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   272
            CONTINUE(JCTree.Tag.CONTINUE) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   273
                @Override
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   274
                JCTree getTarget(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   275
                    return ((JCContinue)tree).target;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   276
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   277
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   279
            JCTree.Tag treeTag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   281
            private JumpKind(Tag treeTag) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   282
                this.treeTag = treeTag;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   283
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   284
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   285
            abstract JCTree getTarget(JCTree tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   286
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   288
        /** The currently pending exits that go from current inner blocks
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   289
         *  to an enclosing block, in source order.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   290
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   291
        ListBuffer<P> pendingExits;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   292
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   293
        /** A pending exit.  These are the statements return, break, and
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   294
         *  continue.  In addition, exception-throwing expressions or
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   295
         *  statements are put here when not known to be caught.  This
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   296
         *  will typically result in an error unless it is within a
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   297
         *  try-finally whose finally block cannot complete normally.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   298
         */
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   299
        static class PendingExit {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   300
            JCTree tree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   302
            PendingExit(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   303
                this.tree = tree;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   304
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   305
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   306
            void resolveJump() {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   307
                //do nothing
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   308
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   309
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   310
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   311
        abstract void markDead();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   312
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   313
        /** Record an outward transfer of control. */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   314
        void recordExit(JCTree tree, P pe) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   315
            pendingExits.append(pe);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   316
            markDead();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   317
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   319
        /** Resolve all jumps of this statement. */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   320
        private boolean resolveJump(JCTree tree,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   321
                        ListBuffer<P> oldPendingExits,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   322
                        JumpKind jk) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   323
            boolean resolved = false;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   324
            List<P> exits = pendingExits.toList();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   325
            pendingExits = oldPendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   326
            for (; exits.nonEmpty(); exits = exits.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   327
                P exit = exits.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   328
                if (exit.tree.hasTag(jk.treeTag) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   329
                        jk.getTarget(exit.tree) == tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   330
                    exit.resolveJump();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   331
                    resolved = true;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   332
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   333
                    pendingExits.append(exit);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   334
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   335
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   336
            return resolved;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   338
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   339
        /** Resolve all breaks of this statement. */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   340
        boolean resolveContinues(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   341
            return resolveJump(tree, new ListBuffer<P>(), JumpKind.CONTINUE);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   342
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   343
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   344
        /** Resolve all continues of this statement. */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   345
        boolean resolveBreaks(JCTree tree, ListBuffer<P> oldPendingExits) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   346
            return resolveJump(tree, oldPendingExits, JumpKind.BREAK);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   350
    /**
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   351
     * This pass implements the first step of the dataflow analysis, namely
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   352
     * the liveness analysis check. This checks that every statement is reachable.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   353
     * The output of this analysis pass are used by other analyzers. This analyzer
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   354
     * sets the 'finallyCanCompleteNormally' field in the JCTry class.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   355
     */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   356
    class AliveAnalyzer extends BaseAnalyzer<BaseAnalyzer.PendingExit> {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   357
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   358
        /** A flag that indicates whether the last statement could
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   359
         *  complete normally.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   360
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   361
        private boolean alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   362
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   363
        @Override
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   364
        void markDead() {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   365
            alive = false;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   366
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   367
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   368
    /*************************************************************************
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   369
     * Visitor methods for statements and definitions
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   370
     *************************************************************************/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   371
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   372
        /** Analyze a definition.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   373
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   374
        void scanDef(JCTree tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   375
            scanStat(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   376
            if (tree != null && tree.hasTag(JCTree.Tag.BLOCK) && !alive) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   377
                log.error(tree.pos(),
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   378
                          "initializer.must.be.able.to.complete.normally");
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   379
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   380
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   381
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   382
        /** Analyze a statement. Check that statement is reachable.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   383
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   384
        void scanStat(JCTree tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   385
            if (!alive && tree != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   386
                log.error(tree.pos(), "unreachable.stmt");
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   387
                if (!tree.hasTag(SKIP)) alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   388
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   389
            scan(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   390
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   391
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   392
        /** Analyze list of statements.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   393
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   394
        void scanStats(List<? extends JCStatement> trees) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   395
            if (trees != null)
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   396
                for (List<? extends JCStatement> l = trees; l.nonEmpty(); l = l.tail)
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   397
                    scanStat(l.head);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   398
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   399
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   400
        /* ------------ Visitor methods for various sorts of trees -------------*/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   401
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   402
        public void visitClassDef(JCClassDecl tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   403
            if (tree.sym == null) return;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   404
            boolean alivePrev = alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   405
            ListBuffer<PendingExit> pendingExitsPrev = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   406
            Lint lintPrev = lint;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   407
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   408
            pendingExits = new ListBuffer<PendingExit>();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   409
            lint = lint.augment(tree.sym.annotations);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   410
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   411
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   412
                // process all the static initializers
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   413
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   414
                    if (!l.head.hasTag(METHODDEF) &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   415
                        (TreeInfo.flags(l.head) & STATIC) != 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   416
                        scanDef(l.head);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   417
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   418
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   419
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   420
                // process all the instance initializers
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   421
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   422
                    if (!l.head.hasTag(METHODDEF) &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   423
                        (TreeInfo.flags(l.head) & STATIC) == 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   424
                        scanDef(l.head);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   425
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   426
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   427
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   428
                // process all the methods
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   429
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   430
                    if (l.head.hasTag(METHODDEF)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   431
                        scan(l.head);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   432
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   433
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   434
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   435
                pendingExits = pendingExitsPrev;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   436
                alive = alivePrev;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   437
                lint = lintPrev;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   438
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   439
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   440
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   441
        public void visitMethodDef(JCMethodDecl tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   442
            if (tree.body == null) return;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   443
            Lint lintPrev = lint;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   444
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   445
            lint = lint.augment(tree.sym.annotations);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   446
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   447
            Assert.check(pendingExits.isEmpty());
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   448
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   449
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   450
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   451
                scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   452
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   453
                if (alive && tree.sym.type.getReturnType().tag != VOID)
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   454
                    log.error(TreeInfo.diagEndPos(tree.body), "missing.ret.stmt");
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   455
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   456
                List<PendingExit> exits = pendingExits.toList();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   457
                pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   458
                while (exits.nonEmpty()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   459
                    PendingExit exit = exits.head;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   460
                    exits = exits.tail;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   461
                    Assert.check(exit.tree.hasTag(RETURN));
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   462
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   463
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   464
                lint = lintPrev;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   465
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   466
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   467
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   468
        public void visitVarDef(JCVariableDecl tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   469
            if (tree.init != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   470
                Lint lintPrev = lint;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   471
                lint = lint.augment(tree.sym.annotations);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   472
                try{
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   473
                    scan(tree.init);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   474
                } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   475
                    lint = lintPrev;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   476
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   477
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   478
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   479
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   480
        public void visitBlock(JCBlock tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   481
            scanStats(tree.stats);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   482
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   483
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   484
        public void visitDoLoop(JCDoWhileLoop tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   485
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   486
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   487
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   488
            alive |= resolveContinues(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   489
            scan(tree.cond);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   490
            alive = alive && !tree.cond.type.isTrue();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   491
            alive |= resolveBreaks(tree, prevPendingExits);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   492
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   493
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   494
        public void visitWhileLoop(JCWhileLoop tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   495
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   496
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   497
            scan(tree.cond);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   498
            alive = !tree.cond.type.isFalse();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   499
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   500
            alive |= resolveContinues(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   501
            alive = resolveBreaks(tree, prevPendingExits) ||
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   502
                !tree.cond.type.isTrue();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   503
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   504
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   505
        public void visitForLoop(JCForLoop tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   506
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   507
            scanStats(tree.init);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   508
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   509
            if (tree.cond != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   510
                scan(tree.cond);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   511
                alive = !tree.cond.type.isFalse();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   512
            } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   513
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   514
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   515
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   516
            alive |= resolveContinues(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   517
            scan(tree.step);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   518
            alive = resolveBreaks(tree, prevPendingExits) ||
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   519
                tree.cond != null && !tree.cond.type.isTrue();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   520
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   521
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   522
        public void visitForeachLoop(JCEnhancedForLoop tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   523
            visitVarDef(tree.var);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   524
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   525
            scan(tree.expr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   526
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   527
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   528
            alive |= resolveContinues(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   529
            resolveBreaks(tree, prevPendingExits);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   530
            alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   531
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   532
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   533
        public void visitLabelled(JCLabeledStatement tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   534
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   535
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   536
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   537
            alive |= resolveBreaks(tree, prevPendingExits);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   538
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   539
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   540
        public void visitSwitch(JCSwitch tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   541
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   542
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   543
            scan(tree.selector);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   544
            boolean hasDefault = false;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   545
            for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   546
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   547
                JCCase c = l.head;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   548
                if (c.pat == null)
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   549
                    hasDefault = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   550
                else
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   551
                    scan(c.pat);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   552
                scanStats(c.stats);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   553
                // Warn about fall-through if lint switch fallthrough enabled.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   554
                if (alive &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   555
                    lint.isEnabled(Lint.LintCategory.FALLTHROUGH) &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   556
                    c.stats.nonEmpty() && l.tail.nonEmpty())
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   557
                    log.warning(Lint.LintCategory.FALLTHROUGH,
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   558
                                l.tail.head.pos(),
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   559
                                "possible.fall-through.into.case");
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   560
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   561
            if (!hasDefault) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   562
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   563
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   564
            alive |= resolveBreaks(tree, prevPendingExits);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   565
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   566
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   567
        public void visitTry(JCTry tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   568
            ListBuffer<PendingExit> prevPendingExits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   569
            pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   570
            for (JCTree resource : tree.resources) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   571
                if (resource instanceof JCVariableDecl) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   572
                    JCVariableDecl vdecl = (JCVariableDecl) resource;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   573
                    visitVarDef(vdecl);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   574
                } else if (resource instanceof JCExpression) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   575
                    scan((JCExpression) resource);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   576
                } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   577
                    throw new AssertionError(tree);  // parser error
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   578
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   579
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   580
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   581
            scanStat(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   582
            boolean aliveEnd = alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   583
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   584
            for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   585
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   586
                JCVariableDecl param = l.head.param;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   587
                scan(param);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   588
                scanStat(l.head.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   589
                aliveEnd |= alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   590
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   591
            if (tree.finalizer != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   592
                ListBuffer<PendingExit> exits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   593
                pendingExits = prevPendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   594
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   595
                scanStat(tree.finalizer);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   596
                tree.finallyCanCompleteNormally = alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   597
                if (!alive) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   598
                    if (lint.isEnabled(Lint.LintCategory.FINALLY)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   599
                        log.warning(Lint.LintCategory.FINALLY,
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   600
                                TreeInfo.diagEndPos(tree.finalizer),
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   601
                                "finally.cannot.complete");
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   602
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   603
                } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   604
                    while (exits.nonEmpty()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   605
                        pendingExits.append(exits.next());
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   606
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   607
                    alive = aliveEnd;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   608
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   609
            } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   610
                alive = aliveEnd;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   611
                ListBuffer<PendingExit> exits = pendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   612
                pendingExits = prevPendingExits;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   613
                while (exits.nonEmpty()) pendingExits.append(exits.next());
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   614
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   615
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   616
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   617
        @Override
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   618
        public void visitIf(JCIf tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   619
            scan(tree.cond);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   620
            scanStat(tree.thenpart);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   621
            if (tree.elsepart != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   622
                boolean aliveAfterThen = alive;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   623
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   624
                scanStat(tree.elsepart);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   625
                alive = alive | aliveAfterThen;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   626
            } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   627
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   628
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   629
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   630
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   631
        public void visitBreak(JCBreak tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   632
            recordExit(tree, new PendingExit(tree));
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   633
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   634
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   635
        public void visitContinue(JCContinue tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   636
            recordExit(tree, new PendingExit(tree));
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   637
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   638
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   639
        public void visitReturn(JCReturn tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   640
            scan(tree.expr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   641
            recordExit(tree, new PendingExit(tree));
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   642
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   643
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   644
        public void visitThrow(JCThrow tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   645
            scan(tree.expr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   646
            markDead();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   647
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   648
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   649
        public void visitApply(JCMethodInvocation tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   650
            scan(tree.meth);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   651
            scan(tree.args);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   652
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   653
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   654
        public void visitNewClass(JCNewClass tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   655
            scan(tree.encl);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   656
            scan(tree.args);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   657
            if (tree.def != null) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   658
                scan(tree.def);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   659
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   660
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   661
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   662
        public void visitTopLevel(JCCompilationUnit tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   663
            // Do nothing for TopLevel since each class is visited individually
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   664
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   665
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   666
    /**************************************************************************
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   667
     * main method
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   668
     *************************************************************************/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   669
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   670
        /** Perform definite assignment/unassignment analysis on a tree.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   671
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   672
        public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   673
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   674
                attrEnv = env;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   675
                Flow.this.make = make;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   676
                pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   677
                alive = true;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   678
                scan(env.tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   679
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   680
                pendingExits = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   681
                Flow.this.make = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   682
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   683
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   684
    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   685
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   686
    /**
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   687
     * This pass implements the second step of the dataflow analysis, namely
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   688
     * the exception analysis. This is to ensure that every checked exception that is
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   689
     * thrown is declared or caught. The analyzer uses some info that has been set by
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   690
     * the liveliness analyzer.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
     */
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   692
    class FlowAnalyzer extends BaseAnalyzer<FlowAnalyzer.FlowPendingExit> {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   693
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   694
        /** A flag that indicates whether the last statement could
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   695
         *  complete normally.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   696
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   697
        HashMap<Symbol, List<Type>> preciseRethrowTypes;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   698
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   699
        /** The current class being defined.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   700
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   701
        JCClassDecl classDef;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   702
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   703
        /** The list of possibly thrown declarable exceptions.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   704
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   705
        List<Type> thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   706
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   707
        /** The list of exceptions that are either caught or declared to be
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   708
         *  thrown.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   709
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   710
        List<Type> caught;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   711
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   712
        class FlowPendingExit extends BaseAnalyzer.PendingExit {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   713
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   714
            Type thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   715
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   716
            FlowPendingExit(JCTree tree, Type thrown) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   717
                super(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   718
                this.thrown = thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   719
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   720
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   721
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   722
        @Override
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   723
        void markDead() {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   724
            //do nothing
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   725
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   726
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   727
        /*-------------------- Exceptions ----------------------*/
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   728
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   729
        /** Complain that pending exceptions are not caught.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   730
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   731
        void errorUncaught() {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   732
            for (FlowPendingExit exit = pendingExits.next();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   733
                 exit != null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   734
                 exit = pendingExits.next()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   735
                if (classDef != null &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   736
                    classDef.pos == exit.tree.pos) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   737
                    log.error(exit.tree.pos(),
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   738
                            "unreported.exception.default.constructor",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   739
                            exit.thrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   740
                } else if (exit.tree.hasTag(VARDEF) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   741
                        ((JCVariableDecl)exit.tree).sym.isResourceVariable()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   742
                    log.error(exit.tree.pos(),
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   743
                            "unreported.exception.implicit.close",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   744
                            exit.thrown,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   745
                            ((JCVariableDecl)exit.tree).sym.name);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   746
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   747
                    log.error(exit.tree.pos(),
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   748
                            "unreported.exception.need.to.catch.or.throw",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   749
                            exit.thrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   750
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   751
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   752
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   753
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   754
        /** Record that exception is potentially thrown and check that it
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   755
         *  is caught.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   756
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   757
        void markThrown(JCTree tree, Type exc) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   758
            if (!chk.isUnchecked(tree.pos(), exc)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   759
                if (!chk.isHandled(exc, caught))
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   760
                    pendingExits.append(new FlowPendingExit(tree, exc));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   761
                    thrown = chk.incl(exc, thrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   762
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   763
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   764
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   765
    /*************************************************************************
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   766
     * Visitor methods for statements and definitions
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   767
     *************************************************************************/
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   768
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   769
        /* ------------ Visitor methods for various sorts of trees -------------*/
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   770
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   771
        public void visitClassDef(JCClassDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   772
            if (tree.sym == null) return;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   773
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   774
            JCClassDecl classDefPrev = classDef;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   775
            List<Type> thrownPrev = thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   776
            List<Type> caughtPrev = caught;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   777
            ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   778
            Lint lintPrev = lint;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   779
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   780
            pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   781
            if (tree.name != names.empty) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   782
                caught = List.nil();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   783
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   784
            classDef = tree;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   785
            thrown = List.nil();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   786
            lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   787
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   788
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   789
                // process all the static initializers
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   790
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   791
                    if (!l.head.hasTag(METHODDEF) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   792
                        (TreeInfo.flags(l.head) & STATIC) != 0) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   793
                        scan(l.head);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   794
                        errorUncaught();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   795
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   796
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   797
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   798
                // add intersection of all thrown clauses of initial constructors
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   799
                // to set of caught exceptions, unless class is anonymous.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   800
                if (tree.name != names.empty) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   801
                    boolean firstConstructor = true;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   802
                    for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   803
                        if (TreeInfo.isInitialConstructor(l.head)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   804
                            List<Type> mthrown =
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   805
                                ((JCMethodDecl) l.head).sym.type.getThrownTypes();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   806
                            if (firstConstructor) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   807
                                caught = mthrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   808
                                firstConstructor = false;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   809
                            } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   810
                                caught = chk.intersect(mthrown, caught);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   811
                            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   812
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   813
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   814
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   815
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   816
                // process all the instance initializers
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   817
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   818
                    if (!l.head.hasTag(METHODDEF) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   819
                        (TreeInfo.flags(l.head) & STATIC) == 0) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   820
                        scan(l.head);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   821
                        errorUncaught();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   822
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   823
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   824
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   825
                // in an anonymous class, add the set of thrown exceptions to
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   826
                // the throws clause of the synthetic constructor and propagate
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   827
                // outwards.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   828
                // Changing the throws clause on the fly is okay here because
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   829
                // the anonymous constructor can't be invoked anywhere else,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   830
                // and its type hasn't been cached.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   831
                if (tree.name == names.empty) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   832
                    for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   833
                        if (TreeInfo.isInitialConstructor(l.head)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   834
                            JCMethodDecl mdef = (JCMethodDecl)l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   835
                            mdef.thrown = make.Types(thrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   836
                            mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   837
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   838
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   839
                    thrownPrev = chk.union(thrown, thrownPrev);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   840
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   841
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   842
                // process all the methods
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   843
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   844
                    if (l.head.hasTag(METHODDEF)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   845
                        scan(l.head);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   846
                        errorUncaught();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   847
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   848
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   849
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   850
                thrown = thrownPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   851
            } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   852
                pendingExits = pendingExitsPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   853
                caught = caughtPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   854
                classDef = classDefPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   855
                lint = lintPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   856
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   857
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   858
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   859
        public void visitMethodDef(JCMethodDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   860
            if (tree.body == null) return;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   861
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   862
            List<Type> caughtPrev = caught;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   863
            List<Type> mthrown = tree.sym.type.getThrownTypes();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   864
            Lint lintPrev = lint;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   865
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   866
            lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   867
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   868
            Assert.check(pendingExits.isEmpty());
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   869
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   870
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   871
                for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   872
                    JCVariableDecl def = l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   873
                    scan(def);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   874
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   875
                if (TreeInfo.isInitialConstructor(tree))
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   876
                    caught = chk.union(caught, mthrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   877
                else if ((tree.sym.flags() & (BLOCK | STATIC)) != BLOCK)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   878
                    caught = mthrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   879
                // else we are in an instance initializer block;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   880
                // leave caught unchanged.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   881
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   882
                scan(tree.body);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   883
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   884
                List<FlowPendingExit> exits = pendingExits.toList();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   885
                pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   886
                while (exits.nonEmpty()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   887
                    FlowPendingExit exit = exits.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   888
                    exits = exits.tail;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   889
                    if (exit.thrown == null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   890
                        Assert.check(exit.tree.hasTag(RETURN));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   891
                    } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   892
                        // uncaught throws will be reported later
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   893
                        pendingExits.append(exit);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   894
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   895
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   896
            } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   897
                caught = caughtPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   898
                lint = lintPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   899
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   900
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   901
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   902
        public void visitVarDef(JCVariableDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   903
            if (tree.init != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   904
                Lint lintPrev = lint;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
   905
                lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   906
                try{
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   907
                    scan(tree.init);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   908
                } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   909
                    lint = lintPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   910
                }
8428
1e9935b883cd 7017104: improve error reporting for uncaught/undeclared exceptions from try-with-resources
mcimadamore
parents: 8036
diff changeset
   911
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   913
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   914
        public void visitBlock(JCBlock tree) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   915
            scan(tree.stats);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   916
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   918
        public void visitDoLoop(JCDoWhileLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   919
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   920
            pendingExits = new ListBuffer<FlowPendingExit>();
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   921
            scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   922
            resolveContinues(tree);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   923
            scan(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   924
            resolveBreaks(tree, prevPendingExits);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   927
        public void visitWhileLoop(JCWhileLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   928
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   929
            pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   930
            scan(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   931
            scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   932
            resolveContinues(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   933
            resolveBreaks(tree, prevPendingExits);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   934
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   936
        public void visitForLoop(JCForLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   937
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   938
            scan(tree.init);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   939
            pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   940
            if (tree.cond != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   941
                scan(tree.cond);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   942
            }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   943
            scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   944
            resolveContinues(tree);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   945
            scan(tree.step);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   946
            resolveBreaks(tree, prevPendingExits);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   947
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   949
        public void visitForeachLoop(JCEnhancedForLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   950
            visitVarDef(tree.var);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   951
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   952
            scan(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   953
            pendingExits = new ListBuffer<FlowPendingExit>();
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   954
            scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   955
            resolveContinues(tree);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   956
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   957
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   958
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   959
        public void visitLabelled(JCLabeledStatement tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   960
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   961
            pendingExits = new ListBuffer<FlowPendingExit>();
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   962
            scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   963
            resolveBreaks(tree, prevPendingExits);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   965
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   966
        public void visitSwitch(JCSwitch tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   967
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   968
            pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   969
            scan(tree.selector);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   970
            for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   971
                JCCase c = l.head;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   972
                if (c.pat != null) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   973
                    scan(c.pat);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   974
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   975
                scan(c.stats);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   976
            }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
   977
            resolveBreaks(tree, prevPendingExits);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   978
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   980
        public void visitTry(JCTry tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   981
            List<Type> caughtPrev = caught;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   982
            List<Type> thrownPrev = thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   983
            thrown = List.nil();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   984
            for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   985
                List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   986
                        ((JCTypeUnion)l.head.param.vartype).alternatives :
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   987
                        List.of(l.head.param.vartype);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   988
                for (JCExpression ct : subClauses) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   989
                    caught = chk.incl(ct.type, caught);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   990
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   991
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   992
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   993
            ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   994
            pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   995
            for (JCTree resource : tree.resources) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   996
                if (resource instanceof JCVariableDecl) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   997
                    JCVariableDecl vdecl = (JCVariableDecl) resource;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   998
                    visitVarDef(vdecl);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
   999
                } else if (resource instanceof JCExpression) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1000
                    scan((JCExpression) resource);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1001
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1002
                    throw new AssertionError(tree);  // parser error
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1003
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1004
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1005
            for (JCTree resource : tree.resources) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1006
                List<Type> closeableSupertypes = resource.type.isCompound() ?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1007
                    types.interfaces(resource.type).prepend(types.supertype(resource.type)) :
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1008
                    List.of(resource.type);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1009
                for (Type sup : closeableSupertypes) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1010
                    if (types.asSuper(sup, syms.autoCloseableType.tsym) != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1011
                        Symbol closeMethod = rs.resolveQualifiedMethod(tree,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1012
                                attrEnv,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1013
                                sup,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1014
                                names.close,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1015
                                List.<Type>nil(),
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1016
                                List.<Type>nil());
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1017
                        if (closeMethod.kind == MTH) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1018
                            for (Type t : ((MethodSymbol)closeMethod).getThrownTypes()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1019
                                markThrown(resource, t);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1020
                            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1021
                        }
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 3149
diff changeset
  1022
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
            }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1025
            scan(tree.body);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1026
            List<Type> thrownInTry = allowImprovedCatchAnalysis ?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1027
                chk.union(thrown, List.of(syms.runtimeExceptionType, syms.errorType)) :
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1028
                thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1029
            thrown = thrownPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1030
            caught = caughtPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1031
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1032
            List<Type> caughtInTry = List.nil();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1033
            for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1034
                JCVariableDecl param = l.head.param;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1035
                List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1036
                        ((JCTypeUnion)l.head.param.vartype).alternatives :
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1037
                        List.of(l.head.param.vartype);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1038
                List<Type> ctypes = List.nil();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1039
                List<Type> rethrownTypes = chk.diff(thrownInTry, caughtInTry);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1040
                for (JCExpression ct : subClauses) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1041
                    Type exc = ct.type;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1042
                    if (exc != syms.unknownType) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1043
                        ctypes = ctypes.append(exc);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1044
                        if (types.isSameType(exc, syms.objectType))
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1045
                            continue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1046
                        checkCaughtType(l.head.pos(), exc, thrownInTry, caughtInTry);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1047
                        caughtInTry = chk.incl(exc, caughtInTry);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1048
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1049
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1050
                scan(param);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1051
                preciseRethrowTypes.put(param.sym, chk.intersect(ctypes, rethrownTypes));
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1052
                scan(l.head.body);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1053
                preciseRethrowTypes.remove(param.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1054
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1055
            if (tree.finalizer != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1056
                List<Type> savedThrown = thrown;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1057
                thrown = List.nil();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1058
                ListBuffer<FlowPendingExit> exits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1059
                pendingExits = prevPendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1060
                scan(tree.finalizer);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1061
                if (!tree.finallyCanCompleteNormally) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1062
                    // discard exits and exceptions from try and finally
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1063
                    thrown = chk.union(thrown, thrownPrev);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1064
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1065
                    thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1066
                    thrown = chk.union(thrown, savedThrown);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1067
                    // FIX: this doesn't preserve source order of exits in catch
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1068
                    // versus finally!
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1069
                    while (exits.nonEmpty()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1070
                        pendingExits.append(exits.next());
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1071
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1072
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1073
            } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1074
                thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1075
                ListBuffer<FlowPendingExit> exits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1076
                pendingExits = prevPendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1077
                while (exits.nonEmpty()) pendingExits.append(exits.next());
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1078
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1080
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1081
        @Override
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1082
        public void visitIf(JCIf tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1083
            scan(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1084
            scan(tree.thenpart);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1085
            if (tree.elsepart != null) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1086
                scan(tree.elsepart);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1087
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1088
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1090
        void checkCaughtType(DiagnosticPosition pos, Type exc, List<Type> thrownInTry, List<Type> caughtInTry) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1091
            if (chk.subset(exc, caughtInTry)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1092
                log.error(pos, "except.already.caught", exc);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1093
            } else if (!chk.isUnchecked(pos, exc) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1094
                    !isExceptionOrThrowable(exc) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1095
                    !chk.intersects(exc, thrownInTry)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1096
                log.error(pos, "except.never.thrown.in.try", exc);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1097
            } else if (allowImprovedCatchAnalysis) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1098
                List<Type> catchableThrownTypes = chk.intersect(List.of(exc), thrownInTry);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1099
                // 'catchableThrownTypes' cannnot possibly be empty - if 'exc' was an
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1100
                // unchecked exception, the result list would not be empty, as the augmented
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1101
                // thrown set includes { RuntimeException, Error }; if 'exc' was a checked
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1102
                // exception, that would have been covered in the branch above
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1103
                if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty() &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1104
                        !isExceptionOrThrowable(exc)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1105
                    String key = catchableThrownTypes.length() == 1 ?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1106
                            "unreachable.catch" :
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1107
                            "unreachable.catch.1";
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1108
                    log.warning(pos, key, catchableThrownTypes);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1109
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1110
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1111
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1112
        //where
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1113
            private boolean isExceptionOrThrowable(Type exc) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1114
                return exc.tsym == syms.throwableType.tsym ||
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1115
                    exc.tsym == syms.exceptionType.tsym;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1116
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1117
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1118
        public void visitBreak(JCBreak tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1119
            recordExit(tree, new FlowPendingExit(tree, null));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1120
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1121
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1122
        public void visitContinue(JCContinue tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1123
            recordExit(tree, new FlowPendingExit(tree, null));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1124
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1125
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1126
        public void visitReturn(JCReturn tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1127
            scan(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1128
            recordExit(tree, new FlowPendingExit(tree, null));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1129
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1130
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1131
        public void visitThrow(JCThrow tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1132
            scan(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1133
            Symbol sym = TreeInfo.symbol(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1134
            if (sym != null &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1135
                sym.kind == VAR &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1136
                (sym.flags() & (FINAL | EFFECTIVELY_FINAL)) != 0 &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1137
                preciseRethrowTypes.get(sym) != null &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1138
                allowImprovedRethrowAnalysis) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1139
                for (Type t : preciseRethrowTypes.get(sym)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1140
                    markThrown(tree, t);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1141
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1142
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1143
            else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1144
                markThrown(tree, tree.expr.type);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1145
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1146
            markDead();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1147
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1148
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1149
        public void visitApply(JCMethodInvocation tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1150
            scan(tree.meth);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1151
            scan(tree.args);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1152
            for (List<Type> l = tree.meth.type.getThrownTypes(); l.nonEmpty(); l = l.tail)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1153
                markThrown(tree, l.head);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1154
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1155
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1156
        public void visitNewClass(JCNewClass tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1157
            scan(tree.encl);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1158
            scan(tree.args);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1159
           // scan(tree.def);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1160
            for (List<Type> l = tree.constructorType.getThrownTypes();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1161
                 l.nonEmpty();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1162
                 l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1163
                markThrown(tree, l.head);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1164
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1165
            List<Type> caughtPrev = caught;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1166
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1167
                // If the new class expression defines an anonymous class,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1168
                // analysis of the anonymous constructor may encounter thrown
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1169
                // types which are unsubstituted type variables.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1170
                // However, since the constructor's actual thrown types have
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1171
                // already been marked as thrown, it is safe to simply include
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1172
                // each of the constructor's formal thrown types in the set of
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1173
                // 'caught/declared to be thrown' types, for the duration of
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1174
                // the class def analysis.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1175
                if (tree.def != null)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1176
                    for (List<Type> l = tree.constructor.type.getThrownTypes();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1177
                         l.nonEmpty();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1178
                         l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1179
                        caught = chk.incl(l.head, caught);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1180
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1181
                scan(tree.def);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1182
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1183
            finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1184
                caught = caughtPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1185
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1186
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1187
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1188
        public void visitTopLevel(JCCompilationUnit tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1189
            // Do nothing for TopLevel since each class is visited individually
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1190
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1191
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1192
    /**************************************************************************
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1193
     * main method
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1194
     *************************************************************************/
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1195
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1196
        /** Perform definite assignment/unassignment analysis on a tree.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1197
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1198
        public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1199
            analyzeTree(env, env.tree, make);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1200
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1201
        public void analyzeTree(Env<AttrContext> env, JCTree tree, TreeMaker make) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1202
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1203
                attrEnv = env;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1204
                Flow.this.make = make;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1205
                pendingExits = new ListBuffer<FlowPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1206
                preciseRethrowTypes = new HashMap<Symbol, List<Type>>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1207
                this.thrown = this.caught = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1208
                this.classDef = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1209
                scan(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1210
            } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1211
                pendingExits = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1212
                Flow.this.make = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1213
                this.thrown = this.caught = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1214
                this.classDef = null;
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6156
diff changeset
  1215
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1219
    /**
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1220
     * This pass implements (i) definite assignment analysis, which ensures that
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1221
     * each variable is assigned when used and (ii) definite unassignment analysis,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1222
     * which ensures that no final variable is assigned more than once. This visitor
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1223
     * depends on the results of the liveliness analyzer. This pass is also used to mark
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1224
     * effectively-final local variables/parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
     */
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1226
    class AssignAnalyzer extends BaseAnalyzer<AssignAnalyzer.AssignPendingExit> {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1227
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1228
        /** The set of definitely assigned variables.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1229
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1230
        Bits inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1231
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1232
        /** The set of definitely unassigned variables.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1233
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1234
        Bits uninits;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1236
        /** The set of variables that are definitely unassigned everywhere
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1237
         *  in current try block. This variable is maintained lazily; it is
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1238
         *  updated only when something gets removed from uninits,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1239
         *  typically by being assigned in reachable code.  To obtain the
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1240
         *  correct set of variables which are definitely unassigned
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1241
         *  anywhere in current try block, intersect uninitsTry and
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1242
         *  uninits.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1243
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1244
        Bits uninitsTry;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1246
        /** When analyzing a condition, inits and uninits are null.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1247
         *  Instead we have:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1248
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1249
        Bits initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1250
        Bits initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1251
        Bits uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1252
        Bits uninitsWhenFalse;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1254
        /** A mapping from addresses to variable symbols.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1255
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1256
        VarSymbol[] vars;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1257
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1258
        /** The current class being defined.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1259
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1260
        JCClassDecl classDef;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1261
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1262
        /** The first variable sequence number in this class definition.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1263
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1264
        int firstadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1265
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1266
        /** The next available variable sequence number.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1267
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1268
        int nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1269
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1270
        /** The list of unreferenced automatic resources.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1271
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1272
        Scope unrefdResources;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1273
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1274
        /** Set when processing a loop body the second time for DU analysis. */
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1275
        FlowKind flowKind = FlowKind.NORMAL;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1276
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1277
        /** The starting position of the analysed tree */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1278
        int startPos;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1279
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1280
        class AssignPendingExit extends BaseAnalyzer.PendingExit {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1281
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1282
            Bits exit_inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1283
            Bits exit_uninits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1284
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1285
            AssignPendingExit(JCTree tree, Bits inits, Bits uninits) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1286
                super(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1287
                this.exit_inits = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1288
                this.exit_uninits = uninits.dup();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1291
            void resolveJump() {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1292
                inits.andSet(exit_inits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1293
                uninits.andSet(exit_uninits);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1297
        @Override
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1298
        void markDead() {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1299
            inits.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1300
            uninits.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1301
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1302
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1303
        /*-------------- Processing variables ----------------------*/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1305
        /** Do we need to track init/uninit state of this symbol?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1306
         *  I.e. is symbol either a local or a blank final variable?
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1307
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1308
        boolean trackable(VarSymbol sym) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1309
            return
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1310
                sym.pos >= startPos &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1311
                ((sym.owner.kind == MTH ||
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1312
                 ((sym.flags() & (FINAL | HASINIT | PARAMETER)) == FINAL &&
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1313
                  classDef.sym.isEnclosedBy((ClassSymbol)sym.owner))));
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1314
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1316
        /** Initialize new trackable variable by setting its address field
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1317
         *  to the next available sequence number and entering it under that
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1318
         *  index into the vars array.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1319
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1320
        void newVar(VarSymbol sym) {
14049
3207422a0f9b 7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
jjg
parents: 13689
diff changeset
  1321
            vars = ArrayUtils.ensureCapacity(vars, nextadr);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1322
            if ((sym.flags() & FINAL) == 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1323
                sym.flags_field |= EFFECTIVELY_FINAL;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1324
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1325
            sym.adr = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1326
            vars[nextadr] = sym;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1327
            inits.excl(nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1328
            uninits.incl(nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1329
            nextadr++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1332
        /** Record an initialization of a trackable variable.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1333
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1334
        void letInit(DiagnosticPosition pos, VarSymbol sym) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1335
            if (sym.adr >= firstadr && trackable(sym)) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1336
                if ((sym.flags() & EFFECTIVELY_FINAL) != 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1337
                    if (!uninits.isMember(sym.adr)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1338
                        //assignment targeting an effectively final variable
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1339
                        //makes the variable lose its status of effectively final
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1340
                        //if the variable is _not_ definitively unassigned
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1341
                        sym.flags_field &= ~EFFECTIVELY_FINAL;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1342
                    } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1343
                        uninit(sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1344
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1345
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1346
                else if ((sym.flags() & FINAL) != 0) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1347
                    if ((sym.flags() & PARAMETER) != 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1348
                        if ((sym.flags() & UNION) != 0) { //multi-catch parameter
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1349
                            log.error(pos, "multicatch.parameter.may.not.be.assigned",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1350
                                      sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1351
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1352
                        else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1353
                            log.error(pos, "final.parameter.may.not.be.assigned",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1354
                                  sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1355
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1356
                    } else if (!uninits.isMember(sym.adr)) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1357
                        log.error(pos, flowKind.errKey, sym);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1358
                    } else {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1359
                        uninit(sym);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1360
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1361
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1362
                inits.incl(sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1363
            } else if ((sym.flags() & FINAL) != 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1364
                log.error(pos, "var.might.already.be.assigned", sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1365
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
        }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1367
        //where
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1368
            void uninit(VarSymbol sym) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1369
                if (!inits.isMember(sym.adr)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1370
                    // reachable assignment
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1371
                    uninits.excl(sym.adr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1372
                    uninitsTry.excl(sym.adr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1373
                } else {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1374
                    //log.rawWarning(pos, "unreachable assignment");//DEBUG
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1375
                    uninits.excl(sym.adr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1376
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1377
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1379
        /** If tree is either a simple name or of the form this.name or
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1380
         *  C.this.name, and tree represents a trackable variable,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1381
         *  record an initialization of the variable.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1382
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1383
        void letInit(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1384
            tree = TreeInfo.skipParens(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1385
            if (tree.hasTag(IDENT) || tree.hasTag(SELECT)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1386
                Symbol sym = TreeInfo.symbol(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1387
                if (sym.kind == VAR) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1388
                    letInit(tree.pos(), (VarSymbol)sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1389
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1390
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1391
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1393
        /** Check that trackable variable is initialized.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1394
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1395
        void checkInit(DiagnosticPosition pos, VarSymbol sym) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1396
            if ((sym.adr >= firstadr || sym.owner.kind != TYP) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1397
                trackable(sym) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1398
                !inits.isMember(sym.adr)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1399
                log.error(pos, "var.might.not.have.been.initialized",
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1400
                          sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1401
                inits.incl(sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1402
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1403
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1404
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1405
        /** Split (duplicate) inits/uninits into WhenTrue/WhenFalse sets
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1406
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1407
        void split(boolean setToNull) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
            initsWhenFalse = inits.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
            uninitsWhenFalse = uninits.dup();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
            initsWhenTrue = inits;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
            uninitsWhenTrue = uninits;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1412
            if (setToNull)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1413
                inits = uninits = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1416
        /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1417
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1418
        void merge() {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1419
            inits = initsWhenFalse.andSet(initsWhenTrue);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1420
            uninits = uninitsWhenFalse.andSet(uninitsWhenTrue);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1421
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1423
    /* ************************************************************************
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1424
     * Visitor methods for statements and definitions
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1425
     *************************************************************************/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1427
        /** Analyze an expression. Make sure to set (un)inits rather than
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1428
         *  (un)initsWhenTrue(WhenFalse) on exit.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1429
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1430
        void scanExpr(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1431
            if (tree != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1432
                scan(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1433
                if (inits == null) merge();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1434
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1435
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1437
        /** Analyze a list of expressions.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1438
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1439
        void scanExprs(List<? extends JCExpression> trees) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1440
            if (trees != null)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1441
                for (List<? extends JCExpression> l = trees; l.nonEmpty(); l = l.tail)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1442
                    scanExpr(l.head);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1445
        /** Analyze a condition. Make sure to set (un)initsWhenTrue(WhenFalse)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1446
         *  rather than (un)inits on exit.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1447
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1448
        void scanCond(JCTree tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1449
            if (tree.type.isFalse()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1450
                if (inits == null) merge();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1451
                initsWhenTrue = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1452
                initsWhenTrue.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1453
                uninitsWhenTrue = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1454
                uninitsWhenTrue.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1455
                initsWhenFalse = inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1456
                uninitsWhenFalse = uninits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1457
            } else if (tree.type.isTrue()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1458
                if (inits == null) merge();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1459
                initsWhenFalse = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1460
                initsWhenFalse.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1461
                uninitsWhenFalse = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1462
                uninitsWhenFalse.inclRange(firstadr, nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1463
                initsWhenTrue = inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1464
                uninitsWhenTrue = uninits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1465
            } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1466
                scan(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1467
                if (inits != null)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1468
                    split(tree.type != syms.unknownType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1469
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1470
            if (tree.type != syms.unknownType)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1471
                inits = uninits = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1472
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1474
        /* ------------ Visitor methods for various sorts of trees -------------*/
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1475
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1476
        public void visitClassDef(JCClassDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1477
            if (tree.sym == null) return;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1478
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1479
            JCClassDecl classDefPrev = classDef;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1480
            int firstadrPrev = firstadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1481
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1482
            ListBuffer<AssignPendingExit> pendingExitsPrev = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1483
            Lint lintPrev = lint;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1485
            pendingExits = new ListBuffer<AssignPendingExit>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
            if (tree.name != names.empty) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1487
                firstadr = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1488
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1489
            classDef = tree;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
  1490
            lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1491
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1492
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1493
                // define all the static fields
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1495
                    if (l.head.hasTag(VARDEF)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1496
                        JCVariableDecl def = (JCVariableDecl)l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1497
                        if ((def.mods.flags & STATIC) != 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1498
                            VarSymbol sym = def.sym;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1499
                            if (trackable(sym))
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1500
                                newVar(sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1505
                // process all the static initializers
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1506
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1507
                    if (!l.head.hasTag(METHODDEF) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1508
                        (TreeInfo.flags(l.head) & STATIC) != 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1509
                        scan(l.head);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1513
                // define all the instance fields
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1514
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1515
                    if (l.head.hasTag(VARDEF)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1516
                        JCVariableDecl def = (JCVariableDecl)l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1517
                        if ((def.mods.flags & STATIC) == 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1518
                            VarSymbol sym = def.sym;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1519
                            if (trackable(sym))
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1520
                                newVar(sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1521
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1522
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1525
                // process all the instance initializers
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1527
                    if (!l.head.hasTag(METHODDEF) &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1528
                        (TreeInfo.flags(l.head) & STATIC) == 0) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1529
                        scan(l.head);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1530
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1531
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1532
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1533
                // process all the methods
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1534
                for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1535
                    if (l.head.hasTag(METHODDEF)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1536
                        scan(l.head);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
                }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1539
            } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1540
                pendingExits = pendingExitsPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1541
                nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1542
                firstadr = firstadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1543
                classDef = classDefPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1544
                lint = lintPrev;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1546
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1548
        public void visitMethodDef(JCMethodDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1549
            if (tree.body == null) return;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1551
            Bits initsPrev = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1552
            Bits uninitsPrev = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1553
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1554
            int firstadrPrev = firstadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1555
            Lint lintPrev = lint;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
  1557
            lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1558
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1559
            Assert.check(pendingExits.isEmpty());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1561
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1562
                boolean isInitialConstructor =
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1563
                    TreeInfo.isInitialConstructor(tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1565
                if (!isInitialConstructor)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1566
                    firstadr = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1567
                for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1568
                    JCVariableDecl def = l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1569
                    scan(def);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1570
                    inits.incl(def.sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1571
                    uninits.excl(def.sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1572
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1573
                // else we are in an instance initializer block;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1574
                // leave caught unchanged.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1575
                scan(tree.body);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1576
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1577
                if (isInitialConstructor) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1578
                    for (int i = firstadr; i < nextadr; i++)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1579
                        if (vars[i].owner == classDef.sym)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1580
                            checkInit(TreeInfo.diagEndPos(tree.body), vars[i]);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1581
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1582
                List<AssignPendingExit> exits = pendingExits.toList();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1583
                pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1584
                while (exits.nonEmpty()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1585
                    AssignPendingExit exit = exits.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1586
                    exits = exits.tail;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1587
                    Assert.check(exit.tree.hasTag(RETURN), exit.tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1588
                    if (isInitialConstructor) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1589
                        inits = exit.exit_inits;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1590
                        for (int i = firstadr; i < nextadr; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
                            checkInit(exit.tree.pos(), vars[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
            } finally {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1595
                inits = initsPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1596
                uninits = uninitsPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1597
                nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1598
                firstadr = firstadrPrev;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
                lint = lintPrev;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1600
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1601
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1603
        public void visitVarDef(JCVariableDecl tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1604
            boolean track = trackable(tree.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1605
            if (track && tree.sym.owner.kind == MTH) newVar(tree.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1606
            if (tree.init != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1607
                Lint lintPrev = lint;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13439
diff changeset
  1608
                lint = lint.augment(tree.sym.annotations);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1609
                try{
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1610
                    scanExpr(tree.init);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1611
                    if (track) letInit(tree.pos(), tree.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1612
                } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1613
                    lint = lintPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1614
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1615
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1616
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1617
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1618
        public void visitBlock(JCBlock tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1619
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1620
            scan(tree.stats);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1621
            nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1622
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1624
        public void visitDoLoop(JCDoWhileLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1625
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1626
            FlowKind prevFlowKind = flowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1627
            flowKind = FlowKind.NORMAL;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1628
            Bits initsSkip = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1629
            Bits uninitsSkip = null;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1630
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1631
            int prevErrors = log.nerrors;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1632
            do {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1633
                Bits uninitsEntry = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1634
                uninitsEntry.excludeFrom(nextadr);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1635
                scan(tree.body);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1636
                resolveContinues(tree);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1637
                scanCond(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1638
                if (!flowKind.isFinal()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1639
                    initsSkip = initsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1640
                    uninitsSkip = uninitsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1641
                }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1642
                if (log.nerrors !=  prevErrors ||
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1643
                    flowKind.isFinal() ||
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1644
                    uninitsEntry.dup().diffSet(uninitsWhenTrue).nextBit(firstadr)==-1)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1645
                    break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1646
                inits = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1647
                uninits = uninitsEntry.andSet(uninitsWhenTrue);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1648
                flowKind = FlowKind.SPECULATIVE_LOOP;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1649
            } while (true);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1650
            flowKind = prevFlowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1651
            inits = initsSkip;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1652
            uninits = uninitsSkip;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1653
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1654
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1656
        public void visitWhileLoop(JCWhileLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1657
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1658
            FlowKind prevFlowKind = flowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1659
            flowKind = FlowKind.NORMAL;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1660
            Bits initsSkip = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1661
            Bits uninitsSkip = null;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1662
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1663
            int prevErrors = log.nerrors;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1664
            Bits uninitsEntry = uninits.dup();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1665
            uninitsEntry.excludeFrom(nextadr);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1666
            do {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
                scanCond(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1668
                if (!flowKind.isFinal()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1669
                    initsSkip = initsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1670
                    uninitsSkip = uninitsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1671
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
                inits = initsWhenTrue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
                uninits = uninitsWhenTrue;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1674
                scan(tree.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1675
                resolveContinues(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1676
                if (log.nerrors != prevErrors ||
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1677
                    flowKind.isFinal() ||
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1678
                    uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1679
                    break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1680
                uninits = uninitsEntry.andSet(uninits);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1681
                flowKind = FlowKind.SPECULATIVE_LOOP;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1682
            } while (true);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1683
            flowKind = prevFlowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1684
            //a variable is DA/DU after the while statement, if it's DA/DU assuming the
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1685
            //branch is not taken AND if it's DA/DU before any break statement
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1686
            inits = initsSkip;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1687
            uninits = uninitsSkip;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1688
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1689
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1691
        public void visitForLoop(JCForLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1692
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1693
            FlowKind prevFlowKind = flowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1694
            flowKind = FlowKind.NORMAL;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1695
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1696
            scan(tree.init);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1697
            Bits initsSkip = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1698
            Bits uninitsSkip = null;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1699
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1700
            int prevErrors = log.nerrors;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1701
            do {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1702
                Bits uninitsEntry = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1703
                uninitsEntry.excludeFrom(nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1704
                if (tree.cond != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1705
                    scanCond(tree.cond);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1706
                    if (!flowKind.isFinal()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1707
                        initsSkip = initsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1708
                        uninitsSkip = uninitsWhenFalse;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1709
                    }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1710
                    inits = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1711
                    uninits = uninitsWhenTrue;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1712
                } else if (!flowKind.isFinal()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1713
                    initsSkip = inits.dup();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1714
                    initsSkip.inclRange(firstadr, nextadr);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1715
                    uninitsSkip = uninits.dup();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1716
                    uninitsSkip.inclRange(firstadr, nextadr);
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1717
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1718
                scan(tree.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1719
                resolveContinues(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1720
                scan(tree.step);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1721
                if (log.nerrors != prevErrors ||
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1722
                    flowKind.isFinal() ||
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1723
                    uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1724
                    break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1725
                uninits = uninitsEntry.andSet(uninits);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1726
                flowKind = FlowKind.SPECULATIVE_LOOP;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1727
            } while (true);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1728
            flowKind = prevFlowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1729
            //a variable is DA/DU after a for loop, if it's DA/DU assuming the
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1730
            //branch is not taken AND if it's DA/DU before any break statement
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1731
            inits = initsSkip;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1732
            uninits = uninitsSkip;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1733
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1734
            nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1735
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1737
        public void visitForeachLoop(JCEnhancedForLoop tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1738
            visitVarDef(tree.var);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1739
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1740
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1741
            FlowKind prevFlowKind = flowKind;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1742
            flowKind = FlowKind.NORMAL;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1743
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1744
            scan(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1745
            Bits initsStart = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1746
            Bits uninitsStart = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1747
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1748
            letInit(tree.pos(), tree.var.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1749
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1750
            int prevErrors = log.nerrors;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1751
            do {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1752
                Bits uninitsEntry = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1753
                uninitsEntry.excludeFrom(nextadr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1754
                scan(tree.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1755
                resolveContinues(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1756
                if (log.nerrors != prevErrors ||
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1757
                    flowKind.isFinal() ||
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1758
                    uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1759
                    break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1760
                uninits = uninitsEntry.andSet(uninits);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1761
                flowKind = FlowKind.SPECULATIVE_LOOP;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1762
            } while (true);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  1763
            flowKind = prevFlowKind;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1764
            inits = initsStart;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1765
            uninits = uninitsStart.andSet(uninits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1766
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1767
            nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1768
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1769
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1770
        public void visitLabelled(JCLabeledStatement tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1771
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1772
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1773
            scan(tree.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1774
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1775
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1777
        public void visitSwitch(JCSwitch tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1778
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1779
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1780
            int nextadrPrev = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1781
            scanExpr(tree.selector);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1782
            Bits initsSwitch = inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1783
            Bits uninitsSwitch = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1784
            boolean hasDefault = false;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1785
            for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1786
                inits = initsSwitch.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1787
                uninits = uninits.andSet(uninitsSwitch);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1788
                JCCase c = l.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1789
                if (c.pat == null)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1790
                    hasDefault = true;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1791
                else
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1792
                    scanExpr(c.pat);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1793
                scan(c.stats);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1794
                addVars(c.stats, initsSwitch, uninitsSwitch);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1795
                // Warn about fall-through if lint switch fallthrough enabled.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1796
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1797
            if (!hasDefault) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1798
                inits.andSet(initsSwitch);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1799
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1800
            resolveBreaks(tree, prevPendingExits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1801
            nextadr = nextadrPrev;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1802
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1803
        // where
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1804
            /** Add any variables defined in stats to inits and uninits. */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1805
            private void addVars(List<JCStatement> stats, Bits inits,
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1806
                                        Bits uninits) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1807
                for (;stats.nonEmpty(); stats = stats.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1808
                    JCTree stat = stats.head;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1809
                    if (stat.hasTag(VARDEF)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1810
                        int adr = ((JCVariableDecl) stat).sym.adr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1811
                        inits.excl(adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1812
                        uninits.incl(adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1813
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1814
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1815
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1817
        public void visitTry(JCTry tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1818
            ListBuffer<JCVariableDecl> resourceVarDecls = ListBuffer.lb();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1819
            Bits uninitsTryPrev = uninitsTry;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1820
            ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1821
            pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1822
            Bits initsTry = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1823
            uninitsTry = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1824
            for (JCTree resource : tree.resources) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1825
                if (resource instanceof JCVariableDecl) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1826
                    JCVariableDecl vdecl = (JCVariableDecl) resource;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1827
                    visitVarDef(vdecl);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1828
                    unrefdResources.enter(vdecl.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1829
                    resourceVarDecls.append(vdecl);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1830
                } else if (resource instanceof JCExpression) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1831
                    scanExpr((JCExpression) resource);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1832
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1833
                    throw new AssertionError(tree);  // parser error
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1834
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1835
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1836
            scan(tree.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1837
            uninitsTry.andSet(uninits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1838
            Bits initsEnd = inits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1839
            Bits uninitsEnd = uninits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1840
            int nextadrCatch = nextadr;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1841
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1842
            if (!resourceVarDecls.isEmpty() &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1843
                    lint.isEnabled(Lint.LintCategory.TRY)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1844
                for (JCVariableDecl resVar : resourceVarDecls) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1845
                    if (unrefdResources.includes(resVar.sym)) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1846
                        log.warning(Lint.LintCategory.TRY, resVar.pos(),
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1847
                                    "try.resource.not.referenced", resVar.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1848
                        unrefdResources.remove(resVar.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1849
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1850
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1851
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1853
            for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1854
                JCVariableDecl param = l.head.param;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1855
                inits = initsTry.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1856
                uninits = uninitsTry.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1857
                scan(param);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1858
                inits.incl(param.sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1859
                uninits.excl(param.sym.adr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1860
                scan(l.head.body);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1861
                initsEnd.andSet(inits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1862
                uninitsEnd.andSet(uninits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1863
                nextadr = nextadrCatch;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1864
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1865
            if (tree.finalizer != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1866
                inits = initsTry.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1867
                uninits = uninitsTry.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1868
                ListBuffer<AssignPendingExit> exits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1869
                pendingExits = prevPendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1870
                scan(tree.finalizer);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1871
                if (!tree.finallyCanCompleteNormally) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1872
                    // discard exits and exceptions from try and finally
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1873
                } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1874
                    uninits.andSet(uninitsEnd);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1875
                    // FIX: this doesn't preserve source order of exits in catch
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1876
                    // versus finally!
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1877
                    while (exits.nonEmpty()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1878
                        AssignPendingExit exit = exits.next();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1879
                        if (exit.exit_inits != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1880
                            exit.exit_inits.orSet(inits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1881
                            exit.exit_uninits.andSet(uninits);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1882
                        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1883
                        pendingExits.append(exit);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1884
                    }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1885
                    inits.orSet(initsEnd);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1886
                }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1887
            } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1888
                inits = initsEnd;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1889
                uninits = uninitsEnd;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1890
                ListBuffer<AssignPendingExit> exits = pendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1891
                pendingExits = prevPendingExits;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1892
                while (exits.nonEmpty()) pendingExits.append(exits.next());
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1893
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1894
            uninitsTry.andSet(uninitsTryPrev).andSet(uninits);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1896
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1897
        public void visitConditional(JCConditional tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1898
            scanCond(tree.cond);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1899
            Bits initsBeforeElse = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1900
            Bits uninitsBeforeElse = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1901
            inits = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1902
            uninits = uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1903
            if (tree.truepart.type.tag == BOOLEAN &&
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1904
                tree.falsepart.type.tag == BOOLEAN) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1905
                // if b and c are boolean valued, then
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1906
                // v is (un)assigned after a?b:c when true iff
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1907
                //    v is (un)assigned after b when true and
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1908
                //    v is (un)assigned after c when true
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1909
                scanCond(tree.truepart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1910
                Bits initsAfterThenWhenTrue = initsWhenTrue.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1911
                Bits initsAfterThenWhenFalse = initsWhenFalse.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1912
                Bits uninitsAfterThenWhenTrue = uninitsWhenTrue.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1913
                Bits uninitsAfterThenWhenFalse = uninitsWhenFalse.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1914
                inits = initsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1915
                uninits = uninitsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1916
                scanCond(tree.falsepart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1917
                initsWhenTrue.andSet(initsAfterThenWhenTrue);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1918
                initsWhenFalse.andSet(initsAfterThenWhenFalse);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1919
                uninitsWhenTrue.andSet(uninitsAfterThenWhenTrue);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1920
                uninitsWhenFalse.andSet(uninitsAfterThenWhenFalse);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1921
            } else {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1922
                scanExpr(tree.truepart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1923
                Bits initsAfterThen = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1924
                Bits uninitsAfterThen = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1925
                inits = initsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1926
                uninits = uninitsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1927
                scanExpr(tree.falsepart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1928
                inits.andSet(initsAfterThen);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1929
                uninits.andSet(uninitsAfterThen);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1930
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1931
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1932
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1933
        public void visitIf(JCIf tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1934
            scanCond(tree.cond);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1935
            Bits initsBeforeElse = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1936
            Bits uninitsBeforeElse = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1937
            inits = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1938
            uninits = uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1939
            scan(tree.thenpart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1940
            if (tree.elsepart != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1941
                Bits initsAfterThen = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1942
                Bits uninitsAfterThen = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1943
                inits = initsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1944
                uninits = uninitsBeforeElse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1945
                scan(tree.elsepart);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1946
                inits.andSet(initsAfterThen);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1947
                uninits.andSet(uninitsAfterThen);
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1948
            } else {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1949
                inits.andSet(initsBeforeElse);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1950
                uninits.andSet(uninitsBeforeElse);
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1951
            }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1952
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1953
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1954
        public void visitBreak(JCBreak tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1955
            recordExit(tree, new AssignPendingExit(tree, inits, uninits));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1956
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1957
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1958
        public void visitContinue(JCContinue tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1959
            recordExit(tree, new AssignPendingExit(tree, inits, uninits));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1960
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1961
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1962
        public void visitReturn(JCReturn tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1963
            scanExpr(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1964
            recordExit(tree, new AssignPendingExit(tree, inits, uninits));
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1965
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1966
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1967
        public void visitThrow(JCThrow tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1968
            scanExpr(tree.expr);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1969
            markDead();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1970
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1971
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1972
        public void visitApply(JCMethodInvocation tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1973
            scanExpr(tree.meth);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1974
            scanExprs(tree.args);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1975
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1976
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1977
        public void visitNewClass(JCNewClass tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1978
            scanExpr(tree.encl);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1979
            scanExprs(tree.args);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1980
            scan(tree.def);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1981
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1982
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1983
        public void visitNewArray(JCNewArray tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1984
            scanExprs(tree.dims);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1985
            scanExprs(tree.elems);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1986
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1987
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1988
        public void visitAssert(JCAssert tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1989
            Bits initsExit = inits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1990
            Bits uninitsExit = uninits.dup();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1991
            scanCond(tree.cond);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1992
            uninitsExit.andSet(uninitsWhenTrue);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1993
            if (tree.detail != null) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1994
                inits = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1995
                uninits = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1996
                scanExpr(tree.detail);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1997
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1998
            inits = initsExit;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  1999
            uninits = uninitsExit;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2000
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2001
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2002
        public void visitAssign(JCAssign tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2003
            JCTree lhs = TreeInfo.skipParens(tree.lhs);
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2004
            if (!(lhs instanceof JCIdent)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2005
                scanExpr(lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2006
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2007
            scanExpr(tree.rhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2008
            letInit(lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2009
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2010
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2011
        public void visitAssignop(JCAssignOp tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2012
            scanExpr(tree.lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2013
            scanExpr(tree.rhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2014
            letInit(tree.lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2015
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2016
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2017
        public void visitUnary(JCUnary tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2018
            switch (tree.getTag()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2019
            case NOT:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2020
                scanCond(tree.arg);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2021
                Bits t = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2022
                initsWhenFalse = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2023
                initsWhenTrue = t;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2024
                t = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2025
                uninitsWhenFalse = uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2026
                uninitsWhenTrue = t;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2027
                break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2028
            case PREINC: case POSTINC:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2029
            case PREDEC: case POSTDEC:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2030
                scanExpr(tree.arg);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2031
                letInit(tree.arg);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2032
                break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2033
            default:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2034
                scanExpr(tree.arg);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2035
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2036
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2037
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2038
        public void visitBinary(JCBinary tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2039
            switch (tree.getTag()) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2040
            case AND:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2041
                scanCond(tree.lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2042
                Bits initsWhenFalseLeft = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2043
                Bits uninitsWhenFalseLeft = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2044
                inits = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2045
                uninits = uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2046
                scanCond(tree.rhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2047
                initsWhenFalse.andSet(initsWhenFalseLeft);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2048
                uninitsWhenFalse.andSet(uninitsWhenFalseLeft);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2049
                break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2050
            case OR:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2051
                scanCond(tree.lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2052
                Bits initsWhenTrueLeft = initsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2053
                Bits uninitsWhenTrueLeft = uninitsWhenTrue;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2054
                inits = initsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2055
                uninits = uninitsWhenFalse;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2056
                scanCond(tree.rhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2057
                initsWhenTrue.andSet(initsWhenTrueLeft);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2058
                uninitsWhenTrue.andSet(uninitsWhenTrueLeft);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2059
                break;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2060
            default:
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2061
                scanExpr(tree.lhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2062
                scanExpr(tree.rhs);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2063
            }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2064
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2065
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2066
        public void visitIdent(JCIdent tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2067
            if (tree.sym.kind == VAR) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2068
                checkInit(tree.pos(), (VarSymbol)tree.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2069
                referenced(tree.sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2070
            }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2071
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2072
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2073
        void referenced(Symbol sym) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2074
            unrefdResources.remove(sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2075
        }
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2076
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2077
        public void visitTopLevel(JCCompilationUnit tree) {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2078
            // Do nothing for TopLevel since each class is visited individually
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2079
        }
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2080
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2081
    /**************************************************************************
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2082
     * main method
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2083
     *************************************************************************/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2084
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2085
        /** Perform definite assignment/unassignment analysis on a tree.
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2086
         */
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2087
        public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2088
            analyzeTree(env, env.tree, make);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2089
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2090
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2091
        public void analyzeTree(Env<AttrContext> env, JCTree tree, TreeMaker make) {
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2092
            try {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2093
                attrEnv = env;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2094
                Flow.this.make = make;
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2095
                startPos = tree.pos().getStartPosition();
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2096
                inits = new Bits();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2097
                uninits = new Bits();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2098
                uninitsTry = new Bits();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2099
                initsWhenTrue = initsWhenFalse =
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2100
                    uninitsWhenTrue = uninitsWhenFalse = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2101
                if (vars == null)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2102
                    vars = new VarSymbol[32];
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2103
                else
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2104
                    for (int i=0; i<vars.length; i++)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2105
                        vars[i] = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2106
                firstadr = 0;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2107
                nextadr = 0;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2108
                pendingExits = new ListBuffer<AssignPendingExit>();
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2109
                this.classDef = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2110
                unrefdResources = new Scope(env.enclClass.sym);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2111
                scan(tree);
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2112
            } finally {
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2113
                // note that recursive invocations of this method fail hard
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2114
                startPos = -1;
12333
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2115
                inits = uninits = uninitsTry = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2116
                initsWhenTrue = initsWhenFalse =
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2117
                    uninitsWhenTrue = uninitsWhenFalse = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2118
                if (vars != null) for (int i=0; i<vars.length; i++)
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2119
                    vars[i] = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2120
                firstadr = 0;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2121
                nextadr = 0;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2122
                pendingExits = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2123
                Flow.this.make = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2124
                this.classDef = null;
7b02d0529a97 7151580: Separate DA/DU logic from exception checking logic in Flow.java
mcimadamore
parents: 10950
diff changeset
  2125
                unrefdResources = null;
8849
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
  2126
            }
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
  2127
        }
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 8627
diff changeset
  2128
    }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2129
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2130
    /**
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2131
     * This pass implements the last step of the dataflow analysis, namely
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2132
     * the effectively-final analysis check. This checks that every local variable
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2133
     * reference from a lambda body/local inner class is either final or effectively final.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2134
     * As effectively final variables are marked as such during DA/DU, this pass must run after
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2135
     * AssignAnalyzer.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2136
     */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2137
    class CaptureAnalyzer extends BaseAnalyzer<BaseAnalyzer.PendingExit> {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2138
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2139
        JCTree currentTree; //local class or lambda
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2140
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2141
        @Override
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2142
        void markDead() {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2143
            //do nothing
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2144
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2145
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2146
        @SuppressWarnings("fallthrough")
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2147
        void checkEffectivelyFinal(DiagnosticPosition pos, VarSymbol sym) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2148
            if (currentTree != null &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2149
                    sym.owner.kind == MTH &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2150
                    sym.pos < currentTree.getStartPosition()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2151
                switch (currentTree.getTag()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2152
                    case CLASSDEF:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2153
                        if (!allowEffectivelyFinalInInnerClasses) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2154
                            if ((sym.flags() & FINAL) == 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2155
                                reportInnerClsNeedsFinalError(pos, sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2156
                            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2157
                            break;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2158
                        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2159
                    case LAMBDA:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2160
                        if ((sym.flags() & (EFFECTIVELY_FINAL | FINAL)) == 0) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2161
                           reportEffectivelyFinalError(pos, sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2162
                        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2163
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2164
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2165
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2166
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2167
        @SuppressWarnings("fallthrough")
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2168
        void letInit(JCTree tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2169
            tree = TreeInfo.skipParens(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2170
            if (tree.hasTag(IDENT) || tree.hasTag(SELECT)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2171
                Symbol sym = TreeInfo.symbol(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2172
                if (currentTree != null &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2173
                        sym.kind == VAR &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2174
                        sym.owner.kind == MTH &&
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2175
                        ((VarSymbol)sym).pos < currentTree.getStartPosition()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2176
                    switch (currentTree.getTag()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2177
                        case CLASSDEF:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2178
                            if (!allowEffectivelyFinalInInnerClasses) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2179
                                reportInnerClsNeedsFinalError(tree, sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2180
                                break;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2181
                            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2182
                        case LAMBDA:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2183
                            reportEffectivelyFinalError(tree, sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2184
                    }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2185
                }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2186
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2187
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2188
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2189
        void reportEffectivelyFinalError(DiagnosticPosition pos, Symbol sym) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2190
            String subKey = currentTree.hasTag(LAMBDA) ?
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2191
                  "lambda"  : "inner.cls";
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2192
            log.error(pos, "cant.ref.non.effectively.final.var", sym, diags.fragment(subKey));
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2193
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2194
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2195
        void reportInnerClsNeedsFinalError(DiagnosticPosition pos, Symbol sym) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2196
            log.error(pos,
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2197
                    "local.var.accessed.from.icls.needs.final",
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2198
                    sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2199
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2200
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2201
    /*************************************************************************
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2202
     * Visitor methods for statements and definitions
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2203
     *************************************************************************/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2204
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2205
        /* ------------ Visitor methods for various sorts of trees -------------*/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2206
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2207
        public void visitClassDef(JCClassDecl tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2208
            JCTree prevTree = currentTree;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2209
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2210
                currentTree = tree.sym.isLocal() ? tree : null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2211
                super.visitClassDef(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2212
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2213
                currentTree = prevTree;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2214
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2215
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2216
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2217
        @Override
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2218
        public void visitLambda(JCLambda tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2219
            JCTree prevTree = currentTree;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2220
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2221
                currentTree = tree;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2222
                super.visitLambda(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2223
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2224
                currentTree = prevTree;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2225
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2226
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2227
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2228
        @Override
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2229
        public void visitIdent(JCIdent tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2230
            if (tree.sym.kind == VAR) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2231
                checkEffectivelyFinal(tree, (VarSymbol)tree.sym);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2232
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2233
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2234
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2235
        public void visitAssign(JCAssign tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2236
            JCTree lhs = TreeInfo.skipParens(tree.lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2237
            if (!(lhs instanceof JCIdent)) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2238
                scan(lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2239
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2240
            scan(tree.rhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2241
            letInit(lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2242
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2243
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2244
        public void visitAssignop(JCAssignOp tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2245
            scan(tree.lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2246
            scan(tree.rhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2247
            letInit(tree.lhs);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2248
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2249
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2250
        public void visitUnary(JCUnary tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2251
            switch (tree.getTag()) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2252
                case PREINC: case POSTINC:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2253
                case PREDEC: case POSTDEC:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2254
                    scan(tree.arg);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2255
                    letInit(tree.arg);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2256
                    break;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2257
                default:
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2258
                    scan(tree.arg);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2259
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2260
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2261
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2262
        public void visitTopLevel(JCCompilationUnit tree) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2263
            // Do nothing for TopLevel since each class is visited individually
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2264
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2265
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2266
    /**************************************************************************
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2267
     * main method
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2268
     *************************************************************************/
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2269
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2270
        /** Perform definite assignment/unassignment analysis on a tree.
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2271
         */
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2272
        public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2273
            analyzeTree(env, env.tree, make);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2274
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2275
        public void analyzeTree(Env<AttrContext> env, JCTree tree, TreeMaker make) {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2276
            try {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2277
                attrEnv = env;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2278
                Flow.this.make = make;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2279
                pendingExits = new ListBuffer<PendingExit>();
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2280
                scan(tree);
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2281
            } finally {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2282
                pendingExits = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2283
                Flow.this.make = null;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2284
            }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2285
        }
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 13273
diff changeset
  2286
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2287
}