protected Object _internalEvaluate(final XBinaryOperation it, final Context ctx) { Object _xblockexpression = null; { final Context context = ctx.cloneWithExpectation(null); final Object left = this.evaluate(it.getLeftOperand(), context); final Object right = this.evaluate(it.getRightOperand(), context); _xblockexpression = this.evaluateBinaryOperation(it, left, right); } return _xblockexpression; }
/** Replies if the given operator is a reassignment operator. * A reassignment operator changes its left operand. * * @param operator the operator. * @return {@code true} if the operator changes its left operand. */ protected boolean isReassignmentOperator(XBinaryOperation operator) { if (operator.isReassignFirstArgument()) { return true; } final QualifiedName operatorName = this.operatorMapping.getOperator( QualifiedName.create(operator.getFeature().getSimpleName())); final QualifiedName compboundOperatorName = this.operatorMapping.getSimpleOperator(operatorName); return compboundOperatorName != null; }
protected boolean isTripleEqualsOperation(XBinaryOperation binaryOperation){ String syntax = binaryOperation.getConcreteSyntaxFeatureName(); return syntax.equals(OperatorMapping.TRIPLE_EQUALS.toString()) || syntax.equals(OperatorMapping.TRIPLE_NOT_EQUALS.toString()); }
@Check public void checkAssignment(XBinaryOperation binaryOperation) { if (binaryOperation.isReassignFirstArgument()) { XExpression leftOperand = binaryOperation.getLeftOperand(); checkAssignment(leftOperand, false); } }
/** Test if the given expression has side effects. * * @param expression the expression. * @param context the list of context expressions. * @return {@code true} if the expression has side effects. */ protected Boolean _hasSideEffects(XBinaryOperation expression, ISideEffectContext context) { if (isReassignmentOperator(expression)) { if (!isLocalExpression(expression.getLeftOperand(), context, false)) { return true; } } else { if (expression.isTypeLiteral() || expression.isPackageFragment()) { return false; } if (hasSideEffects(expression.getLeftOperand(), context)) { return true; } } if (hasSideEffects(expression.getRightOperand(), context)) { return true; } return false; }
protected boolean startsWithUnaryOperator(EObject obj) { if(obj instanceof XUnaryOperation) return true; if(obj instanceof XBinaryOperation) return startsWithUnaryOperator(((XBinaryOperation)obj).getLeftOperand()); if(obj instanceof XPostfixOperation) { return startsWithUnaryOperator(((XPostfixOperation)obj).getOperand()); } return false; }
@Check public void checkPrimitiveComparedToNull(XBinaryOperation binaryOperation) { String operatorSymbol = binaryOperation.getConcreteSyntaxFeatureName(); XExpression left = binaryOperation.getLeftOperand(); XExpression right = binaryOperation.getRightOperand(); if (right != null && right.eClass() == XbasePackage.Literals.XNULL_LITERAL || left != null && left.eClass() == XbasePackage.Literals.XNULL_LITERAL) { boolean equalsComparison = expressionHelper.isOperatorFromExtension(binaryOperation, operatorSymbol, OperatorMapping.EQUALS, ObjectExtensions.class)
JvmIdentifiableElement feature = operation.getFeature(); Set<String> operatorNames = Sets.newHashSet(); if (feature.eIsProxy()) { ICompositeNode featureNode = (ICompositeNode) nodes.getNodeForSingelValue(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, operation.getFeature()); String featureToken; acceptor.accept(opAdd.getXBinaryOperationLeftOperandAction_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opAdd.getFeatureJvmIdentifiableElementOpAddParserRuleCall_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode); acceptor.accept(opAdd.getRightOperandXMultiplicativeExpressionParserRuleCall_1_1_0(), operation.getRightOperand()); } else if((featureToken = getValidOperator(operation, opMulti.getFeatureJvmIdentifiableElementOpMultiParserRuleCall_1_0_0_1_0_1(), operatorNames, featureNode)) != null) { acceptor.accept(opMulti.getXBinaryOperationLeftOperandAction_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opMulti.getFeatureJvmIdentifiableElementOpMultiParserRuleCall_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode); acceptor.accept(opMulti.getRightOperandXUnaryOperationParserRuleCall_1_1_0(), operation.getRightOperand()); } else if((featureToken = getValidOperator(operation, opOther.getFeatureJvmIdentifiableElementOpOtherParserRuleCall_1_0_0_1_0_1(), operatorNames, featureNode)) != null) { acceptor.accept(opOther.getXBinaryOperationLeftOperandAction_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opOther.getFeatureJvmIdentifiableElementOpOtherParserRuleCall_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode); acceptor.accept(opOther.getRightOperandXAdditiveExpressionParserRuleCall_1_1_0(), operation.getRightOperand()); } else if((featureToken = getValidOperator(operation, opCompare.getFeatureJvmIdentifiableElementOpCompareParserRuleCall_1_1_0_0_1_0_1(), operatorNames, featureNode)) != null) { acceptor.accept(opCompare.getXBinaryOperationLeftOperandAction_1_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opCompare.getFeatureJvmIdentifiableElementOpCompareParserRuleCall_1_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode); acceptor.accept(opCompare.getRightOperandXOtherOperatorExpressionParserRuleCall_1_1_1_0(), operation.getRightOperand()); } else if((featureToken = getValidOperator(operation, opEquality.getFeatureJvmIdentifiableElementOpEqualityParserRuleCall_1_0_0_1_0_1(), operatorNames, featureNode)) != null) { acceptor.accept(opEquality.getXBinaryOperationLeftOperandAction_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opEquality.getFeatureJvmIdentifiableElementOpEqualityParserRuleCall_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode); acceptor.accept(opEquality.getRightOperandXRelationalExpressionParserRuleCall_1_1_0(), operation.getRightOperand()); } else if((featureToken = getValidOperator(operation, opAnd.getFeatureJvmIdentifiableElementOpAndParserRuleCall_1_0_0_1_0_1(), operatorNames, featureNode)) != null) { acceptor.accept(opAnd.getXBinaryOperationLeftOperandAction_1_0_0_0(), operation.getLeftOperand()); acceptor.accept(opAnd.getFeatureJvmIdentifiableElementOpAndParserRuleCall_1_0_0_1_0_1(), operation.getFeature(), featureToken, featureNode);
protected void generateShortCircuitInvocation(final XAbstractFeatureCall featureCall, final ITreeAppendable b) { final XBinaryOperation binaryOperation = (XBinaryOperation) featureCall; final XExpression leftOperand = binaryOperation.getLeftOperand(); final XExpression rightOperand = binaryOperation.getRightOperand(); declareSyntheticVariable(binaryOperation, b); boolean isElvis = binaryOperation.getConcreteSyntaxFeatureName().equals(expressionHelper.getElvisOperator()); prepareExpression(leftOperand, b); if(isElvis) { } else { b.newLine().append("if ("); if (binaryOperation.getConcreteSyntaxFeatureName().equals(expressionHelper.getAndOperator())) { b.append("!"); b.append(") {").increaseIndentation(); b.newLine().append(b.getName(binaryOperation)).append(" = "); b.append(Boolean.toString(binaryOperation.getConcreteSyntaxFeatureName().equals(expressionHelper.getOrOperator()))).append(";"); if (binaryOperation.getImplicitReceiver() != null) { internalToJavaStatement(binaryOperation.getImplicitReceiver(), b, true);
protected boolean isReassignFirstArgument(XAbstractFeatureCall featureCall) { if (featureCall instanceof XBinaryOperation) { XBinaryOperation binaryOperation = (XBinaryOperation) featureCall; return binaryOperation.isReassignFirstArgument(); } return false; }
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) { if (expression instanceof XFeatureCall) { return ((XFeatureCall) expression).getFeatureCallArguments(); } if (expression instanceof XMemberFeatureCall) { return ((XMemberFeatureCall) expression).getMemberCallArguments(); } if (expression instanceof XAssignment) { return Collections.singletonList(((XAssignment) expression).getValue()); } if (expression instanceof XBinaryOperation) { return Collections.singletonList(((XBinaryOperation) expression).getRightOperand()); } // explicit condition to make sure we thought about it if (expression instanceof XUnaryOperation) { return Collections.emptyList(); } if (expression instanceof XPostfixOperation) { return Collections.emptyList(); } return Collections.emptyList(); }
protected boolean startsWithUnaryOperator(EObject obj) { if(obj instanceof XUnaryOperation) return true; if(obj instanceof XBinaryOperation) return startsWithUnaryOperator(((XBinaryOperation)obj).getLeftOperand()); if(obj instanceof XPostfixOperation) { return startsWithUnaryOperator(((XPostfixOperation)obj).getOperand()); } return false; }
protected EvaluationResult _internalEvaluate(final XBinaryOperation it, final EvaluationContext context) { if ((this.isFromXbaseLibrary(it, context) && (it.getRightOperand() != null))) { final EvaluationResult left = this.doEvaluate(it.getLeftOperand(), context); final EvaluationResult right = this.doEvaluate(it.getRightOperand(), context); try { final String op = it.getConcreteSyntaxFeatureName(); Object _switchResult = null; if (op != null) {
protected Object _doEvaluate(XAbstractFeatureCall featureCall, IEvaluationContext context, CancelIndicator indicator) { if (expressionHelper.isShortCircuitOperation(featureCall)) { XExpression leftOperand = ((XBinaryOperation)featureCall).getLeftOperand(); Object result = internalEvaluate(leftOperand, context, indicator); String operatorName = featureCall.getConcreteSyntaxFeatureName(); if (featureCall instanceof XBinaryOperation) { XBinaryOperation binaryOperation = (XBinaryOperation) featureCall; if (binaryOperation.isReassignFirstArgument()) { XAbstractFeatureCall leftOperand = (XAbstractFeatureCall) binaryOperation.getLeftOperand(); assignValueTo(leftOperand.getFeature(), featureCall, result, context, indicator);
private boolean needMultiAssignment(XAbstractFeatureCall expr) { if (expr instanceof XBinaryOperation) { final XBinaryOperation binaryOperation = (XBinaryOperation) expr; return binaryOperation.isReassignFirstArgument(); } return false; }
protected Object _doEvaluate(XSetLiteral literal, IEvaluationContext context, CancelIndicator indicator) { if(isType(literal, Map.class)) { Map<Object, Object> map = newHashMap(); for(XExpression element: literal.getElements()) { if (indicator.isCanceled()) throw new InterpreterCanceledException(); if (expressionHelper.isOperatorFromExtension(element, OperatorMapping.MAPPED_TO, ObjectExtensions.class)) { map.put(internalEvaluate(((XBinaryOperation)element).getLeftOperand(), context, indicator), internalEvaluate(((XBinaryOperation)element).getRightOperand(), context, indicator)); } else if (isType(element, Pair.class)) { Pair<?, ?> pair = (Pair<?, ?>) internalEvaluate(element, context, indicator); map.put(pair == null ? null : pair.getKey(), pair == null ? null : pair.getValue()); } } return Collections.unmodifiableMap(map); } else { Set<Object> set = newHashSet(); for(XExpression element: literal.getElements()) { if (indicator.isCanceled()) throw new InterpreterCanceledException(); set.add(internalEvaluate(element, context, indicator)); } return Collections.unmodifiableSet(set); } }
private void buildLeftOperand(XAbstractFeatureCall expr, List<Object> output) { final XBinaryOperation binaryOperation = (XBinaryOperation) expr; final XAbstractFeatureCall leftOperand = (XAbstractFeatureCall) binaryOperation.getLeftOperand(); final JvmIdentifiableElement feature = leftOperand.getFeature(); if (this.codeReceiver.hasName(feature)) { output.add(this.codeReceiver.getName(feature)); return; } buildCallReceiver(leftOperand, getExtraLanguageKeywordProvider().getThisKeywordLambda(), this.referenceNameLambda, output); output.add(feature.getSimpleName()); }
protected boolean needMultiAssignment(XAbstractFeatureCall expr) { if (expr instanceof XBinaryOperation) { XBinaryOperation binaryOperation = (XBinaryOperation) expr; return binaryOperation.isReassignFirstArgument(); } return false; }
if (operator != null) { it.append("("); //$NON-NLS-1$ generate(operation.getLeftOperand(), it, context); switch (operator) { case "-": //$NON-NLS-1$ throw new IllegalArgumentException(MessageFormat.format(Messages.PyExpressionGenerator_0, operator)); generate(operation.getRightOperand(), it, context); it.append(")"); //$NON-NLS-1$
public XExpression getSyntacticReceiver(XExpression expression) { if (expression instanceof XAbstractFeatureCall) { if (expression instanceof XFeatureCall) { return null; } if (expression instanceof XMemberFeatureCall) { return ((XMemberFeatureCall) expression).getMemberCallTarget(); } if (expression instanceof XAssignment) { return ((XAssignment) expression).getAssignable(); } if (expression instanceof XBinaryOperation) { return ((XBinaryOperation) expression).getLeftOperand(); } if (expression instanceof XUnaryOperation) { return ((XUnaryOperation) expression).getOperand(); } if (expression instanceof XPostfixOperation) { return ((XPostfixOperation) expression).getOperand(); } } return null; }