private BinaryExpression getOrExpression(Expression expr) { BinaryExpression binExpr = ObjectUtil.asInstance(expr, BinaryExpression.class); if (binExpr == null) return null; int binExprType = binExpr.getOperation().getType(); if (binExprType == Types.BITWISE_OR || binExprType == Types.LOGICAL_OR) return binExpr; return null; }
public void visitBinaryExpression(BinaryExpression expression) { Expression left = expression.getLeftExpression(); Expression right = expression.getRightExpression(); boolean leaf = (right instanceof ConstantExpression || left instanceof ConstantExpression); if (!leaf) buffer.append("("); left.visit(this); buffer.append(" "); Token token = expression.getOperation(); buffer.append(tokenAsSql(token)); buffer.append(" "); right.visit(this); if (!leaf) buffer.append(")"); }
/** * Returns true for expressions of the form x[...] * * @param expression an expression * @return true for array access expressions */ protected static boolean isArrayAccessExpression(Expression expression) { return expression instanceof BinaryExpression && isArrayOp(((BinaryExpression) expression).getOperation().getType()); }
private boolean isCompoundAssignment(Expression exp) { if (!(exp instanceof BinaryExpression)) return false; int type = ((BinaryExpression) exp).getOperation().getType(); return isAssignment(type) && type != ASSIGN; }
private static boolean isAssignmentToArray(BinaryExpression binExp) { Expression leftExpression = binExp.getLeftExpression(); if (!(leftExpression instanceof BinaryExpression)) return false; BinaryExpression leftBinExpr = (BinaryExpression) leftExpression; return leftBinExpr.getOperation().getType() == LEFT_SQUARE_BRACKET; }
private Expression parseResults(Expression expr) { while (expr instanceof BinaryExpression) { BinaryExpression binExpr = (BinaryExpression) expr; int type = binExpr.getOperation().getType(); if (type != Types.RIGHT_SHIFT && type != Types.RIGHT_SHIFT_UNSIGNED) break; responses.add(new InteractionResponse(binExpr.getRightExpression(), type == Types.RIGHT_SHIFT_UNSIGNED)); expr = binExpr.getLeftExpression(); } return expr; }
public void visitBinaryExpression(BinaryExpression expression) { onLineNumber(expression, "visitBinaryExpression: \"" + expression.getOperation().getText() + "\" "); controller.getBinaryExpressionHelper().eval(expression); controller.getAssertionWriter().record(expression.getOperation()); }
@Override public void visitBinaryExpression(BinaryExpression expr) { result = new ExpressionInfo( TextRegion.of(expr), expr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET ? startOf("[", expr.getRightExpression()) : // workaround for the fact that Token.startLine == 0 for token [ TextPosition.startOf(expr.getOperation()), expr.getOperation().getText(), convert(expr.getLeftExpression()), convert(expr.getRightExpression()) ); }
private Expression parseCount(Expression expr) { BinaryExpression binExpr = ObjectUtil.asInstance(expr, BinaryExpression.class); if (binExpr == null || binExpr.getOperation().getType() != Types.MULTIPLY) return expr; count = binExpr.getLeftExpression(); return binExpr.getRightExpression(); }
private boolean isLHSOfEnclosingAssignment(final Expression expression) { final BinaryExpression ec = typeCheckingContext.getEnclosingBinaryExpression(); return ec != null && ec.getLeftExpression() == expression && isAssignment(ec.getOperation().getType()); }
private void checkIsValidImplicitCondition(Statement stat) { BinaryExpression binExpr = AstUtil.getExpression(stat, BinaryExpression.class); if (binExpr == null) return; if (Types.ofType(binExpr.getOperation().getType(), Types.ASSIGNMENT_OPERATOR)) { resources.getErrorReporter().error(stat, "Expected a condition, but found an assignment. Did you intend to write '==' ?"); } } }
@Override public void visitBinaryExpression(BinaryExpression expr) { // order of convert calls is important or indexes and thus recorded values get confused Expression convertedLeftExpression = Types.ofType(expr.getOperation().getType(), Types.ASSIGNMENT_OPERATOR) ? // prevent lvalue from getting turned into record(lvalue), which can no longer be assigned to convertAndRecordNa(expr.getLeftExpression()) : convert(expr.getLeftExpression()); Expression convertedRightExpression = convert(expr.getRightExpression()); Expression conversion = Types.ofType(expr.getOperation().getType(), Types.KEYWORD_INSTANCEOF) ? // morph instanceof expression to isInstance method call to be able to record rvalue new MethodCallExpression(convertedRightExpression, "isInstance", convertedLeftExpression): new BinaryExpression(convertedLeftExpression, expr.getOperation(), convertedRightExpression); conversion.setSourcePosition(expr); result = record(conversion); }
private Token getOpWithoutEqual(Expression exp) { if (!(exp instanceof BinaryExpression)) return null; // should never happen Token op = ((BinaryExpression) exp).getOperation(); int typeWithoutEqual = TokenUtil.removeAssignment(op.getType()); return new Token(typeWithoutEqual, op.getText() /* will do */, op.getStartLine(), op.getStartColumn()); }
public void visitBinaryExpression(final BinaryExpression expression) { assertExpressionAuthorized(expression); assertTokenAuthorized(expression.getOperation()); expression.getLeftExpression().visit(this); expression.getRightExpression().visit(this); }
private void rewriteWhereStat(ListIterator<Statement> stats) throws InvalidSpecCompileException { Statement stat = stats.next(); BinaryExpression binExpr = AstUtil.getExpression(stat, BinaryExpression.class); if (binExpr == null || binExpr.getClass() != BinaryExpression.class) // don't allow subclasses like DeclarationExpression notAParameterization(stat); int type = binExpr.getOperation().getType(); if (type == Types.LEFT_SHIFT) { Expression leftExpr = binExpr.getLeftExpression(); if (leftExpr instanceof VariableExpression) rewriteSimpleParameterization(binExpr, stat); else if (leftExpr instanceof ListExpression) rewriteMultiParameterization(binExpr, stat); else notAParameterization(stat); } else if (type == Types.ASSIGN) rewriteDerivedParameterization(binExpr, stat); else if (getOrExpression(binExpr) != null) { stats.previous(); rewriteTableLikeParameterization(stats); } else notAParameterization(stat); }
public static SpecialMethodCall parse(MethodCallExpression methodCallExpr, @Nullable BinaryExpression binaryExpr) { boolean builtInCall = checkIsBuiltInMethodCall(methodCallExpr); boolean conditionBlock = checkIsConditionBlock(methodCallExpr); if (!(builtInCall || conditionBlock)) return null; String methodName = methodCallExpr.getMethodAsString(); Expression inferredName; Expression inferredType; if (binaryExpr != null && binaryExpr.getOperation().getType() == Types.ASSIGN && binaryExpr.getRightExpression() == methodCallExpr) { inferredName = AstUtil.getVariableName(binaryExpr); inferredType = AstUtil.getVariableType(binaryExpr); } else { binaryExpr = null; // not part of this special method call inferredName = ConstantExpression.NULL; inferredType = ConstantExpression.NULL; } ClosureExpression closureExpr = null; List<Expression> arguments = AstUtil.getArgumentList(methodCallExpr); if (!arguments.isEmpty()) { Expression lastArg = CollectionUtil.getLastElement(arguments); if (lastArg instanceof ClosureExpression) { closureExpr = (ClosureExpression) lastArg; } } return new SpecialMethodCall(methodName, inferredName, inferredType, methodCallExpr, binaryExpr, closureExpr, conditionBlock); }
@Override public void visitBinaryExpression(final BinaryExpression expression) { boolean assignment = StaticTypeCheckingSupport.isAssignment(expression.getOperation().getType()); boolean isDeclaration = expression instanceof DeclarationExpression; Expression leftExpression = expression.getLeftExpression(); Expression rightExpression = expression.getRightExpression(); if (isDeclaration) { recordFinalVars(leftExpression); } // visit RHS first for expressions like a = b = 0 inAssignmentRHS = assignment; rightExpression.visit(this); inAssignmentRHS = false; leftExpression.visit(this); if (assignment) { recordAssignments(expression, isDeclaration, leftExpression, rightExpression); } }
private static BinaryExpression tryOptimizeCharComparison(final Expression left, final Expression right, final BinaryExpression bin) { int op = bin.getOperation().getType(); if (isCompareToBoolean(op) || op == COMPARE_EQUAL || op == COMPARE_NOT_EQUAL) { Character cLeft = tryCharConstant(left); Character cRight = tryCharConstant(right); if (cLeft != null || cRight != null) { Expression oLeft = cLeft == null ? left : new ConstantExpression(cLeft, true); oLeft.setSourcePosition(left); Expression oRight = cRight == null ? right : new ConstantExpression(cRight, true); oRight.setSourcePosition(right); bin.setLeftExpression(oLeft); bin.setRightExpression(oRight); return bin; } } return null; }
protected void evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression) { Expression leftExpression = expression.getLeftExpression(); AsmClassGenerator acg = controller.getAcg(); OperandStack operandStack = controller.getOperandStack(); if (leftExpression instanceof BinaryExpression) { BinaryExpression leftBinExpr = (BinaryExpression) leftExpression; if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) { evaluateArrayAssignmentWithOperator(method, expression, leftBinExpr); return; } } evaluateBinaryExpression(method, expression); // br to leave a copy of rvalue on the stack. see also isPopRequired() operandStack.dup(); controller.getCompileStack().pushLHS(true); leftExpression.visit(acg); controller.getCompileStack().popLHS(); }
protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) { Expression leftExp = binExp.getLeftExpression(); Expression rightExp = binExp.getRightExpression(); int operation = binExp.getOperation().getType(); int operationType = getOperandConversionType(leftType,rightType); BinaryExpressionWriter bew = binExpWriter[operationType]; if (!bew.write(operation, true)) return false; AsmClassGenerator acg = getController().getAcg(); OperandStack os = getController().getOperandStack(); leftExp.visit(acg); os.doGroovyCast(bew.getNormalOpResultType()); rightExp.visit(acg); os.doGroovyCast(bew.getNormalOpResultType()); bew.write(operation, false); return true; }