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