/** * Make a new item. If both name and signature are null, null is returned. * * TODO: intern these * * @param name {@code null-ok;} local variable name * @param signature {@code null-ok;} local variable signature * @return {@code non-null;} appropriate instance. */ public static LocalItem make(CstString name, CstString signature) { if (name == null && signature == null) { return null; } return new LocalItem (name, signature); }
/** {@inheritDoc} */ @Override public int compareTo(LocalItem local) { int ret; ret = compareHandlesNulls(name, local.name); if (ret != 0) { return ret; } ret = compareHandlesNulls(signature, local.signature); return ret; }
/** {@inheritDoc} */ @Override public boolean equals(Object other) { if (!(other instanceof LocalItem)) { return false; } LocalItem local = (LocalItem) other; return 0 == compareTo(local); }
/** * Helper for {@link #getAllConstants} which adds all the info for * a single {@code RegisterSpec}. * * @param result {@code non-null;} result set to add to * @param spec {@code null-ok;} register spec to add */ private static void addConstants(HashSet<Constant> result, RegisterSpec spec) { if (spec == null) { return; } LocalItem local = spec.getLocalItem(); CstString name = local.getName(); CstString signature = local.getSignature(); Type type = spec.getType(); if (type != Type.KNOWN_NULL) { result.add(CstType.intern(type)); } if (name != null) { result.add(name); } if (signature != null) { result.add(signature); } }
/** * Helper for {@link #toString} and {@link #toHuman}. * * @param human whether to be human-oriented * @return {@code non-null;} the string form */ private String toString0(boolean human) { StringBuffer sb = new StringBuffer(40); sb.append(regString()); sb.append(":"); if (local != null) { sb.append(local.toString()); } Type justType = type.getType(); sb.append(justType); if (justType != type) { sb.append("="); if (human && (type instanceof Constant)) { sb.append(((Constant) type).toHuman()); } else { sb.append(type); } } return sb.toString(); }
/** * Returns true if a and b are equal, whether * or not either of them are null. * @param a * @param b * @return true if equal */ private static boolean equalsHandlesNulls(LocalItem a, LocalItem b) { return (a == b) || ((a != null) && a.equals(b)); }
/** * Gets the variable name. * * @return {@code null-ok;} the variable name */ public CstString getName() { return spec.getLocalItem().getName(); }
/** * Gets the variable signature. * * @return {@code null-ok;} the variable signature */ public CstString getSignature() { return spec.getLocalItem().getSignature(); }
/** * Helper for {@link #hashCode} which actually does the calculation. * * @param reg value of the instance variable * @param type value of the instance variable * @param local value of the instance variable * @return the hash code */ private static int hashCodeOf(int reg, TypeBearer type, LocalItem local) { int hash = (local != null) ? local.hashCode() : 0; hash = (hash * 31 + type.hashCode()) * 31 + reg; return hash; }
/** * Gets the variable's LocalItem, a (name, signature) tuple * * @return {@code null-ok;} the variable's type descriptor */ public LocalItem getLocalItem() { return LocalItem.make(name, signature); }
/** * Helper for {@link #getAllConstants} which adds all the info for * a single {@code RegisterSpec}. * * @param result {@code non-null;} result set to add to * @param spec {@code null-ok;} register spec to add */ private static void addConstants(HashSet<Constant> result, RegisterSpec spec) { if (spec == null) { return; } LocalItem local = spec.getLocalItem(); CstString name = local.getName(); CstString signature = local.getSignature(); Type type = spec.getType(); if (type != Type.KNOWN_NULL) { result.add(CstType.intern(type)); } if (name != null) { result.add(name); } if (signature != null) { result.add(signature); } }
/** * Helper for {@link #toString} and {@link #toHuman}. * * @param human whether to be human-oriented * @return {@code non-null;} the string form */ private String toString0(boolean human) { StringBuffer sb = new StringBuffer(40); sb.append(regString()); sb.append(":"); if (local != null) { sb.append(local.toString()); } Type justType = type.getType(); sb.append(justType); if (justType != type) { sb.append("="); if (human && (type instanceof CstString)) { sb.append(((CstString) type).toQuoted()); } else if (human && (type instanceof Constant)) { sb.append(type.toHuman()); } else { sb.append(type); } } return sb.toString(); }
/** * Returns true if a and b are equal, whether * or not either of them are null. * @param a * @param b * @return true if equal */ private static boolean equalsHandlesNulls(LocalItem a, LocalItem b) { return (a == b) || ((a != null) && a.equals(b)); }
/** * Gets the variable name. * * @return {@code null-ok;} the variable name */ public CstString getName() { return spec.getLocalItem().getName(); }
/** * Gets the variable signature. * * @return {@code null-ok;} the variable signature */ public CstString getSignature() { return spec.getLocalItem().getSignature(); }
/** * Helper for {@link #hashCode} and {@link #ForComparison.hashCode}, * which actually does the calculation. * * @param reg value of the instance variable * @param type value of the instance variable * @param local value of the instance variable * @return the hash code */ private static int hashCodeOf(int reg, TypeBearer type, LocalItem local) { int hash = (local != null) ? local.hashCode() : 0; hash = (hash * 31 + type.hashCode()) * 31 + reg; return hash; }
/** * Gets the variable's LocalItem, a (name, signature) tuple * * @return {@code null-ok;} the variable's type descriptor */ public LocalItem getLocalItem() { return LocalItem.make(name, signature); }
/** * Helper for {@link #getAllConstants} which adds all the info for * a single {@code RegisterSpec}. * * @param result {@code non-null;} result set to add to * @param spec {@code null-ok;} register spec to add */ private static void addConstants(HashSet<Constant> result, RegisterSpec spec) { if (spec == null) { return; } LocalItem local = spec.getLocalItem(); CstString name = local.getName(); CstString signature = local.getSignature(); Type type = spec.getType(); if (type != Type.KNOWN_NULL) { result.add(CstType.intern(type)); } if (name != null) { result.add(name); } if (signature != null) { result.add(signature); } }
/** * Helper for {@link #toString} and {@link #toHuman}. * * @param human whether to be human-oriented * @return {@code non-null;} the string form */ private String toString0(boolean human) { StringBuffer sb = new StringBuffer(40); sb.append(regString()); sb.append(":"); if (local != null) { sb.append(local.toString()); } Type justType = type.getType(); sb.append(justType); if (justType != type) { sb.append("="); if (human && (type instanceof CstString)) { sb.append(((CstString) type).toQuoted()); } else if (human && (type instanceof Constant)) { sb.append(type.toHuman()); } else { sb.append(type); } } return sb.toString(); }
/** * Returns true if a and b are equal, whether * or not either of them are null. * @param a * @param b * @return true if equal */ private static boolean equalsHandlesNulls(LocalItem a, LocalItem b) { return (a == b) || ((a != null) && a.equals(b)); }