Search in sources :

Example 71 with Expression

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

the class AssignmentRelationFactory method findInAllDestructNodes.

private void findInAllDestructNodes(Multimap<Symbol, Object> assgns, ControlFlowElement cfe) {
    EObject top = DestructureUtils.getTop(cfe);
    DestructNode dNode = DestructNode.unify(top);
    if (dNode == null) {
        return;
    }
    if (top instanceof ForStatement) {
        ForStatement fs = (ForStatement) top;
        Expression fsExpr = fs.getExpression();
        if (fsExpr instanceof ArrayLiteral) {
            ArrayLiteral al = (ArrayLiteral) fsExpr;
            EObject rootOfDestrNode = DestructureUtils.getRoot(cfe);
            for (ArrayElement arrElem : al.getElements()) {
                dNode = DestructNode.unify(rootOfDestrNode, arrElem.getExpression());
                findInDestructNodes(assgns, dNode);
            }
        }
    } else {
        findInDestructNodes(assgns, dNode);
    }
}
Also used : BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) EObject(org.eclipse.emf.ecore.EObject) DestructNode(org.eclipse.n4js.n4JS.DestructNode) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ArrayLiteral(org.eclipse.n4js.n4JS.ArrayLiteral) ArrayElement(org.eclipse.n4js.n4JS.ArrayElement)

Example 72 with Expression

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

the class Assumption method callHoldsOnDataflow.

/**
 * Called from {@link DataFlowBranchWalker}.
 * <p>
 * Method transforms multiple right hand sides into separate calls to
 * {@link #callHoldsOnDataflow(Symbol, Collection)}. Multiple right hand sides occur when either using
 * {@link ConditionalExpression}s <br/>
 * {@code let v = 1 ? null : undefined;} <br/>
 * or when using nested {@link AssignmentExpression}s <br/>
 * {@code let v = a = null;}.
 */
final void callHoldsOnDataflow(Symbol lhs, Collection<Object> rhss) {
    checkState(isOpen());
    Set<PartialResult.Type> resultSet = new HashSet<>();
    for (Object rhs : rhss) {
        Symbol rSymbol = null;
        PartialResult result = null;
        if (rhs instanceof Symbol) {
            rSymbol = (Symbol) rhs;
            result = holdsOnDataflow(lhs, rSymbol, null);
            aliases.remove(lhs);
            if (rSymbol.isVariableSymbol() && followAliases()) {
                aliases.add(rSymbol);
            }
        } else if (rhs instanceof Expression) {
            Expression rValue = (Expression) rhs;
            result = holdsOnDataflow(lhs, null, rValue);
        }
        if (result != null) {
            resultSet.add(result.type);
            handleHoldResult(result, lhs);
        }
    }
    if (resultSet.size() > 1 && resultSet.contains(PartialResult.Type.Unclear)) {
        openBranch = true;
    }
}
Also used : GuardType(org.eclipse.n4js.flowgraphs.dataflow.guards.GuardType) AssignmentExpression(org.eclipse.n4js.n4JS.AssignmentExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) HashSet(java.util.HashSet)

Example 73 with Expression

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

the class SymbolOfParameterizedPropertyAccessExpression method createSymbolKey.

@Override
protected Object createSymbolKey() {
    List<Object> keyChain = new LinkedList<>();
    keyChain.add(getDeclaration());
    Expression lastContext = getContext();
    Symbol tgtSymbol = getContextSymbol();
    while (tgtSymbol != null) {
        keyChain.add(tgtSymbol.getDeclaration());
        lastContext = tgtSymbol.getContext();
        tgtSymbol = tgtSymbol.getContextSymbol();
    }
    if (lastContext != null) {
        keyChain.add(lastContext);
    }
    int hash = Objects.hash(keyChain.toArray(new Object[keyChain.size()]));
    return hash;
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) Expression(org.eclipse.n4js.n4JS.Expression) EObject(org.eclipse.emf.ecore.EObject) LinkedList(java.util.LinkedList)

Example 74 with Expression

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

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

the class GuardFactory method createGuardForInstanceof.

private static Guard createGuardForInstanceof(EObject topContainer, boolean negateTree, RelationalExpression re) {
    Expression lhs = re.getLhs();
    Expression rhs = re.getRhs();
    if (SymbolFactory.canCreate(lhs)) {
        GuardAssertion asserts = FlowAssertionFactory.getGuard(topContainer, re, negateTree, false);
        Guard guard = createIsZeroGuard(re, asserts, lhs, rhs);
        return guard;
    }
    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)

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