Give comment-generating functions more precise naming

This commit is contained in:
Jeff Smith 2014-02-17 00:08:50 -06:00 committed by Connor Tumbleson
parent a4d5d2299b
commit f5765d37c8
4 changed files with 19 additions and 17 deletions

View File

@ -66,10 +66,11 @@ public class ArrayDataMethodItem extends InstructionMethodItem<ArrayPayload> {
LongRenderer.writeSignedIntOrLongTo(writer, number.longValue());
writer.write(suffix);
if (elementWidth == 8) {
writeDouble(writer, number.longValue());
writeCommentIfLikelyDouble(writer, number.longValue());
} else if (elementWidth == 4) {
writeResourceId(writer, number.intValue());
writeFloat(writer, number.intValue());
int value = number.intValue();
boolean isResourceId = writeCommentIfResourceId(writer, value);
if (!isResourceId) writeCommentIfLikelyFloat(writer, value);
}
writer.write("\n");
}

View File

@ -232,10 +232,10 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
writer.write(", ");
writeLiteral(writer);
if (instruction.getOpcode().setsWideRegister()) {
writeDouble(writer);
writeCommentIfLikelyDouble(writer);
} else {
writeResourceId(writer);
writeFloat(writer);
boolean isResourceId = writeCommentIfResourceId(writer);
if (!isResourceId) writeCommentIfLikelyFloat(writer);
}
return true;
case Format21t:
@ -441,11 +441,11 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
LongRenderer.writeSignedIntOrLongTo(writer, ((WideLiteralInstruction)instruction).getWideLiteral());
}
protected void writeFloat(IndentingWriter writer) throws IOException {
writeFloat(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
protected void writeCommentIfLikelyFloat(IndentingWriter writer) throws IOException {
writeCommentIfLikelyFloat(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
}
protected void writeFloat(IndentingWriter writer, int val) throws IOException {
protected void writeCommentIfLikelyFloat(IndentingWriter writer, int val) throws IOException {
if (NumberUtils.isLikelyFloat(val)) {
writer.write(" # ");
float fval = Float.intBitsToFloat(val);
@ -468,11 +468,11 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
}
}
protected void writeDouble(IndentingWriter writer) throws IOException {
writeDouble(writer, ((WideLiteralInstruction)instruction).getWideLiteral());
protected void writeCommentIfLikelyDouble(IndentingWriter writer) throws IOException {
writeCommentIfLikelyDouble(writer, ((WideLiteralInstruction)instruction).getWideLiteral());
}
protected void writeDouble(IndentingWriter writer, long val) throws IOException {
protected void writeCommentIfLikelyDouble(IndentingWriter writer, long val) throws IOException {
if (NumberUtils.isLikelyDouble(val)) {
writer.write(" # ");
double dval = Double.longBitsToDouble(val);
@ -493,17 +493,18 @@ public class InstructionMethodItem<T extends Instruction> extends MethodItem {
}
}
protected void writeResourceId(IndentingWriter writer) throws IOException {
writeResourceId(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
protected boolean writeCommentIfResourceId(IndentingWriter writer) throws IOException {
return writeCommentIfResourceId(writer, ((NarrowLiteralInstruction)instruction).getNarrowLiteral());
}
protected void writeResourceId(IndentingWriter writer, int val) throws IOException {
protected boolean writeCommentIfResourceId(IndentingWriter writer, int val) throws IOException {
Map<Integer,String> resourceIds = methodDef.classDef.options.resourceIds;
String resource = resourceIds.get(Integer.valueOf(val));
if (resource != null) {
writer.write(" # ");
writer.write(resource);
}
return (resource != null);
}
protected void writeFieldOffset(IndentingWriter writer) throws IOException {

View File

@ -85,7 +85,7 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
int key = firstKey;
for (PackedSwitchTarget target: targets) {
target.writeTargetTo(writer);
writeResourceId(writer, key);
writeCommentIfResourceId(writer, key);
writer.write('\n');
key++;
}

View File

@ -71,7 +71,7 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
IntegerRenderer.writeTo(writer, target.getKey());
writer.write(" -> ");
target.writeTargetTo(writer);
writeResourceId(writer, target.getKey());
writeCommentIfResourceId(writer, target.getKey());
writer.write('\n');
}
writer.deindent(4);