author | jlahoda |
Wed, 27 Nov 2019 09:00:01 +0100 | |
changeset 59285 | 7799a51dbe30 |
permissions | -rw-r--r-- |
59285
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
1 |
/* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
4 |
* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
10 |
* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
15 |
* accompanied this code). |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
16 |
* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
20 |
* |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
23 |
* questions. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
24 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
25 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.comp; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
27 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
28 |
import com.sun.tools.javac.code.Flags; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
29 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
30 |
import com.sun.tools.javac.code.Symtab; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
31 |
import com.sun.tools.javac.code.Type; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
32 |
import com.sun.tools.javac.code.Types; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.tree.JCTree; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.tree.JCTree.JCAssign; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.tree.JCTree.JCBinary; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.tree.JCTree.JCConditional; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
38 |
import com.sun.tools.javac.tree.JCTree.JCExpression; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.tree.JCTree.JCForLoop; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.tree.JCTree.JCIdent; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.tree.JCTree.JCIf; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.tree.JCTree.JCInstanceOf; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
43 |
import com.sun.tools.javac.tree.JCTree.JCLabeledStatement; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
44 |
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
45 |
import com.sun.tools.javac.tree.JCTree.JCStatement; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
46 |
import com.sun.tools.javac.tree.JCTree.JCVariableDecl; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
47 |
import com.sun.tools.javac.tree.JCTree.JCBindingPattern; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
48 |
import com.sun.tools.javac.tree.JCTree.JCWhileLoop; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
49 |
import com.sun.tools.javac.tree.JCTree.Tag; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
50 |
import com.sun.tools.javac.tree.TreeMaker; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
51 |
import com.sun.tools.javac.tree.TreeTranslator; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
52 |
import com.sun.tools.javac.util.Assert; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
53 |
import com.sun.tools.javac.util.Context; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
54 |
import com.sun.tools.javac.util.List; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
55 |
import com.sun.tools.javac.util.ListBuffer; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
56 |
import com.sun.tools.javac.util.Log; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
57 |
import com.sun.tools.javac.util.Names; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
58 |
import com.sun.tools.javac.util.Options; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
59 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
60 |
import java.util.Map; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
61 |
import java.util.Map.Entry; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
62 |
import java.util.stream.Collectors; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
63 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
64 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
65 |
import static com.sun.tools.javac.code.TypeTag.BOOLEAN; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
66 |
import static com.sun.tools.javac.code.TypeTag.BOT; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
67 |
import com.sun.tools.javac.comp.MatchBindingsComputer.BindingSymbol; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
68 |
import com.sun.tools.javac.jvm.Target; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
69 |
import com.sun.tools.javac.tree.JCTree.JCBlock; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
70 |
import com.sun.tools.javac.tree.JCTree.JCDoWhileLoop; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
71 |
import com.sun.tools.javac.tree.JCTree.JCStatement; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
72 |
import com.sun.tools.javac.tree.JCTree.LetExpr; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
73 |
import com.sun.tools.javac.util.List; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
74 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
75 |
/** |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
76 |
* This pass translates pattern-matching constructs, such as instanceof <pattern>. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
77 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
78 |
public class TransPatterns extends TreeTranslator { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
79 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
80 |
protected static final Context.Key<TransPatterns> transPatternsKey = new Context.Key<>(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
81 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
82 |
public static TransPatterns instance(Context context) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
83 |
TransPatterns instance = context.get(transPatternsKey); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
84 |
if (instance == null) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
85 |
instance = new TransPatterns(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
86 |
return instance; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
87 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
88 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
89 |
private final Symtab syms; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
90 |
private final Types types; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
91 |
private final Operators operators; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
92 |
private final Log log; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
93 |
private final ConstFold constFold; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
94 |
private final Names names; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
95 |
private final Target target; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
96 |
private final MatchBindingsComputer matchBindingsComputer; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
97 |
private TreeMaker make; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
98 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
99 |
BindingContext bindingContext = new BindingContext() { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
100 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
101 |
VarSymbol getBindingFor(BindingSymbol varSymbol) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
102 |
return null; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
103 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
104 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
105 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
106 |
JCStatement decorateStatement(JCStatement stat) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
107 |
return stat; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
108 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
109 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
110 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
111 |
JCExpression decorateExpression(JCExpression expr) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
112 |
return expr; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
113 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
114 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
115 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
116 |
BindingContext pop() { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
117 |
//do nothing |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
118 |
return this; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
119 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
120 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
121 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
122 |
boolean tryPrepend(BindingSymbol binding, JCVariableDecl var) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
123 |
return false; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
124 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
125 |
}; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
126 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
127 |
JCLabeledStatement pendingMatchLabel = null; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
128 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
129 |
boolean debugTransPatterns; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
130 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
131 |
private MethodSymbol currentMethodSym = null; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
132 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
133 |
protected TransPatterns(Context context) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
134 |
context.put(transPatternsKey, this); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
135 |
syms = Symtab.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
136 |
make = TreeMaker.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
137 |
types = Types.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
138 |
operators = Operators.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
139 |
log = Log.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
140 |
constFold = ConstFold.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
141 |
names = Names.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
142 |
target = Target.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
143 |
matchBindingsComputer = MatchBindingsComputer.instance(context); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
144 |
debugTransPatterns = Options.instance(context).isSet("debug.patterns"); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
145 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
146 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
147 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
148 |
public void visitTypeTest(JCInstanceOf tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
149 |
if (tree.pattern.hasTag(Tag.BINDINGPATTERN)) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
150 |
//E instanceof T N |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
151 |
//=> |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
152 |
//(let T' N$temp = E; N$temp instanceof T && (N = (T) N$temp == (T) N$temp)) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
153 |
JCBindingPattern patt = (JCBindingPattern)tree.pattern; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
154 |
VarSymbol pattSym = patt.symbol; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
155 |
Type tempType = tree.expr.type.hasTag(BOT) ? |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
156 |
syms.objectType |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
157 |
: tree.expr.type; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
158 |
VarSymbol temp = new VarSymbol(pattSym.flags() | Flags.SYNTHETIC, |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
159 |
names.fromString(pattSym.name.toString() + target.syntheticNameChar() + "temp"), |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
160 |
tempType, |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
161 |
patt.symbol.owner); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
162 |
JCExpression translatedExpr = translate(tree.expr); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
163 |
Type castTargetType = types.boxedTypeOrType(pattSym.erasure(types)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
164 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
165 |
result = makeTypeTest(make.Ident(temp), make.Type(castTargetType)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
166 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
167 |
VarSymbol bindingVar = bindingContext.getBindingFor(patt.symbol); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
168 |
if (bindingVar != null) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
169 |
JCAssign fakeInit = (JCAssign)make.at(tree.pos).Assign( |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
170 |
make.Ident(bindingVar), convert(make.Ident(temp), castTargetType)).setType(bindingVar.erasure(types)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
171 |
result = makeBinary(Tag.AND, (JCExpression)result, |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
172 |
makeBinary(Tag.EQ, fakeInit, convert(make.Ident(temp), castTargetType))); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
173 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
174 |
result = make.at(tree.pos).LetExpr(make.VarDef(temp, translatedExpr), (JCExpression)result).setType(syms.booleanType); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
175 |
((LetExpr) result).needsCond = true; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
176 |
} else { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
177 |
super.visitTypeTest(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
178 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
179 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
180 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
181 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
182 |
public void visitBinary(JCBinary tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
183 |
List<BindingSymbol> matchBindings; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
184 |
switch (tree.getTag()) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
185 |
case AND: |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
186 |
matchBindings = matchBindingsComputer.getMatchBindings(tree.lhs, true); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
187 |
break; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
188 |
case OR: |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
189 |
matchBindings = matchBindingsComputer.getMatchBindings(tree.lhs, false); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
190 |
break; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
191 |
default: |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
192 |
matchBindings = List.nil(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
193 |
break; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
194 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
195 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
196 |
bindingContext = new BasicBindingContext(matchBindings); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
197 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
198 |
super.visitBinary(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
199 |
result = bindingContext.decorateExpression(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
200 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
201 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
202 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
203 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
204 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
205 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
206 |
public void visitConditional(JCConditional tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
207 |
bindingContext = new BasicBindingContext( |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
208 |
matchBindingsComputer.getMatchBindings(tree.cond, true) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
209 |
.appendList(matchBindingsComputer.getMatchBindings(tree.cond, false))); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
210 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
211 |
super.visitConditional(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
212 |
result = bindingContext.decorateExpression(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
213 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
214 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
215 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
216 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
217 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
218 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
219 |
public void visitIf(JCIf tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
220 |
bindingContext = new BasicBindingContext(getMatchBindings(tree.cond)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
221 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
222 |
super.visitIf(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
223 |
result = bindingContext.decorateStatement(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
224 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
225 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
226 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
227 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
228 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
229 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
230 |
public void visitForLoop(JCForLoop tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
231 |
bindingContext = new BasicBindingContext(getMatchBindings(tree.cond)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
232 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
233 |
super.visitForLoop(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
234 |
result = bindingContext.decorateStatement(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
235 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
236 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
237 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
238 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
239 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
240 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
241 |
public void visitWhileLoop(JCWhileLoop tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
242 |
bindingContext = new BasicBindingContext(getMatchBindings(tree.cond)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
243 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
244 |
super.visitWhileLoop(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
245 |
result = bindingContext.decorateStatement(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
246 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
247 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
248 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
249 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
250 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
251 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
252 |
public void visitDoLoop(JCDoWhileLoop tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
253 |
bindingContext = new BasicBindingContext(getMatchBindings(tree.cond)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
254 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
255 |
super.visitDoLoop(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
256 |
result = bindingContext.decorateStatement(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
257 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
258 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
259 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
260 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
261 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
262 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
263 |
public void visitMethodDef(JCMethodDecl tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
264 |
MethodSymbol prevMethodSym = currentMethodSym; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
265 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
266 |
currentMethodSym = tree.sym; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
267 |
super.visitMethodDef(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
268 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
269 |
currentMethodSym = prevMethodSym; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
270 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
271 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
272 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
273 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
274 |
public void visitIdent(JCIdent tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
275 |
VarSymbol bindingVar = null; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
276 |
if ((tree.sym.flags() & Flags.MATCH_BINDING) != 0) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
277 |
bindingVar = bindingContext.getBindingFor((BindingSymbol)tree.sym); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
278 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
279 |
if (bindingVar == null) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
280 |
super.visitIdent(tree); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
281 |
} else { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
282 |
result = make.at(tree.pos).Ident(bindingVar); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
283 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
284 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
285 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
286 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
287 |
public void visitBlock(JCBlock tree) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
288 |
ListBuffer<JCStatement> statements = new ListBuffer<>(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
289 |
bindingContext = new BasicBindingContext(List.nil()) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
290 |
boolean tryPrepend(BindingSymbol binding, JCVariableDecl var) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
291 |
//{ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
292 |
// if (E instanceof T N) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
293 |
// return ; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
294 |
// } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
295 |
// //use of N: |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
296 |
//} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
297 |
//=> |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
298 |
//{ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
299 |
// T N; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
300 |
// if ((let T' N$temp = E; N$temp instanceof T && (N = (T) N$temp == (T) N$temp))) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
301 |
// return ; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
302 |
// } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
303 |
// //use of N: |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
304 |
//} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
305 |
hoistedVarMap.put(binding, var.sym); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
306 |
statements.append(var); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
307 |
return true; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
308 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
309 |
}; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
310 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
311 |
for (List<JCStatement> l = tree.stats; l.nonEmpty(); l = l.tail) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
312 |
statements.append(translate(l.head)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
313 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
314 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
315 |
tree.stats = statements.toList(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
316 |
result = tree; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
317 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
318 |
bindingContext.pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
319 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
320 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
321 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
322 |
public JCTree translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
323 |
try { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
324 |
this.make = make; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
325 |
translate(cdef); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
326 |
} finally { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
327 |
// note that recursive invocations of this method fail hard |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
328 |
this.make = null; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
329 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
330 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
331 |
return cdef; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
332 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
333 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
334 |
/** Make an instanceof expression. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
335 |
* @param lhs The expression. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
336 |
* @param type The type to be tested. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
337 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
338 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
339 |
JCInstanceOf makeTypeTest(JCExpression lhs, JCExpression type) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
340 |
JCInstanceOf tree = make.TypeTest(lhs, type); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
341 |
tree.type = syms.booleanType; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
342 |
return tree; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
343 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
344 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
345 |
/** Make an attributed binary expression (copied from Lower). |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
346 |
* @param optag The operators tree tag. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
347 |
* @param lhs The operator's left argument. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
348 |
* @param rhs The operator's right argument. |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
349 |
*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
350 |
JCBinary makeBinary(JCTree.Tag optag, JCExpression lhs, JCExpression rhs) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
351 |
JCBinary tree = make.Binary(optag, lhs, rhs); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
352 |
tree.operator = operators.resolveBinary(tree, optag, lhs.type, rhs.type); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
353 |
tree.type = tree.operator.type.getReturnType(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
354 |
return tree; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
355 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
356 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
357 |
JCExpression convert(JCExpression expr, Type target) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
358 |
JCExpression result = make.at(expr.pos()).TypeCast(make.Type(target), expr); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
359 |
result.type = target; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
360 |
return result; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
361 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
362 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
363 |
private List<BindingSymbol> getMatchBindings(JCExpression cond) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
364 |
return matchBindingsComputer.getMatchBindings(cond, true) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
365 |
.appendList(matchBindingsComputer.getMatchBindings(cond, false)); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
366 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
367 |
abstract class BindingContext { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
368 |
abstract VarSymbol getBindingFor(BindingSymbol varSymbol); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
369 |
abstract JCStatement decorateStatement(JCStatement stat); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
370 |
abstract JCExpression decorateExpression(JCExpression expr); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
371 |
abstract BindingContext pop(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
372 |
abstract boolean tryPrepend(BindingSymbol binding, JCVariableDecl var); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
373 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
374 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
375 |
class BasicBindingContext extends BindingContext { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
376 |
List<BindingSymbol> matchBindings; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
377 |
Map<BindingSymbol, VarSymbol> hoistedVarMap; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
378 |
BindingContext parent; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
379 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
380 |
public BasicBindingContext(List<BindingSymbol> matchBindings) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
381 |
this.matchBindings = matchBindings; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
382 |
this.parent = bindingContext; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
383 |
this.hoistedVarMap = matchBindings.stream() |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
384 |
.filter(v -> parent.getBindingFor(v) == null) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
385 |
.collect(Collectors.toMap(v -> v, v -> { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
386 |
VarSymbol res = new VarSymbol(v.flags(), v.name, v.type, v.owner); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
387 |
res.setTypeAttributes(v.getRawTypeAttributes()); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
388 |
return res; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
389 |
})); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
390 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
391 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
392 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
393 |
VarSymbol getBindingFor(BindingSymbol varSymbol) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
394 |
VarSymbol res = parent.getBindingFor(varSymbol); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
395 |
if (res != null) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
396 |
return res; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
397 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
398 |
return hoistedVarMap.entrySet().stream() |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
399 |
.filter(e -> e.getKey().isAliasFor(varSymbol)) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
400 |
.findFirst() |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
401 |
.map(e -> e.getValue()).orElse(null); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
402 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
403 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
404 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
405 |
JCStatement decorateStatement(JCStatement stat) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
406 |
if (hoistedVarMap.isEmpty()) return stat; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
407 |
//if (E instanceof T N) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
408 |
// //use N |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
409 |
//} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
410 |
//=> |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
411 |
//{ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
412 |
// T N; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
413 |
// if ((let T' N$temp = E; N$temp instanceof T && (N = (T) N$temp == (T) N$temp))) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
414 |
// //use N |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
415 |
// } |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
416 |
//} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
417 |
ListBuffer<JCStatement> stats = new ListBuffer<>(); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
418 |
for (Entry<BindingSymbol, VarSymbol> e : hoistedVarMap.entrySet()) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
419 |
JCVariableDecl decl = makeHoistedVarDecl(stat.pos, e.getValue()); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
420 |
if (!e.getKey().isPreserved() || |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
421 |
!parent.tryPrepend(e.getKey(), decl)) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
422 |
stats.add(decl); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
423 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
424 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
425 |
if (stats.nonEmpty()) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
426 |
stats.add(stat); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
427 |
stat = make.at(stat.pos).Block(0, stats.toList()); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
428 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
429 |
return stat; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
430 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
431 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
432 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
433 |
JCExpression decorateExpression(JCExpression expr) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
434 |
//E instanceof T N && /*use of N*/ |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
435 |
//=> |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
436 |
//(let T N; (let T' N$temp = E; N$temp instanceof T && (N = (T) N$temp == (T) N$temp)) && /*use of N*/) |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
437 |
for (VarSymbol vsym : hoistedVarMap.values()) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
438 |
expr = make.at(expr.pos).LetExpr(makeHoistedVarDecl(expr.pos, vsym), expr).setType(expr.type); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
439 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
440 |
return expr; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
441 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
442 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
443 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
444 |
BindingContext pop() { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
445 |
return bindingContext = parent; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
446 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
447 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
448 |
@Override |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
449 |
boolean tryPrepend(BindingSymbol binding, JCVariableDecl var) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
450 |
return false; |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
451 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
452 |
|
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
453 |
private JCVariableDecl makeHoistedVarDecl(int pos, VarSymbol varSymbol) { |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
454 |
return make.at(pos).VarDef(varSymbol, null); |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
455 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
456 |
} |
7799a51dbe30
8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff
changeset
|
457 |
} |