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