Search in sources :

Example 6 with ConditionalExpression

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

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

the class GuardStructureFactory method getCondition.

/**
 * @return the top {@link Expression} of a {@link GuardStructure}, or null.
 */
private static Expression getCondition(ControlFlowEdge edge) {
    Expression condition = null;
    Node previousNode = edge.start;
    ControlFlowElement previousCFE = previousNode.getControlFlowElement();
    if (previousCFE instanceof ConditionalExpression) {
        ConditionalExpression ce = (ConditionalExpression) previousCFE;
        condition = ce.getExpression();
    } else if (previousCFE instanceof BinaryLogicalExpression) {
        BinaryLogicalExpression ble = (BinaryLogicalExpression) previousCFE;
        condition = ble.getLhs();
    } else if (previousCFE instanceof IfStatement) {
        IfStatement is = (IfStatement) previousCFE;
        condition = is.getExpression();
    } else if (previousCFE instanceof WhileStatement) {
        WhileStatement ws = (WhileStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof DoStatement) {
        DoStatement ws = (DoStatement) previousCFE;
        condition = ws.getExpression();
    } else if (previousCFE instanceof ForStatement) {
        ForStatement ws = (ForStatement) previousCFE;
        condition = ws.getExpression();
    }
    return condition;
}
Also used : IfStatement(org.eclipse.n4js.n4JS.IfStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) DoStatement(org.eclipse.n4js.n4JS.DoStatement) BinaryLogicalExpression(org.eclipse.n4js.n4JS.BinaryLogicalExpression) Expression(org.eclipse.n4js.n4JS.Expression) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) Node(org.eclipse.n4js.flowgraphs.model.Node) ConditionalExpression(org.eclipse.n4js.n4JS.ConditionalExpression) WhileStatement(org.eclipse.n4js.n4JS.WhileStatement) ForStatement(org.eclipse.n4js.n4JS.ForStatement) ControlFlowElement(org.eclipse.n4js.n4JS.ControlFlowElement)

Aggregations

ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)7 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)6 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)4 Expression (org.eclipse.n4js.n4JS.Expression)4 DoStatement (org.eclipse.n4js.n4JS.DoStatement)3 ForStatement (org.eclipse.n4js.n4JS.ForStatement)3 IfStatement (org.eclipse.n4js.n4JS.IfStatement)3 ParenExpression (org.eclipse.n4js.n4JS.ParenExpression)3 WhileStatement (org.eclipse.n4js.n4JS.WhileStatement)3 EObject (org.eclipse.emf.ecore.EObject)2 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)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 Statement (org.eclipse.n4js.n4JS.Statement)2 UnaryExpression (org.eclipse.n4js.n4JS.UnaryExpression)2 HashSet (java.util.HashSet)1 EPackage (org.eclipse.emf.ecore.EPackage)1 GuardType (org.eclipse.n4js.flowgraphs.dataflow.guards.GuardType)1