Search in sources :

Example 6 with UnaryExpression

use of org.eclipse.n4js.n4JS.UnaryExpression in project n4js by eclipse.

the class GuardFactory method createGuardForEquality.

private static Guard createGuardForEquality(EObject topContainer, boolean negateTree, EqualityExpression eqe, boolean sameEqualNot) {
    Expression lhs = eqe.getLhs();
    Expression rhs = eqe.getRhs();
    UnaryOperator luo = lhs instanceof UnaryExpression ? ((UnaryExpression) lhs).getOp() : null;
    UnaryOperator ruo = rhs instanceof UnaryExpression ? ((UnaryExpression) rhs).getOp() : null;
    // typeof foo != 'undefined'
    if (luo == UnaryOperator.TYPEOF) {
        return createGuardForTypeof(topContainer, (UnaryExpression) lhs, negateTree, sameEqualNot, rhs);
    }
    if (ruo == UnaryOperator.TYPEOF) {
        return createGuardForTypeof(topContainer, (UnaryExpression) rhs, negateTree, sameEqualNot, lhs);
    }
    // name == void 0
    if (luo == UnaryOperator.VOID && SymbolFactory.canCreate(rhs)) {
        return createGuardForVoid(topContainer, (UnaryExpression) lhs, negateTree, sameEqualNot, rhs);
    }
    if (ruo == UnaryOperator.VOID && SymbolFactory.canCreate(lhs)) {
        return createGuardForVoid(topContainer, (UnaryExpression) rhs, negateTree, sameEqualNot, lhs);
    }
    // v == null|undefined|0
    if (SymbolFactory.canCreate(lhs) && SymbolFactory.canCreate(rhs)) {
        GuardType guardType = getGuardType(lhs);
        Expression symbolExpr = rhs;
        if (guardType == null) {
            guardType = getGuardType(rhs);
            symbolExpr = lhs;
        }
        if (guardType != null) {
            return createGuardForNUZ(topContainer, eqe, negateTree, sameEqualNot, guardType, symbolExpr);
        }
    }
    return null;
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator)

Example 7 with UnaryExpression

use of org.eclipse.n4js.n4JS.UnaryExpression in project n4js by eclipse.

the class GuardFactory method createGuardForTypeof.

private static Guard createGuardForTypeof(EObject topContainer, UnaryExpression ue, boolean negateTree, boolean negateEqe, Expression rhs) {
    if (rhs instanceof StringLiteral) {
        StringLiteral rhsStringLit = (StringLiteral) rhs;
        String lit = rhsStringLit.getValue();
        if (!"undefined".equals(lit)) {
            return null;
        }
    }
    Expression typeofExpr = ue.getExpression();
    if (SymbolFactory.canCreate(typeofExpr)) {
        GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, ue.eContainer(), negateTree, negateEqe);
        Guard guard = createIsUndefinedGuard(ue, asserts, typeofExpr);
        return guard;
    }
    return null;
}
Also used : StringLiteral(org.eclipse.n4js.n4JS.StringLiteral) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression)

Aggregations

BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)7 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)7 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)6 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)6 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)6 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)5 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)5 Expression (org.eclipse.n4js.n4JS.Expression)4 EObject (org.eclipse.emf.ecore.EObject)2 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)2 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)2 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)2 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)2 CastExpression (org.eclipse.n4js.n4JS.CastExpression)2 CommaExpression (org.eclipse.n4js.n4JS.CommaExpression)2 StringLiteral (org.eclipse.n4js.n4JS.StringLiteral)2 EPackage (org.eclipse.emf.ecore.EPackage)1 Annotation (org.eclipse.n4js.n4JS.Annotation)1 AnnotationList (org.eclipse.n4js.n4JS.AnnotationList)1 Argument (org.eclipse.n4js.n4JS.Argument)1