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