Search in sources :

Example 46 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method testShneCondition5.

@SuppressWarnings("unchecked")
public void testShneCondition5() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.SHNE, createVar(blind, "a", createUnionType(NULL_TYPE, VOID_TYPE)), createVar(blind, "b", createUnionType(NULL_TYPE)), ImmutableSet.of(new TypedName("a", VOID_TYPE), new TypedName("b", NULL_TYPE)), ImmutableSet.of(new TypedName("a", NULL_TYPE), new TypedName("b", NULL_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 47 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method testShneCondition3.

/**
 * Tests reverse interpretation of a SHNE(NAME, NAME) expression.
 */
@SuppressWarnings("unchecked")
public void testShneCondition3() throws Exception {
    FlowScope blind = newScope();
    testBinop(blind, Token.SHNE, createVar(blind, "b", createUnionType(STRING_TYPE, BOOLEAN_TYPE)), createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), ImmutableSet.of(new TypedName("a", createUnionType(STRING_TYPE, NUMBER_TYPE)), new TypedName("b", createUnionType(STRING_TYPE, BOOLEAN_TYPE))), ImmutableSet.of(new TypedName("a", STRING_TYPE), new TypedName("b", STRING_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 48 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method testInstanceOf.

@SuppressWarnings("unchecked")
public void testInstanceOf() {
    FlowScope blind = newScope();
    testBinop(blind, Token.INSTANCEOF, createVar(blind, "x", UNKNOWN_TYPE), createVar(blind, "s", STRING_OBJECT_FUNCTION_TYPE), ImmutableSet.of(new TypedName("x", STRING_OBJECT_TYPE), new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)), ImmutableSet.of(new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 49 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class SemanticReverseAbstractInterpreterTest method testInstanceOf4.

@SuppressWarnings("unchecked")
public void testInstanceOf4() {
    FlowScope blind = newScope();
    testBinop(blind, Token.INSTANCEOF, createVar(blind, "x", ALL_TYPE), createVar(blind, "s", STRING_OBJECT_FUNCTION_TYPE), ImmutableSet.of(new TypedName("x", STRING_OBJECT_TYPE), new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)), ImmutableSet.of(new TypedName("s", STRING_OBJECT_FUNCTION_TYPE)));
}
Also used : FlowScope(com.google.javascript.jscomp.type.FlowScope)

Example 50 with FlowScope

use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.

the class TypeInference method traverseHook.

private FlowScope traverseHook(Node n, FlowScope scope) {
    Node condition = n.getFirstChild();
    Node trueNode = condition.getNext();
    Node falseNode = n.getLastChild();
    // verify the condition
    scope = traverse(condition, scope);
    // reverse abstract interpret the condition to produce two new scopes
    FlowScope trueScope = reverseInterpreter.getPreciserScopeKnowingConditionOutcome(condition, scope, Outcome.TRUE);
    FlowScope falseScope = reverseInterpreter.getPreciserScopeKnowingConditionOutcome(condition, scope, Outcome.FALSE);
    // traverse the true node with the trueScope
    traverse(trueNode, trueScope);
    // traverse the false node with the falseScope
    traverse(falseNode, falseScope);
    // meet true and false nodes' types and assign
    JSType trueType = trueNode.getJSType();
    JSType falseType = falseNode.getJSType();
    if (trueType != null && falseType != null) {
        n.setJSType(trueType.getLeastSupertype(falseType));
    } else {
        n.setJSType(unknownType);
    }
    return scope;
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Node(com.google.javascript.rhino.Node) FlowScope(com.google.javascript.jscomp.type.FlowScope)

Aggregations

FlowScope (com.google.javascript.jscomp.type.FlowScope)60 Node (com.google.javascript.rhino.Node)20 Test (org.junit.Test)16 JSType (com.google.javascript.rhino.jstype.JSType)12 Token (com.google.javascript.rhino.Token)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 CheckReturnValue (com.google.errorprone.annotations.CheckReturnValue)1 Branch (com.google.javascript.jscomp.ControlFlowGraph.Branch)1 AbstractScopedCallback (com.google.javascript.jscomp.NodeTraversal.AbstractScopedCallback)1 DiGraphEdge (com.google.javascript.jscomp.graph.DiGraph.DiGraphEdge)1 Module (com.google.javascript.jscomp.modules.Module)1 ClosureReverseAbstractInterpreter (com.google.javascript.jscomp.type.ClosureReverseAbstractInterpreter)1 ReverseAbstractInterpreter (com.google.javascript.jscomp.type.ReverseAbstractInterpreter)1 JSTypeResolver (com.google.javascript.rhino.jstype.JSTypeResolver)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1 StaticTypedScope (com.google.javascript.rhino.jstype.StaticTypedScope)1 TemplateType (com.google.javascript.rhino.jstype.TemplateType)1 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1