use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final RelationalExpression e) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeRelationalExpression(G, _subtrace_, e);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeRelationalExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeRelationalExpression) {
typeThrowException(ruleName("typeRelationalExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + "ParameterizedTypeRef", TYPERELATIONALEXPRESSION, e_applyRuleTypeRelationalExpression, e, new ErrorInformation[] { new ErrorInformation(e) });
return null;
}
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleExpectedTypeInAssignmentExpression.
protected Result<TypeRef> applyRuleExpectedTypeInAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr, final Expression operand) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { ! jsVariantHelper.isTypeAware(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
RuleFailedException previousFailure = null;
try {
boolean _isTypeAware = this.jsVariantHelper.isTypeAware(expr);
boolean _not = (!_isTypeAware);
/* ! jsVariantHelper.isTypeAware(expr) */
if (!_not) {
sneakyThrowRuleFailedException("! jsVariantHelper.isTypeAware(expr)");
}
Expression _lhs = expr.getLhs();
boolean _tripleEquals = (operand == _lhs);
if (_tripleEquals) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
T = RuleEnvironmentExtensions.topTypeRef(G);
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { DestructureUtils.isTopOfDestructuringAssignment(expr) if (operand===expr.lhs) { T = G.bottomTypeRef } else { T = G.topTypeRef } } or { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
boolean _isTopOfDestructuringAssignment = DestructureUtils.isTopOfDestructuringAssignment(expr);
/* DestructureUtils.isTopOfDestructuringAssignment(expr) */
if (!_isTopOfDestructuringAssignment) {
sneakyThrowRuleFailedException("DestructureUtils.isTopOfDestructuringAssignment(expr)");
}
Expression _lhs_1 = expr.getLhs();
boolean _tripleEquals_1 = (operand == _lhs_1);
if (_tripleEquals_1) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
T = RuleEnvironmentExtensions.topTypeRef(G);
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
/* { expr.op===AssignmentOperator.ASSIGN; if (operand===expr.lhs) { T = G.bottomTypeRef } else { G |- expr.lhs : T } } or { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op = expr.getOp();
boolean _tripleEquals_2 = (_op == AssignmentOperator.ASSIGN);
/* expr.op===AssignmentOperator.ASSIGN */
if (!_tripleEquals_2) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
}
Expression _lhs_2 = expr.getLhs();
boolean _tripleEquals_3 = (operand == _lhs_2);
if (_tripleEquals_3) {
T = RuleEnvironmentExtensions.bottomTypeRef(G);
} else {
/* G |- expr.lhs : T */
Expression _lhs_3 = expr.getLhs();
Result<TypeRef> result = typeInternal(G, _trace_, _lhs_3);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
}
} catch (Exception e_2) {
previousFailure = extractRuleFailedException(e_2);
/* { expr.op===AssignmentOperator.ADD_ASSIGN if (operand===expr.lhs) { T = TypeUtils.createNonSimplifiedIntersectionType(G.numberTypeRef, G.stringTypeRef); } else { G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef if (lhsTypeRef.declaredType === G.stringType) { T = G.anyTypeRef } else if(G.isNumeric(lhsTypeRef.declaredType)) { T = G.numberTypeRef } else { T = G.anyTypeRef } } } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op_1 = expr.getOp();
boolean _tripleEquals_4 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
/* expr.op===AssignmentOperator.ADD_ASSIGN */
if (!_tripleEquals_4) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
}
Expression _lhs_4 = expr.getLhs();
boolean _tripleEquals_5 = (operand == _lhs_4);
if (_tripleEquals_5) {
T = TypeUtils.createNonSimplifiedIntersectionType(RuleEnvironmentExtensions.numberTypeRef(G), RuleEnvironmentExtensions.stringTypeRef(G));
} else {
/* G |- expr.lhs : var ParameterizedTypeRef lhsTypeRef */
Expression _lhs_5 = expr.getLhs();
ParameterizedTypeRef lhsTypeRef = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs_5);
checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
lhsTypeRef = (ParameterizedTypeRef) result_1.getFirst();
Type _declaredType = lhsTypeRef.getDeclaredType();
PrimitiveType _stringType = RuleEnvironmentExtensions.stringType(G);
boolean _tripleEquals_6 = (_declaredType == _stringType);
if (_tripleEquals_6) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
boolean _isNumeric = RuleEnvironmentExtensions.isNumeric(G, lhsTypeRef.getDeclaredType());
if (_isNumeric) {
T = RuleEnvironmentExtensions.numberTypeRef(G);
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
}
} catch (Exception e_3) {
previousFailure = extractRuleFailedException(e_3);
T = RuleEnvironmentExtensions.numberTypeRef(G);
}
}
}
}
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleSubtypeBoundThisTypeRef.
protected Result<Boolean> applyRuleSubtypeBoundThisTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final BoundThisTypeRef left, final BoundThisTypeRef right) throws RuleFailedException {
boolean _isUseSiteStructuralTyping = right.isUseSiteStructuralTyping();
if (_isUseSiteStructuralTyping) {
final StructuralTypingResult result = this.typeSystemHelper.isStructuralSubtype(G, left, right);
boolean _isValue = result.isValue();
boolean _not = (!_isValue);
if (_not) {
/* fail error result.message data PRIORITY_ERROR */
String _message = result.getMessage();
String error = _message;
Object data = TypeSystemErrorExtensions.PRIORITY_ERROR;
throwForExplicitFail(error, new ErrorInformation(null, null, data));
}
} else {
boolean _isUseSiteStructuralTyping_1 = left.isUseSiteStructuralTyping();
boolean _isUseSiteStructuralTyping_2 = right.isUseSiteStructuralTyping();
boolean _tripleEquals = (Boolean.valueOf(_isUseSiteStructuralTyping_1) == Boolean.valueOf(_isUseSiteStructuralTyping_2));
/* left.useSiteStructuralTyping === right.useSiteStructuralTyping */
if (!_tripleEquals) {
sneakyThrowRuleFailedException("left.useSiteStructuralTyping === right.useSiteStructuralTyping");
}
/* G |- left.actualThisTypeRef <: right.actualThisTypeRef */
ParameterizedTypeRef _actualThisTypeRef = left.getActualThisTypeRef();
ParameterizedTypeRef _actualThisTypeRef_1 = right.getActualThisTypeRef();
subtypeInternal(G, _trace_, _actualThisTypeRef, _actualThisTypeRef_1);
}
return new Result<Boolean>(true);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeAssignmentExpression.
protected Result<TypeRef> applyRuleTypeAssignmentExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AssignmentExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { expr.op===AssignmentOperator.ASSIGN; G |- expr.rhs: T } or { expr.op===AssignmentOperator.ADD_ASSIGN G |- expr.lhs: var ParameterizedTypeRef l G |- expr.rhs: var ParameterizedTypeRef r val lnum = l.declaredType == G.booleanType || G.isNumeric(l.declaredType); val rnum = r.declaredType == G.booleanType || G.isNumeric(r.declaredType); val undef = l.declaredType == G.undefinedType || l.declaredType == G.nullType || r.declaredType == G.undefinedType || r.declaredType == G.nullType; !(lnum && rnum); !(undef && (lnum || rnum)); T = G.stringTypeRef } or { T = G.numberTypeRef } */
{
RuleFailedException previousFailure = null;
try {
AssignmentOperator _op = expr.getOp();
boolean _tripleEquals = (_op == AssignmentOperator.ASSIGN);
/* expr.op===AssignmentOperator.ASSIGN */
if (!_tripleEquals) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ASSIGN");
}
/* G |- expr.rhs: T */
Expression _rhs = expr.getRhs();
Result<TypeRef> result = typeInternal(G, _trace_, _rhs);
checkAssignableTo(result.getFirst(), TypeRef.class);
T = (TypeRef) result.getFirst();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { expr.op===AssignmentOperator.ADD_ASSIGN G |- expr.lhs: var ParameterizedTypeRef l G |- expr.rhs: var ParameterizedTypeRef r val lnum = l.declaredType == G.booleanType || G.isNumeric(l.declaredType); val rnum = r.declaredType == G.booleanType || G.isNumeric(r.declaredType); val undef = l.declaredType == G.undefinedType || l.declaredType == G.nullType || r.declaredType == G.undefinedType || r.declaredType == G.nullType; !(lnum && rnum); !(undef && (lnum || rnum)); T = G.stringTypeRef } or { T = G.numberTypeRef } */
{
try {
AssignmentOperator _op_1 = expr.getOp();
boolean _tripleEquals_1 = (_op_1 == AssignmentOperator.ADD_ASSIGN);
/* expr.op===AssignmentOperator.ADD_ASSIGN */
if (!_tripleEquals_1) {
sneakyThrowRuleFailedException("expr.op===AssignmentOperator.ADD_ASSIGN");
}
/* G |- expr.lhs: var ParameterizedTypeRef l */
Expression _lhs = expr.getLhs();
ParameterizedTypeRef l = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _lhs);
checkAssignableTo(result_1.getFirst(), ParameterizedTypeRef.class);
l = (ParameterizedTypeRef) result_1.getFirst();
/* G |- expr.rhs: var ParameterizedTypeRef r */
Expression _rhs_1 = expr.getRhs();
ParameterizedTypeRef r = null;
Result<TypeRef> result_2 = typeInternal(G, _trace_, _rhs_1);
checkAssignableTo(result_2.getFirst(), ParameterizedTypeRef.class);
r = (ParameterizedTypeRef) result_2.getFirst();
final boolean lnum = (Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.booleanType(G)) || RuleEnvironmentExtensions.isNumeric(G, l.getDeclaredType()));
final boolean rnum = (Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.booleanType(G)) || RuleEnvironmentExtensions.isNumeric(G, r.getDeclaredType()));
final boolean undef = (((Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.undefinedType(G)) || Objects.equal(l.getDeclaredType(), RuleEnvironmentExtensions.nullType(G))) || Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.undefinedType(G))) || Objects.equal(r.getDeclaredType(), RuleEnvironmentExtensions.nullType(G)));
/* !(lnum && rnum) */
if (!(!(lnum && rnum))) {
sneakyThrowRuleFailedException("!(lnum && rnum)");
}
/* !(undef && (lnum || rnum)) */
if (!(!(undef && (lnum || rnum)))) {
sneakyThrowRuleFailedException("!(undef && (lnum || rnum))");
}
T = RuleEnvironmentExtensions.stringTypeRef(G);
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
T = RuleEnvironmentExtensions.numberTypeRef(G);
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeSuperLiteral.
protected Result<TypeRef> applyRuleTypeSuperLiteral(final RuleEnvironment G, final RuleApplicationTrace _trace_, final SuperLiteral superLiteral) throws RuleFailedException {
// output parameter
TypeRef T = null;
final N4MemberDeclaration containingMemberDecl = EcoreUtil2.<N4MemberDeclaration>getContainerOfType(superLiteral.eContainer(), N4MemberDeclaration.class);
/* if (containingMemberDecl === null) { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } else { val containingClass = (containingMemberDecl.eContainer as N4ClassDeclaration).definedType as TClass; val superClass = G.getDeclaredOrImplicitSuperType(containingClass) var effectiveSuperClass = superClass if( containingClass.isStaticPolyfill ) { effectiveSuperClass = G.getDeclaredOrImplicitSuperType( superClass as TClass ) } { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } } or { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } */
{
RuleFailedException previousFailure = null;
try {
if ((containingMemberDecl == null)) {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} else {
EObject _eContainer = containingMemberDecl.eContainer();
Type _definedType = ((N4ClassDeclaration) _eContainer).getDefinedType();
final TClass containingClass = ((TClass) _definedType);
final TClassifier superClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, containingClass);
TClassifier effectiveSuperClass = superClass;
boolean _isStaticPolyfill = containingClass.isStaticPolyfill();
if (_isStaticPolyfill) {
effectiveSuperClass = RuleEnvironmentExtensions.getDeclaredOrImplicitSuperType(G, ((TClass) superClass));
}
/* { superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression if(containingMemberDecl.static) T = effectiveSuperClass?.createConstructorTypeRef else T = effectiveSuperClass?.createTypeRef if (T !== null) T = TypeUtils.enforceNominalTyping(T) } or { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
/* superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression */
if (!((superLiteral.eContainer() instanceof ParameterizedPropertyAccessExpression) || (superLiteral.eContainer() instanceof IndexedAccessExpression))) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedPropertyAccessExpression || superLiteral.eContainer instanceof IndexedAccessExpression");
}
boolean _isStatic = containingMemberDecl.isStatic();
if (_isStatic) {
TypeRef _createConstructorTypeRef = null;
if (effectiveSuperClass != null) {
_createConstructorTypeRef = TypeUtils.createConstructorTypeRef(effectiveSuperClass);
}
T = _createConstructorTypeRef;
} else {
ParameterizedTypeRef _createTypeRef = null;
if (effectiveSuperClass != null) {
_createTypeRef = TypeUtils.createTypeRef(effectiveSuperClass);
}
T = _createTypeRef;
}
if ((T != null)) {
T = TypeUtils.enforceNominalTyping(T);
}
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { superLiteral.eContainer instanceof ParameterizedCallExpression if(containingMemberDecl instanceof N4MethodDeclaration && containingMemberDecl.name == 'constructor') { val ctor = containerTypesHelper.fromContext(superLiteral.eResource).findConstructor(effectiveSuperClass); T = ctor?.createTypeRef } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } or { superLiteral.eContainer instanceof NewExpression } */
{
try {
EObject _eContainer_1 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof ParameterizedCallExpression */
if (!(_eContainer_1 instanceof ParameterizedCallExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof ParameterizedCallExpression");
}
if (((containingMemberDecl instanceof N4MethodDeclaration) && Objects.equal(containingMemberDecl.getName(), "constructor"))) {
final TMethod ctor = this.containerTypesHelper.fromContext(superLiteral.eResource()).findConstructor(effectiveSuperClass);
ParameterizedTypeRef _createTypeRef_1 = null;
if (ctor != null) {
_createTypeRef_1 = TypeUtils.createTypeRef(ctor);
}
T = _createTypeRef_1;
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
EObject _eContainer_2 = superLiteral.eContainer();
/* superLiteral.eContainer instanceof NewExpression */
if (!(_eContainer_2 instanceof NewExpression)) {
sneakyThrowRuleFailedException("superLiteral.eContainer instanceof NewExpression");
}
}
}
}
}
}
} catch (Exception e_2) {
previousFailure = extractRuleFailedException(e_2);
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
return new Result<TypeRef>(T);
}
Aggregations