Thu, 20 Dec 2012 16:24:18 -0800
8004982: JDK8 source with GPL header errors
Reviewed-by: ohair
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package org.openjdk.tests.shapegen; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.HashSet; |
aoqi@0 | 29 | import java.util.Set; |
aoqi@0 | 30 | |
aoqi@0 | 31 | import static org.openjdk.tests.shapegen.ClassCase.Kind.*; |
aoqi@0 | 32 | |
aoqi@0 | 33 | /** |
aoqi@0 | 34 | * |
aoqi@0 | 35 | * @author Robert Field |
aoqi@0 | 36 | */ |
aoqi@0 | 37 | public class RuleGroup { |
aoqi@0 | 38 | |
aoqi@0 | 39 | final String name; |
aoqi@0 | 40 | private final Rule[] rules; |
aoqi@0 | 41 | |
aoqi@0 | 42 | public RuleGroup(String name, Rule[] rules) { |
aoqi@0 | 43 | this.name = name; |
aoqi@0 | 44 | this.rules = rules; |
aoqi@0 | 45 | } |
aoqi@0 | 46 | |
aoqi@0 | 47 | public boolean exec(ClassCase cc) { |
aoqi@0 | 48 | boolean found = false; |
aoqi@0 | 49 | for (Rule rule : rules) { |
aoqi@0 | 50 | if (rule.guard(cc)) { |
aoqi@0 | 51 | if (found) { |
aoqi@0 | 52 | throw new RuntimeException("Bad rules -- multiple matches " + toString() + " for " + cc); |
aoqi@0 | 53 | } else { |
aoqi@0 | 54 | rule.eval(cc); |
aoqi@0 | 55 | found = true; |
aoqi@0 | 56 | } |
aoqi@0 | 57 | } |
aoqi@0 | 58 | } |
aoqi@0 | 59 | return found; |
aoqi@0 | 60 | } |
aoqi@0 | 61 | |
aoqi@0 | 62 | @Override |
aoqi@0 | 63 | public String toString() { |
aoqi@0 | 64 | return name; |
aoqi@0 | 65 | } |
aoqi@0 | 66 | |
aoqi@0 | 67 | public static RuleGroup PROVENENCE = new RuleGroup("Provenence", new Rule[] { |
aoqi@0 | 68 | new Rule("P-CDeclare") { |
aoqi@0 | 69 | boolean guard(ClassCase cc) { |
aoqi@0 | 70 | return cc.isa(CCONCRETE, CABSTRACT); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | void eval(ClassCase cc) { |
aoqi@0 | 74 | cc.set_mprov(cc); |
aoqi@0 | 75 | cc.set_HasClassMethod(true); |
aoqi@0 | 76 | } |
aoqi@0 | 77 | }, |
aoqi@0 | 78 | |
aoqi@0 | 79 | new Rule("P-IDeclare") { |
aoqi@0 | 80 | boolean guard(ClassCase cc) { |
aoqi@0 | 81 | return cc.isa(IDEFAULT, IPRESENT); |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | void eval(ClassCase cc) { |
aoqi@0 | 85 | cc.set_mprov(cc); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | }, |
aoqi@0 | 88 | |
aoqi@0 | 89 | new Rule("P-IntfInh") { |
aoqi@0 | 90 | boolean guard(ClassCase cc) { |
aoqi@0 | 91 | return cc.isa(IVAC, CNONE) && !(cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); |
aoqi@0 | 92 | } |
aoqi@0 | 93 | |
aoqi@0 | 94 | void eval(ClassCase cc) { |
aoqi@0 | 95 | Set<ClassCase> _S = new HashSet<>(); |
aoqi@0 | 96 | for (ClassCase t : cc.getSupertypes()) { |
aoqi@0 | 97 | _S.addAll(t.get_mprov()); |
aoqi@0 | 98 | } |
aoqi@0 | 99 | Set<ClassCase> tops = new HashSet<>(); |
aoqi@0 | 100 | for (ClassCase _W : _S) { |
aoqi@0 | 101 | for (ClassCase _V : _S) { |
aoqi@0 | 102 | if (_V.equals(_W) || !(_V.isSubtypeOf(_W))) { |
aoqi@0 | 103 | tops.add(_W); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | } |
aoqi@0 | 106 | } |
aoqi@0 | 107 | cc.set_mprov(tops); |
aoqi@0 | 108 | } |
aoqi@0 | 109 | }, |
aoqi@0 | 110 | |
aoqi@0 | 111 | new Rule("P-ClassInh") { |
aoqi@0 | 112 | boolean guard(ClassCase cc) { |
aoqi@0 | 113 | return cc.isa(CNONE) && (cc.hasSuperclass() && cc.getSuperclass().get_HasClassMethod()); |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | void eval(ClassCase cc) { |
aoqi@0 | 117 | cc.set_mprov(cc.getSuperclass()); |
aoqi@0 | 118 | cc.set_HasClassMethod(true); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | }, |
aoqi@0 | 121 | |
aoqi@0 | 122 | }); |
aoqi@0 | 123 | |
aoqi@0 | 124 | public static RuleGroup MARKER = new RuleGroup("Marker", new Rule[] { |
aoqi@0 | 125 | new Rule("M-Default") { |
aoqi@0 | 126 | boolean guard(ClassCase cc) { |
aoqi@0 | 127 | return cc.isa(IDEFAULT); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | void eval(ClassCase cc) { |
aoqi@0 | 131 | cc.set_HasDefault(true); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | }, |
aoqi@0 | 134 | |
aoqi@0 | 135 | new Rule("M-Conc") { |
aoqi@0 | 136 | boolean guard(ClassCase cc) { |
aoqi@0 | 137 | return cc.isa(CCONCRETE); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | void eval(ClassCase cc) { |
aoqi@0 | 141 | cc.set_IsConcrete(true); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | }, |
aoqi@0 | 144 | |
aoqi@0 | 145 | }); |
aoqi@0 | 146 | |
aoqi@0 | 147 | public static RuleGroup RESOLUTION = new RuleGroup("Resolution", new Rule[] { |
aoqi@0 | 148 | new Rule("R-Resolve") { |
aoqi@0 | 149 | boolean guard(ClassCase cc) { |
aoqi@0 | 150 | if (!(cc.isClass() && cc.get_mprov().size() == 1)) { |
aoqi@0 | 151 | return false; |
aoqi@0 | 152 | } |
aoqi@0 | 153 | ClassCase _V = cc.get_mprov().iterator().next(); |
aoqi@0 | 154 | return _V.get_IsConcrete() || _V.get_HasDefault(); |
aoqi@0 | 155 | } |
aoqi@0 | 156 | |
aoqi@0 | 157 | void eval(ClassCase cc) { |
aoqi@0 | 158 | ClassCase _V = cc.get_mprov().iterator().next(); |
aoqi@0 | 159 | cc.set_mres(_V); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | }, |
aoqi@0 | 162 | |
aoqi@0 | 163 | }); |
aoqi@0 | 164 | |
aoqi@0 | 165 | public static RuleGroup DEFENDER = new RuleGroup("Defender", new Rule[] { |
aoqi@0 | 166 | new Rule("D-Defend") { |
aoqi@0 | 167 | boolean guard(ClassCase cc) { |
aoqi@0 | 168 | ClassCase mresSuper = cc.hasSuperclass() ? cc.getSuperclass().get_mres() : null; |
aoqi@0 | 169 | boolean eq = cc.get_mres() == null ? mresSuper == null : cc.get_mres().equals(mresSuper); |
aoqi@0 | 170 | return cc.isa(CNONE) && !eq; |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | void eval(ClassCase cc) { |
aoqi@0 | 174 | cc.set_mdefend(cc.get_mres()); |
aoqi@0 | 175 | } |
aoqi@0 | 176 | }, |
aoqi@0 | 177 | |
aoqi@0 | 178 | }); |
aoqi@0 | 179 | |
aoqi@0 | 180 | public static RuleGroup CHECKING = new RuleGroup("Checking", new Rule[] { |
aoqi@0 | 181 | new Rule("C-Check") { |
aoqi@0 | 182 | boolean guard(ClassCase cc) { |
aoqi@0 | 183 | for (ClassCase t : cc.getSupertypes()) { |
aoqi@0 | 184 | if (! t.get_OK()) { |
aoqi@0 | 185 | return false; |
aoqi@0 | 186 | } |
aoqi@0 | 187 | } |
aoqi@0 | 188 | int defenderCount = 0; |
aoqi@0 | 189 | int provCount = 0; |
aoqi@0 | 190 | for (ClassCase prov : cc.get_mprov()) { |
aoqi@0 | 191 | if (prov.get_HasDefault()) { |
aoqi@0 | 192 | defenderCount++; |
aoqi@0 | 193 | } |
aoqi@0 | 194 | provCount++; |
aoqi@0 | 195 | } |
aoqi@0 | 196 | return provCount <= 1 || defenderCount == 0; |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | void eval(ClassCase cc) { |
aoqi@0 | 200 | cc.set_OK(true); |
aoqi@0 | 201 | } |
aoqi@0 | 202 | }, |
aoqi@0 | 203 | |
aoqi@0 | 204 | }); |
aoqi@0 | 205 | |
aoqi@0 | 206 | } |