Search in sources :

Example 6 with Symbol

use of org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol in project n4js by eclipse.

the class AssignmentRelationFactory method findInVariableDeclaration.

private void findInVariableDeclaration(Multimap<Symbol, Object> assgns, VariableDeclaration vd) {
    EObject parent = vd.eContainer();
    if (parent instanceof ForStatement) {
        ForStatement fs = (ForStatement) parent;
        if (!fs.isForPlain()) {
            findInForStatementInOf(assgns, vd, (ForStatement) parent);
            return;
        }
    }
    Expression rhs = vd.getExpression();
    if (rhs == null) {
        Symbol undefinedSymbol = symbolFactory.getUndefined();
        createRelation(assgns, vd, undefinedSymbol, null);
    } else {
        handleSubexpressions(assgns, vd, rhs);
    }
}
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) Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) EObject(org.eclipse.emf.ecore.EObject) ForStatement(org.eclipse.n4js.n4JS.ForStatement)

Example 7 with Symbol

use of org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol in project n4js by eclipse.

the class AssignmentRelationFactory method createRelation.

private void createRelation(Multimap<Symbol, Object> assgns, ControlFlowElement lhs, Expression rhs) {
    Symbol rSymbol = symbolFactory.create(rhs);
    createRelation(assgns, lhs, rSymbol, rhs);
}
Also used : Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol)

Example 8 with Symbol

use of org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol 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 9 with Symbol

use of org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol in project n4js by eclipse.

the class NullDereferenceResult method getFailedSymbol.

private Symbol getFailedSymbol(IsNotNull inn) {
    if (inn.failedBranches.isEmpty()) {
        return null;
    }
    Set<Symbol> failedSymbols = new HashSet<>();
    for (PartialResult result : inn.failedBranches) {
        NullDerefernceFailed ndFailed = (NullDerefernceFailed) result;
        failedSymbols.add(ndFailed.symbol);
    }
    if (failedSymbols.size() == 1) {
        return failedSymbols.iterator().next();
    }
    return null;
}
Also used : Symbol(org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol) PartialResult(org.eclipse.n4js.flowgraphs.dataflow.PartialResult) HashSet(java.util.HashSet)

Aggregations

Symbol (org.eclipse.n4js.flowgraphs.dataflow.symbols.Symbol)9 HashSet (java.util.HashSet)3 EObject (org.eclipse.emf.ecore.EObject)2 AssignmentExpression (org.eclipse.n4js.n4JS.AssignmentExpression)2 ConditionalExpression (org.eclipse.n4js.n4JS.ConditionalExpression)2 ControlFlowElement (org.eclipse.n4js.n4JS.ControlFlowElement)2 Expression (org.eclipse.n4js.n4JS.Expression)2 PartialResult (org.eclipse.n4js.flowgraphs.dataflow.PartialResult)1 Guard (org.eclipse.n4js.flowgraphs.dataflow.guards.Guard)1 GuardStructure (org.eclipse.n4js.flowgraphs.dataflow.guards.GuardStructure)1 GuardType (org.eclipse.n4js.flowgraphs.dataflow.guards.GuardType)1 BinaryLogicalExpression (org.eclipse.n4js.n4JS.BinaryLogicalExpression)1 DestructNode (org.eclipse.n4js.n4JS.DestructNode)1 ForStatement (org.eclipse.n4js.n4JS.ForStatement)1