@Override public void visit(UnaryExpr expr) { expr.getOperand().acceptVisitor(this); }
@Override public void visit(UnaryExpr expr) { try { output.writeByte(1); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
writer.print("("); writer.print("!"); expr.getOperand().acceptVisitor(this); writer.print(")"); break; writer.print("("); writer.print("-"); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case LENGTH: writer.print("ARRAY_LENGTH("); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case NULL_CHECK: expr.getOperand().acceptVisitor(this); break; case INT_TO_BYTE: writer.print("TO_BYTE("); expr.getOperand().acceptVisitor(this); writer.print(")"); break; case INT_TO_SHORT: writer.print("TO_SHORT("); expr.getOperand().acceptVisitor(this); writer.print(")"); break;
@Override public void visit(UnaryExpr expr) { pushLocation(expr.getLocation()); try { expr.getOperand().acceptVisitor(this); Expr operand = resultExpr; if (expr.getOperation() == UnaryOperation.NEGATE && operand instanceof ConstantExpr) { ConstantExpr constantExpr = (ConstantExpr) operand; if (tryMakePositive(constantExpr)) { resultExpr = expr; return; } } expr.setOperand(operand); resultExpr = expr; } finally { popLocation(); } }
private boolean isSideEffectFree(Expr expr) { if (expr == null) { return true; } if (expr instanceof VariableExpr || expr instanceof ConstantExpr) { return true; } if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; return isSideEffectFree(binary.getFirstOperand()) && isSideEffectFree(binary.getSecondOperand()); } if (expr instanceof UnaryExpr) { return isSideEffectFree(((UnaryExpr) expr).getOperand()); } if (expr instanceof InstanceOfExpr) { return isSideEffectFree(((InstanceOfExpr) expr).getExpr()); } if (expr instanceof PrimitiveCastExpr) { return isSideEffectFree(((PrimitiveCastExpr) expr).getValue()); } if (expr instanceof NewExpr) { return true; } return false; }
switch (expr.getOperation()) { case INT_TO_BYTE: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(24)); break; case INT_TO_SHORT: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); break; case INT_TO_CHAR: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); break; case LENGTH: accept(expr.getOperand()); result = generateArrayLength(result); break; case NOT: accept(expr.getOperand()); result = negate(result); break; case NEGATE: accept(expr.getOperand());
writer.append("Long_not("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else { expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append(')'); writer.append("Long_neg("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else { expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append(')'); case LENGTH: precedence = Precedence.MEMBER_ACCESS; expr.getOperand().acceptVisitor(this); writer.append(".length"); break; expr.getOperand().acceptVisitor(this); writer.ws().append("<<").ws().append("24").ws().append(">>").ws().append("24"); if (outerPrecedence.ordinal() > Precedence.BITWISE_SHIFT.ordinal()) {
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b, expr.getLocation()); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }
@Override public void visit(UnaryExpr expr) { expr.getOperand().acceptVisitor(this); }
@Override public void visit(UnaryExpr expr) { try { output.writeByte(1); output.writeByte(expr.getOperation().ordinal()); output.writeByte(expr.getType() != null ? expr.getType().ordinal() + 1 : 0); writeExpr(expr.getOperand()); } catch (IOException e) { throw new IOExceptionWrapper(e); } }
@Override public void visit(UnaryExpr expr) { pushLocation(expr.getLocation()); try { expr.getOperand().acceptVisitor(this); Expr operand = resultExpr; if (expr.getOperation() == UnaryOperation.NEGATE && operand instanceof ConstantExpr) { ConstantExpr constantExpr = (ConstantExpr) operand; if (tryMakePositive(constantExpr)) { resultExpr = expr; return; } } expr.setOperand(operand); resultExpr = expr; } finally { popLocation(); } }
switch (expr.getOperation()) { case INT_TO_BYTE: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(24)); break; case INT_TO_SHORT: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); break; case INT_TO_CHAR: accept(expr.getOperand()); result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.SHL, result, new WasmInt32Constant(16)); break; case LENGTH: accept(expr.getOperand()); result = generateArrayLength(result); break; case NOT: accept(expr.getOperand()); result = negate(result); break; case NEGATE: accept(expr.getOperand());
writer.append("Long_not("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else { expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append(')'); writer.append("Long_neg("); precedence = Precedence.min(); expr.getOperand().acceptVisitor(this); writer.append(')'); } else { expr.getOperand().acceptVisitor(this); if (outerPrecedence.ordinal() > Precedence.UNARY.ordinal()) { writer.append(')'); case LENGTH: precedence = Precedence.MEMBER_ACCESS; expr.getOperand().acceptVisitor(this); writer.append(".length"); break; expr.getOperand().acceptVisitor(this); writer.ws().append("<<").ws().append("24").ws().append(">>").ws().append("24"); if (outerPrecedence.ordinal() > Precedence.BITWISE_SHIFT.ordinal()) {
public static Expr invert(Expr expr) { if (expr instanceof UnaryExpr) { UnaryExpr unary = (UnaryExpr) expr; if (unary.getOperation() == UnaryOperation.NOT) { return unary.getOperand(); } } else if (expr instanceof BinaryExpr) { BinaryExpr binary = (BinaryExpr) expr; Expr a = binary.getFirstOperand(); Expr b = binary.getSecondOperand(); switch (binary.getOperation()) { case EQUALS: return Expr.binary(BinaryOperation.NOT_EQUALS, binary.getType(), a, b, expr.getLocation()); case NOT_EQUALS: return Expr.binary(BinaryOperation.EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS: return Expr.binary(BinaryOperation.GREATER_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case LESS_OR_EQUALS: return Expr.binary(BinaryOperation.GREATER, binary.getType(), a, b); case GREATER: return Expr.binary(BinaryOperation.LESS_OR_EQUALS, binary.getType(), a, b, expr.getLocation()); case GREATER_OR_EQUALS: return Expr.binary(BinaryOperation.LESS, binary.getType(), a, b, expr.getLocation()); default: break; } } return Expr.invert(expr); } }