1 package jdk.internal.nicl.types; 2 3 import java.util.Arrays; 4 import java.util.stream.Stream; 5 import jdk.internal.nicl.Platform; 6 7 public class Container implements Type { 8 final Type[] members; 9 final boolean isUnion; 10 11 public Container(boolean isUnion, Type... members) { 12 this.members = members; 13 this.isUnion = isUnion; 14 } 15 16 @Override 17 public long getSize() { 18 return Platform.getInstance().getABI().sizeof(this); 19 } 20 24 25 public Stream<Type> getMembers() { 26 return Stream.of(members); 27 } 28 29 public int memberCount() { 30 return members.length; 31 } 32 33 public Type getMember(int index) { 34 return members[index]; 35 } 36 37 @Override 38 public int hashCode() { 39 return (isUnion ? 0x40000000 : 0x60000000) | Arrays.hashCode(members); 40 } 41 42 @Override 43 public boolean equals(Object o) { 44 if (!(o instanceof jdk.internal.nicl.types.Container)) { 45 return false; 46 } 47 48 jdk.internal.nicl.types.Container other = (jdk.internal.nicl.types.Container) o; 49 if (other.isUnion != isUnion) { 50 return false; 51 } 52 if (other.members.length != members.length) { 53 return false; 54 } 55 for (int i = 0; i < members.length; i++) { 56 if (!members[i].equals(other.members[i])) { 57 return false; 58 } 59 } 60 return true; 61 } 62 63 @Override 64 public String toString() { 65 StringBuffer sb = new StringBuffer(); 66 sb.append("["); 67 for (Type t : members) { 68 sb.append(t); | 1 /* 2 * Copyright (c) 2016, 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 24 package jdk.internal.nicl.types; 25 26 import java.util.Arrays; 27 import java.util.stream.Stream; 28 import jdk.internal.nicl.Platform; 29 30 public class Container implements Type { 31 final Type[] members; 32 final boolean isUnion; 33 34 public Container(boolean isUnion, Type... members) { 35 this.members = members; 36 this.isUnion = isUnion; 37 } 38 39 @Override 40 public long getSize() { 41 return Platform.getInstance().getABI().sizeof(this); 42 } 43 47 48 public Stream<Type> getMembers() { 49 return Stream.of(members); 50 } 51 52 public int memberCount() { 53 return members.length; 54 } 55 56 public Type getMember(int index) { 57 return members[index]; 58 } 59 60 @Override 61 public int hashCode() { 62 return (isUnion ? 0x40000000 : 0x60000000) | Arrays.hashCode(members); 63 } 64 65 @Override 66 public boolean equals(Object o) { 67 if (!(o instanceof Container)) { 68 return false; 69 } 70 71 Container other = (Container) o; 72 if (other.isUnion != isUnion) { 73 return false; 74 } 75 if (other.members.length != members.length) { 76 return false; 77 } 78 for (int i = 0; i < members.length; i++) { 79 if (!members[i].equals(other.members[i])) { 80 return false; 81 } 82 } 83 return true; 84 } 85 86 @Override 87 public String toString() { 88 StringBuffer sb = new StringBuffer(); 89 sb.append("["); 90 for (Type t : members) { 91 sb.append(t); |