MCPcopy Create free account
hub / github.com/chibash/stone / translate

Method translate

src/chap14/ToJava.java:120–148  ·  view source on GitHub ↗
(TypeInfo result)

Source from the content-addressed store, hash-verified

118 @Reviser public static class BinaryEx2 extends TypeChecker.BinaryEx {
119 public BinaryEx2(List<ASTree> c) { super(c); }
120 public String translate(TypeInfo result) {
121 String op = operator();
122 if ("=".equals(op))
123 return ((NameEx3)left()).translateAssign(rightType, right());
124 else if (leftType.type() != TypeInfo.INT
125 || rightType.type() != TypeInfo.INT) {
126 String e1 = translateExpr(left(), leftType, TypeInfo.ANY);
127 String e2 = translateExpr(right(), rightType, TypeInfo.ANY);
128 if ("==".equals(op))
129 return "chap14.Runtime.eq(" + e1 + "," + e2 + ")";
130 else if ("+".equals(op)) {
131 if (leftType.type() == TypeInfo.STRING
132 || rightType.type() == TypeInfo.STRING)
133 return e1 + "+" + e2;
134 else
135 return "chap14.Runtime.plus(" + e1 + "," + e2 + ")";
136 }
137 else
138 throw new StoneException("bad operator", this);
139 }
140 else {
141 String expr = ((ASTreeEx)left()).translate(null) + op
142 + ((ASTreeEx)right()).translate(null);
143 if ("<".equals(op) || ">".equals(op) || "==".equals(op))
144 return "(" + expr + "?1:0)";
145 else
146 return "(" + expr + ")";
147 }
148 }
149 }
150 @Reviser public static class BlockEx2 extends TypeChecker.BlockEx {
151 public BlockEx2(List<ASTree> c) { super(c); }

Callers

nothing calls this directly

Calls 7

operatorMethod · 0.80
translateAssignMethod · 0.80
leftMethod · 0.80
rightMethod · 0.80
translateExprMethod · 0.80
typeMethod · 0.45
translateMethod · 0.45

Tested by

no test coverage detected