Search in sources :

Example 1 with UnaryOperator

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

the class InternalTypeSystem method applyRuleTypeUnaryExpression.

protected Result<TypeRef> applyRuleTypeUnaryExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnaryExpression e) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    if ((((e.getOp() == UnaryOperator.NEG) || (e.getOp() == UnaryOperator.POS)) && (e.getExpression() instanceof IntLiteral))) {
        /* G |- e.expression : T */
        Expression _expression = e.getExpression();
        Result<TypeRef> result = typeInternal(G, _trace_, _expression);
        checkAssignableTo(result.getFirst(), TypeRef.class);
        T = (TypeRef) result.getFirst();
    } else {
        UnaryOperator _op = e.getOp();
        if (_op != null) {
            switch(_op) {
                case DELETE:
                    T = RuleEnvironmentExtensions.booleanTypeRef(G);
                    break;
                case VOID:
                    T = RuleEnvironmentExtensions.undefinedTypeRef(G);
                    break;
                case TYPEOF:
                    T = RuleEnvironmentExtensions.stringTypeRef(G);
                    break;
                case NOT:
                    T = RuleEnvironmentExtensions.booleanTypeRef(G);
                    break;
                default:
                    T = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
            }
        } else {
            T = RuleEnvironmentExtensions.numberTypeRef(G);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : BinaryBitwiseExpression(org.eclipse.n4js.n4JS.BinaryBitwiseExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) FunctionExpression(org.eclipse.n4js.n4JS.FunctionExpression) PromisifyExpression(org.eclipse.n4js.n4JS.PromisifyExpression) UnaryExpression(org.eclipse.n4js.n4JS.UnaryExpression) ParenExpression(org.eclipse.n4js.n4JS.ParenExpression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) AdditiveExpression(org.eclipse.n4js.n4JS.AdditiveExpression) PostfixExpression(org.eclipse.n4js.n4JS.PostfixExpression) YieldExpression(org.eclipse.n4js.n4JS.YieldExpression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) RelationalExpression(org.eclipse.n4js.n4JS.RelationalExpression) NewExpression(org.eclipse.n4js.n4JS.NewExpression) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) AwaitExpression(org.eclipse.n4js.n4JS.AwaitExpression) CommaExpression(org.eclipse.n4js.n4JS.CommaExpression) Expression(org.eclipse.n4js.n4JS.Expression) CastExpression(org.eclipse.n4js.n4JS.CastExpression) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) EqualityExpression(org.eclipse.n4js.n4JS.EqualityExpression) ShiftExpression(org.eclipse.n4js.n4JS.ShiftExpression) ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) MultiplicativeExpression(org.eclipse.n4js.n4JS.MultiplicativeExpression) N4ClassExpression(org.eclipse.n4js.n4JS.N4ClassExpression) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) IntLiteral(org.eclipse.n4js.n4JS.IntLiteral) UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 2 with UnaryOperator

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

the class PrettyPrinterSwitch method caseUnaryExpression.

@Override
public Boolean caseUnaryExpression(UnaryExpression original) {
    final UnaryOperator op = original.getOp();
    write(op.getLiteral());
    // the following 3 unary operators require an additional space between operator and operand
    if (op == UnaryOperator.TYPEOF || op == UnaryOperator.DELETE || op == UnaryOperator.VOID) {
        write(' ');
    }
    process(original.getExpression());
    return DONE;
}
Also used : UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator)

Example 3 with UnaryOperator

use of org.eclipse.n4js.n4JS.UnaryOperator 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 4 with UnaryOperator

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

the class UnaryExpressionImpl method setOp.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setOp(UnaryOperator newOp) {
    UnaryOperator oldOp = op;
    op = newOp == null ? OP_EDEFAULT : newOp;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.UNARY_EXPRESSION__OP, oldOp, op));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator)

Example 5 with UnaryOperator

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

the class InternalTypeSystem method applyRuleExpectedTypeInUnaryExpression.

protected Result<TypeRef> applyRuleExpectedTypeInUnaryExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final UnaryExpression e, final Expression expression) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    StaticBaseTypeRef _xifexpression = null;
    boolean _isTypeAware = this.jsVariantHelper.isTypeAware(e);
    if (_isTypeAware) {
        StaticBaseTypeRef _switchResult = null;
        UnaryOperator _op = e.getOp();
        if (_op != null) {
            switch(_op) {
                case DELETE:
                    _switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                case VOID:
                    _switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                case TYPEOF:
                    _switchResult = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                case INC:
                    _switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
                case DEC:
                    _switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
                case POS:
                    _switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
                case NEG:
                    _switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
                case INV:
                    _switchResult = RuleEnvironmentExtensions.numberTypeRef(G);
                    break;
                case NOT:
                    _switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
                    break;
                default:
                    _switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
                    break;
            }
        } else {
            _switchResult = RuleEnvironmentExtensions.anyTypeRef(G);
        }
        _xifexpression = _switchResult;
    } else {
        StaticBaseTypeRef _switchResult_1 = null;
        UnaryOperator _op_1 = e.getOp();
        if (_op_1 != null) {
            switch(_op_1) {
                case DELETE:
                    _switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                case VOID:
                    _switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                case TYPEOF:
                    _switchResult_1 = TypeUtils.createNonSimplifiedUnionType(RuleEnvironmentExtensions.anyTypeRef(G), RuleEnvironmentExtensions.voidTypeRef(G));
                    break;
                default:
                    _switchResult_1 = RuleEnvironmentExtensions.anyTypeRef(G);
                    break;
            }
        } else {
            _switchResult_1 = RuleEnvironmentExtensions.anyTypeRef(G);
        }
        _xifexpression = _switchResult_1;
    }
    T = _xifexpression;
    return new Result<TypeRef>(T);
}
Also used : ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) UnaryOperator(org.eclipse.n4js.n4JS.UnaryOperator) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Aggregations

UnaryOperator (org.eclipse.n4js.n4JS.UnaryOperator)5 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)2 Expression (org.eclipse.n4js.n4JS.Expression)2 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)2 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)2 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)2 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)2 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)2 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)2 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)2 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)2 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)2 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)2 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)2 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)2 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)2 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)2 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)2