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)));
}
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)));
}
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)));
}
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)));
}
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;
}
Aggregations