use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class Reducer method reduceConstraintForTypeArgumentPair.
/**
* Will add a constraint ⟨ leftArg :> rightArg ⟩, taking into account wildcards, closed existential types, and
* definition site variance.
*/
private boolean reduceConstraintForTypeArgumentPair(TypeArgument leftArg, TypeVariable leftParam, TypeArgument rightArg) {
boolean wasAdded = false;
if (leftArg instanceof Wildcard) {
final TypeRef ub = ((Wildcard) leftArg).getDeclaredUpperBound();
if (ub != null) {
wasAdded |= reduce(ub, ts.upperBound(G, rightArg).getValue(), CONTRA);
}
final TypeRef lb = ((Wildcard) leftArg).getDeclaredLowerBound();
if (lb != null) {
wasAdded |= reduce(lb, ts.lowerBound(G, rightArg).getValue(), CO);
}
} else if (rightArg instanceof ExistentialTypeRef) {
// TODO IDE-1653 reconsider this entire case
// re-open the existential type, because we assume it was closed only while adding substitutions
// UPDATE: this is wrong if right.typeArgs already contained an ExistentialTypeRef! (but might be
// an non-harmful over approximation)
final Wildcard w = ((ExistentialTypeRef) rightArg).getWildcard();
final TypeRef ub = w.getDeclaredUpperBound();
if (ub != null) {
wasAdded |= reduce(ub, ts.upperBound(G, leftArg).getValue(), CONTRA);
}
final TypeRef lb = w.getDeclaredLowerBound();
if (lb != null) {
wasAdded |= reduce(lb, ts.lowerBound(G, leftArg).getValue(), CO);
}
} else {
if (!(leftArg instanceof TypeRef)) {
throw new UnsupportedOperationException("unsupported subtype of TypeArgument: " + leftArg.getClass().getName());
}
// due to the assumption of the method, we always have: leftArg :> rightArg
// (so for def-site variance we just look at the left side in this case, i.e. leftParam)
final Variance leftDefSiteVarianceRaw = leftParam.getVariance();
final Variance leftDefSiteVariance = leftDefSiteVarianceRaw != null ? leftDefSiteVarianceRaw : INV;
wasAdded |= reduce(leftArg, rightArg, CONTRA.mult(leftDefSiteVariance));
}
return wasAdded;
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class Reducer method reduceWildcard.
// TODO IDE-1653 reconsider handling of wildcards in Reducer#reduceWildcard()
private boolean reduceWildcard(Wildcard left, Wildcard right, @SuppressWarnings("unused") Variance variance) {
if (left == right) {
// trivial ==, <:, and :> of a wildcard to itself.
return false;
}
boolean wasAdded = false;
final TypeRef lbLeft = left.getDeclaredLowerBound();
final TypeRef lbRight = right.getDeclaredLowerBound();
if (lbLeft != null || lbRight != null) {
// ⟨ ? super L Φ ? ⟩ implies `L = bottom`
// ⟨ ? super L Φ ? extends R ⟩ implies `L = bottom`
// ⟨ ? super L Φ ? super R ⟩ implies `L = R`
final TypeRef lbLeftOrBottom = (lbLeft != null) ? lbLeft : bottom();
final TypeRef lbRightOrBottom = (lbRight != null) ? lbRight : bottom();
wasAdded |= reduce(lbLeftOrBottom, lbRightOrBottom, INV);
}
final TypeRef ubLeft = left.getDeclaredUpperBound();
final TypeRef ubRight = right.getDeclaredUpperBound();
if (ubLeft != null || ubRight != null) {
// ⟨ ? extends L Φ ? ⟩ implies `L = top`
// ⟨ ? extends L Φ ? super R ⟩ implies `L = top`
// ⟨ ? extends L Φ ? extends R ⟩ implies `L = R`
final TypeRef ubLeftOrTop = (ubLeft != null) ? ubLeft : top();
final TypeRef ubRightOrTop = (ubRight != null) ? ubRight : top();
wasAdded |= reduce(ubLeftOrTop, ubRightOrTop, INV);
}
return wasAdded;
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class FieldFactory method create.
@Override
public TField create(String name) {
TField field = TypesFactory.eINSTANCE.createTField();
field.setComposed(true);
TypeRef typeRef = getReturnTypeRef();
TypeUtils.setMemberTypeRef(field, typeRef);
field.setName(name);
field.setDeclaredFinal(isFinal());
field.setDeclaredMemberAccessModifier(getAccessability());
return field;
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeYieldExpression.
protected Result<TypeRef> applyRuleTypeYieldExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final YieldExpression y) throws RuleFailedException {
// output parameter
TypeRef T = null;
TypeRef t = null;
boolean _isMany = y.isMany();
if (_isMany) {
final Expression yieldValue = y.getExpression();
/* G |- yieldValue : var TypeRef yieldValueTypeRef */
TypeRef yieldValueTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, yieldValue);
checkAssignableTo(result.getFirst(), TypeRef.class);
yieldValueTypeRef = (TypeRef) result.getFirst();
final BuiltInTypeScope scope = RuleEnvironmentExtensions.getPredefinedTypes(G).builtInTypeScope;
boolean _isGenerator = TypeUtils.isGenerator(yieldValueTypeRef, scope);
if (_isGenerator) {
t = this.typeSystemHelper.getGeneratorTReturn(G, yieldValueTypeRef);
} else {
final ParameterizedTypeRef itTypeRef = RuleEnvironmentExtensions.iterableTypeRef(G, TypeUtils.createWildcard());
/* G |- yieldValueTypeRef <: itTypeRef */
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, yieldValueTypeRef, itTypeRef);
final boolean isIterable = _ruleinvocation;
if (isIterable) {
t = scope.getAnyTypeRef();
}
}
} else {
final TypeRef actualGenTypeRef = this.typeSystemHelper.getActualGeneratorReturnType(G, y);
if ((actualGenTypeRef != null)) {
t = this.typeSystemHelper.getGeneratorTNext(G, actualGenTypeRef);
}
}
if ((t == null)) {
t = RuleEnvironmentExtensions.anyTypeRef(G);
}
T = t;
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.TypeRef in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ShiftExpression e) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeShiftExpression(G, _subtrace_, e);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeShiftExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeShiftExpression) {
typeThrowException(ruleName("typeShiftExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + "ParameterizedTypeRef", TYPESHIFTEXPRESSION, e_applyRuleTypeShiftExpression, e, new ErrorInformation[] { new ErrorInformation(e) });
return null;
}
}
Aggregations