Search in sources :

Example 11 with Expression

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

the class InternalTypeSystem method applyRuleTypePropertyNameValuePair.

protected Result<TypeRef> applyRuleTypePropertyNameValuePair(final RuleEnvironment G, final RuleApplicationTrace _trace_, final PropertyNameValuePair property) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    TypeRef _declaredTypeRef = property.getDeclaredTypeRef();
    boolean _tripleNotEquals = (_declaredTypeRef != null);
    if (_tripleNotEquals) {
        T = property.getDeclaredTypeRef();
    } else {
        Expression _expression = property.getExpression();
        boolean _tripleNotEquals_1 = (_expression != null);
        if (_tripleNotEquals_1) {
            /* G |- property.expression: var TypeRef E */
            Expression _expression_1 = property.getExpression();
            TypeRef E = null;
            Result<TypeRef> result = typeInternal(G, _trace_, _expression_1);
            checkAssignableTo(result.getFirst(), TypeRef.class);
            E = (TypeRef) result.getFirst();
            /* G |~ E /\ E */
            Result<TypeRef> result_1 = upperBoundInternal(G, _trace_, E);
            checkAssignableTo(result_1.getFirst(), TypeRef.class);
            E = (TypeRef) result_1.getFirst();
            if ((((E.getDeclaredType() == RuleEnvironmentExtensions.undefinedType(G)) || (E.getDeclaredType() == RuleEnvironmentExtensions.nullType(G))) || (E.getDeclaredType() == RuleEnvironmentExtensions.voidType(G)))) {
                T = RuleEnvironmentExtensions.anyTypeRef(G);
            } else {
                T = E;
            }
        } else {
            T = RuleEnvironmentExtensions.anyTypeRef(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) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 12 with Expression

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

the class InternalTypeSystem method applyRuleTypeBinaryLogicalExpression.

protected Result<TypeRef> applyRuleTypeBinaryLogicalExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BinaryLogicalExpression e) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    final Expression lhs = e.getLhs();
    final Expression rhs = e.getRhs();
    boolean _xifexpression = false;
    if ((lhs instanceof ArrayLiteral)) {
        _xifexpression = ((ArrayLiteral) lhs).getElements().isEmpty();
    }
    final boolean lhsIsEmptyArrayLiteral = _xifexpression;
    boolean _xifexpression_1 = false;
    if ((rhs instanceof ArrayLiteral)) {
        _xifexpression_1 = ((ArrayLiteral) rhs).getElements().isEmpty();
    }
    final boolean rhsIsEmptyArrayLiteral = _xifexpression_1;
    /* G |- e.lhs : var TypeRef L */
    Expression _lhs = e.getLhs();
    TypeRef L = null;
    Result<TypeRef> result = typeInternal(G, _trace_, _lhs);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    L = (TypeRef) result.getFirst();
    /* G |- e.rhs : var TypeRef R */
    Expression _rhs = e.getRhs();
    TypeRef R = null;
    Result<TypeRef> result_1 = typeInternal(G, _trace_, _rhs);
    checkAssignableTo(result_1.getFirst(), TypeRef.class);
    R = (TypeRef) result_1.getFirst();
    boolean _and = false;
    boolean _lhsIsEmptyArrayLiteral = lhsIsEmptyArrayLiteral;
    if (!_lhsIsEmptyArrayLiteral) {
        _and = false;
    } else {
        Type _declaredType = null;
        if (R != null) {
            _declaredType = R.getDeclaredType();
        }
        TObjectPrototype _arrayType = RuleEnvironmentExtensions.arrayType(G);
        boolean _tripleEquals = (_declaredType == _arrayType);
        _and = _tripleEquals;
    }
    if (_and) {
        T = R;
    } else {
        boolean _and_1 = false;
        boolean _rhsIsEmptyArrayLiteral = rhsIsEmptyArrayLiteral;
        if (!_rhsIsEmptyArrayLiteral) {
            _and_1 = false;
        } else {
            Type _declaredType_1 = null;
            if (L != null) {
                _declaredType_1 = L.getDeclaredType();
            }
            TObjectPrototype _arrayType_1 = RuleEnvironmentExtensions.arrayType(G);
            boolean _tripleEquals_1 = (_declaredType_1 == _arrayType_1);
            _and_1 = _tripleEquals_1;
        }
        if (_and_1) {
            T = L;
        } else {
            T = this.typeSystemHelper.createUnionType(G, L, R);
        }
    }
    return new Result<TypeRef>(T);
}
Also used : Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) 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) TObjectPrototype(org.eclipse.n4js.ts.types.TObjectPrototype) 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) ArrayLiteral(org.eclipse.n4js.n4JS.ArrayLiteral) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 13 with Expression

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

the class ExceptionAnalyser method getScriptErrors.

@Override
protected List<Diagnostic> getScriptErrors(Script script) {
    EcoreUtil.resolveAll(script.eResource());
    List<Diagnostic> diagnostics = super.getScriptErrors(script);
    Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
    List<Diagnostic> result = Lists.<Diagnostic>newArrayList(Iterables.filter(diagnostics, ExceptionDiagnostic.class));
    while (expressions.hasNext()) {
        Expression expression = expressions.next();
        RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
        Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
        if (type.getRuleFailedException() != null) {
            Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
            if (!(cause instanceof RuleFailedException)) {
                if (cause instanceof Exception) {
                    result.add(new ExceptionDiagnostic((Exception) cause));
                } else {
                    throw new RuntimeException(cause);
                }
            }
        }
    }
    validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
    return result;
}
Also used : Expression(org.eclipse.n4js.n4JS.Expression) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException)

Example 14 with Expression

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

the class IndexedAccessExpressionImpl method basicSetIndex.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetIndex(Expression newIndex, NotificationChain msgs) {
    Expression oldIndex = index;
    index = newIndex;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.INDEXED_ACCESS_EXPRESSION__INDEX, oldIndex, newIndex);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : IndexedAccessExpression(org.eclipse.n4js.n4JS.IndexedAccessExpression) Expression(org.eclipse.n4js.n4JS.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 15 with Expression

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

the class CastExpressionImpl method basicSetExpression.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExpression(Expression newExpression, NotificationChain msgs) {
    Expression oldExpression = expression;
    expression = newExpression;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.CAST_EXPRESSION__EXPRESSION, oldExpression, newExpression);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : CastExpression(org.eclipse.n4js.n4JS.CastExpression) Expression(org.eclipse.n4js.n4JS.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.eclipse.n4js.n4JS.Expression)111 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)58 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)40 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)38 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)37 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)35 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)33 EqualityExpression (org.eclipse.n4js.n4JS.EqualityExpression)31 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)31 RelationalExpression (org.eclipse.n4js.n4JS.RelationalExpression)31 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)31 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)27 BinaryBitwiseExpression (org.eclipse.n4js.n4JS.BinaryBitwiseExpression)27 IndexedAccessExpression (org.eclipse.n4js.n4JS.IndexedAccessExpression)27 MultiplicativeExpression (org.eclipse.n4js.n4JS.MultiplicativeExpression)27 ShiftExpression (org.eclipse.n4js.n4JS.ShiftExpression)27 AwaitExpression (org.eclipse.n4js.n4JS.AwaitExpression)26 CastExpression (org.eclipse.n4js.n4JS.CastExpression)26 FunctionExpression (org.eclipse.n4js.n4JS.FunctionExpression)26 NewExpression (org.eclipse.n4js.n4JS.NewExpression)26