1 package jdk.internal.nicl.types; 2 3 import jdk.internal.nicl.Platform; 4 5 public class Scalar implements Type { 6 final char type; 7 final Endianness endianness; 8 final long size; 9 10 private final static String noEndianness = "BVcxv"; 11 12 public Scalar(char type) { 13 this(type, Endianness.NATIVE); 14 } 15 16 public Scalar(char type, Endianness endianness) { 17 this.type = type; 18 this.endianness = (noEndianness.indexOf(type) == -1) ? 19 Endianness.NATIVE : endianness; 20 this.size = Platform.getInstance().getABI().definedSize(type); 21 } 22 23 public Scalar(char type, Endianness endianness, int bits) { 24 this.type = type; 25 this.size = ((bits & 7) != 0) ? (bits >> 3) + 1 : bits >> 3; 26 this.endianness = (noEndianness.indexOf(type) != -1) ? 27 Endianness.NATIVE : endianness; 28 } 29 30 public Endianness getEndianness() { 31 return endianness; 32 } 33 34 public char typeCode() { 35 return type; 36 } 37 38 public boolean isSigned() { 39 return Character.isLowerCase(type); 40 } 41 42 @Override 43 public long getSize() { 44 return size; 45 } 46 47 @Override 48 public int hashCode() { 49 return (type & 0xFF) | ((int) size << 8) | (endianness.ordinal() << 16); 50 } 51 52 @Override 53 public boolean equals(Object o) { 54 if (!(o instanceof jdk.internal.nicl.types.Scalar)) { 55 return false; 56 } 57 jdk.internal.nicl.types.Scalar other = (jdk.internal.nicl.types.Scalar) o; 58 if (type != other.type) { 59 return false; 60 } 61 if (endianness != other.endianness) { 62 return false; 63 } 64 if (size != other.size) { 65 return false; 66 } 67 return true; 68 } 69 70 @Override 71 public String toString() { 72 StringBuffer sb = new StringBuffer(); 73 if (Endianness.NATIVE != endianness) { 74 sb.append(endianness.modifier); 75 } 76 if (type == 'i' || type == 'f' || type == 'v' || type == 'I' || type == 'F') { 77 sb.append('='); 78 sb.append(size << 3); 79 } 80 sb.append(type); 81 return sb.toString(); 82 } 83 } --- EOF ---