1 /*
   2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.nodes.test;
  24 
  25 import org.junit.Assert;
  26 
  27 import org.graalvm.compiler.core.common.type.Stamp;
  28 import org.graalvm.compiler.core.common.type.TypeReference;
  29 import org.graalvm.compiler.core.test.GraalCompilerTest;
  30 
  31 public abstract class AbstractObjectStampTest extends GraalCompilerTest {
  32 
  33     protected static class A {
  34 
  35     }
  36 
  37     protected static class B extends A {
  38 
  39     }
  40 
  41     protected static class C extends B implements I {
  42 
  43     }
  44 
  45     protected static class D extends A {
  46 
  47     }
  48 
  49     protected abstract static class E extends A {
  50 
  51     }
  52 
  53     protected interface I {
  54 
  55     }
  56 
  57     protected interface OtherI {
  58 
  59     }
  60 
  61     protected interface SubI1 extends I {
  62 
  63     }
  64 
  65     protected interface SubI2 extends I {
  66 
  67     }
  68 
  69     protected interface SubI3 extends I {
  70 
  71     }
  72 
  73     protected interface SubI4 extends SubI3, SubI1 {
  74     }
  75 
  76     protected interface SubI5 extends SubI3, OtherI {
  77 
  78     }
  79 
  80     protected interface SubI6 extends OtherI {
  81 
  82     }
  83 
  84     protected interface Base1 {
  85 
  86     }
  87 
  88     protected interface Base2 {
  89 
  90     }
  91 
  92     protected interface ImplOrder1 extends Base1, Base2 {
  93 
  94     }
  95 
  96     protected interface ImplOrder2 extends Base2, Base1 {
  97 
  98     }
  99 
 100     /* Example of a deep interface hierarchy. */
 101 
 102     protected interface I45 {
 103 
 104     }
 105 
 106     protected interface I46 {
 107 
 108     }
 109 
 110     protected interface I41 extends I45 {
 111 
 112     }
 113 
 114     protected interface I42 extends I45 {
 115 
 116     }
 117 
 118     protected interface I43 extends I46 {
 119 
 120     }
 121 
 122     protected interface I44 extends I46 {
 123 
 124     }
 125 
 126     protected interface I35 extends I41, I42 {
 127 
 128     }
 129 
 130     protected interface I36 extends I43, I44 {
 131 
 132     }
 133 
 134     protected interface I31 extends I35 {
 135 
 136     }
 137 
 138     protected interface I32 extends I35 {
 139 
 140     }
 141 
 142     protected interface I33 extends I36 {
 143 
 144     }
 145 
 146     protected interface I34 extends I36 {
 147 
 148     }
 149 
 150     protected interface I25 extends I31, I32 {
 151 
 152     }
 153 
 154     protected interface I26 extends I33, I34 {
 155 
 156     }
 157 
 158     protected interface I21 extends I25 {
 159 
 160     }
 161 
 162     protected interface I22 extends I25 {
 163 
 164     }
 165 
 166     protected interface I23 extends I26 {
 167 
 168     }
 169 
 170     protected interface I24 extends I26 {
 171 
 172     }
 173 
 174     protected interface I15 extends I21, I22 {
 175 
 176     }
 177 
 178     protected interface I16 extends I23, I24 {
 179 
 180     }
 181 
 182     protected interface I11 extends I15 {
 183 
 184     }
 185 
 186     protected interface I12 extends I15 {
 187 
 188     }
 189 
 190     protected interface I13 extends I16 {
 191 
 192     }
 193 
 194     protected interface I14 extends I16 {
 195 
 196     }
 197 
 198     protected interface I5 extends I11, I12 {
 199 
 200     }
 201 
 202     protected interface I6 extends I13, I14 {
 203 
 204     }
 205 
 206     protected interface I1 extends I5 {
 207 
 208     }
 209 
 210     protected interface I2 extends I5 {
 211 
 212     }
 213 
 214     protected interface I3 extends I6 {
 215 
 216     }
 217 
 218     protected interface I4 extends I6 {
 219 
 220     }
 221 
 222     protected interface Deep1 extends I1, I2 {
 223 
 224     }
 225 
 226     protected interface Deep2 extends I3, I4 {
 227 
 228     }
 229 
 230     /**
 231      * Joins the two stamps and also asserts that the meet operation is commutative.
 232      */
 233     protected static Stamp join(Stamp a, Stamp b) {
 234         Stamp ab = a.join(b);
 235         Stamp ba = b.join(a);
 236         Assert.assertEquals(ab, ba);
 237         return ab;
 238     }
 239 
 240     /**
 241      * Meets the two stamps and also asserts that the meet operation is commutative.
 242      */
 243     protected static Stamp meet(Stamp a, Stamp b) {
 244         Stamp ab = a.meet(b);
 245         Stamp ba = b.meet(a);
 246         Assert.assertEquals(ab, ba);
 247         return ab;
 248     }
 249 
 250     protected TypeReference getType(Class<?> clazz) {
 251         return TypeReference.createTrustedWithoutAssumptions(getMetaAccess().lookupJavaType(clazz));
 252     }
 253 }