Search in sources :

Example 1 with Expression

use of org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression in project xtext-core by eclipse.

the class ConditionSimplifier method simplify.

public void simplify(IfCondition condition) {
    Expression expression = simplifyRecursive(condition.getCondition());
    condition.setCondition(expression);
}
Also used : AndExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression) OrExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression) Expression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression)

Example 2 with Expression

use of org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression in project xtext-core by eclipse.

the class ConditionSimplifier method caseNotExpression.

@Override
public Expression caseNotExpression(NotExpression object) {
    if (object.getExpression() instanceof NotExpression)
        return doSwitch(((NotExpression) object.getExpression()).getExpression());
    Expression result = doSwitch(object.getExpression());
    if (result instanceof BooleanLiteral) {
        BooleanLiteral casted = (BooleanLiteral) result;
        casted.setValue(!casted.isValue());
        return casted;
    } else {
        object.setExpression(result);
        return object;
    }
}
Also used : AndExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression) OrExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression) Expression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression) BooleanLiteral(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.BooleanLiteral) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression)

Example 3 with Expression

use of org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression in project xtext-core by eclipse.

the class ConditionSimplifier method caseOrExpression.

@Override
public Expression caseOrExpression(OrExpression object) {
    if (object.getRight() == null)
        return doSwitch(object.getLeft());
    if (object.getLeft() == null)
        return doSwitch(object.getRight());
    Expression left = doSwitch(object.getLeft());
    Expression right = doSwitch(object.getRight());
    if (areSemanticallyEqual(left, right))
        return left;
    if (left instanceof BooleanLiteral) {
        if (((BooleanLiteral) left).isValue()) {
            return left;
        }
        return right;
    }
    if (right instanceof BooleanLiteral) {
        if (((BooleanLiteral) right).isValue()) {
            return right;
        }
        return left;
    }
    if (left instanceof AndExpression) {
        AndExpression leftAsAnd = (AndExpression) left;
        if (areSemanticallyEqual(leftAsAnd.getLeft(), right) || areSemanticallyEqual(leftAsAnd.getRight(), right))
            return right;
    } else if (right instanceof AndExpression) {
        AndExpression rightAsAnd = (AndExpression) right;
        if (areSemanticallyEqual(rightAsAnd.getLeft(), left) || areSemanticallyEqual(rightAsAnd.getRight(), left))
            return left;
    }
    if (left instanceof OrExpression) {
        OrExpression leftAsOr = (OrExpression) left;
        if (areSemanticallyEqual(leftAsOr.getLeft(), right) || areSemanticallyEqual(leftAsOr.getRight(), right))
            return left;
    } else if (right instanceof OrExpression) {
        OrExpression rightAsOr = (OrExpression) right;
        if (areSemanticallyEqual(rightAsOr.getLeft(), left) || areSemanticallyEqual(rightAsOr.getRight(), left))
            return right;
    }
    if (left instanceof NotExpression) {
        if (areSemanticallyEqual(((NotExpression) left).getExpression(), right)) {
            BooleanLiteral result = SimpleExpressionsFactory.eINSTANCE.createBooleanLiteral();
            result.setValue(true);
            return result;
        }
    } else if (right instanceof NotExpression) {
        if (areSemanticallyEqual(left, ((NotExpression) right).getExpression())) {
            BooleanLiteral result = SimpleExpressionsFactory.eINSTANCE.createBooleanLiteral();
            result.setValue(true);
            return result;
        }
    }
    object.setLeft(left);
    object.setRight(right);
    return object;
}
Also used : AndExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression) AndExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression) OrExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression) Expression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression) BooleanLiteral(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.BooleanLiteral) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression) OrExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression)

Example 4 with Expression

use of org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression in project xtext-core by eclipse.

the class ConditionSimplifier method caseAndExpression.

@Override
public Expression caseAndExpression(AndExpression object) {
    if (object.getRight() == null)
        return doSwitch(object.getLeft());
    if (object.getLeft() == null)
        return doSwitch(object.getRight());
    Expression left = doSwitch(object.getLeft());
    Expression right = doSwitch(object.getRight());
    if (areSemanticallyEqual(left, right))
        return left;
    if (left instanceof BooleanLiteral) {
        if (((BooleanLiteral) left).isValue()) {
            return right;
        }
        return left;
    }
    if (right instanceof BooleanLiteral) {
        if (((BooleanLiteral) right).isValue()) {
            return left;
        }
        return right;
    }
    if (left instanceof NotExpression) {
        if (areSemanticallyEqual(((NotExpression) left).getExpression(), right)) {
            BooleanLiteral result = SimpleExpressionsFactory.eINSTANCE.createBooleanLiteral();
            result.setValue(false);
            return result;
        }
    } else if (right instanceof NotExpression) {
        if (areSemanticallyEqual(left, ((NotExpression) right).getExpression())) {
            BooleanLiteral result = SimpleExpressionsFactory.eINSTANCE.createBooleanLiteral();
            result.setValue(false);
            return result;
        }
    }
    object.setLeft(left);
    object.setRight(right);
    return object;
}
Also used : AndExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression) OrExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression) Expression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression) BooleanLiteral(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.BooleanLiteral) NotExpression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression)

Example 5 with Expression

use of org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression in project xtext-core by eclipse.

the class ComparisonImpl method basicSetLeft.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetLeft(Expression newLeft, NotificationChain msgs) {
    Expression oldLeft = left;
    left = newLeft;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SimpleExpressionsPackage.COMPARISON__LEFT, oldLeft, newLeft);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.Expression)12 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)8 AndExpression (org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.AndExpression)6 OrExpression (org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.OrExpression)6 NotExpression (org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.NotExpression)5 BooleanLiteral (org.eclipse.xtext.xtext.generator.parser.antlr.splitting.simpleExpressions.BooleanLiteral)3