use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Argument arg) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeArgument(G, _subtrace_, arg);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeArgument") + stringRepForEnv(G) + " |- " + stringRep(arg) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeArgument) {
typeThrowException(ruleName("typeArgument") + stringRepForEnv(G) + " |- " + stringRep(arg) + " : " + "TypeRef", TYPEARGUMENT, e_applyRuleTypeArgument, arg, new ErrorInformation[] { new ErrorInformation(arg) });
return null;
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final AwaitExpression e) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeAwaitExpression(G, _subtrace_, e);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeAwaitExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeAwaitExpression) {
typeThrowException(ruleName("typeAwaitExpression") + stringRepForEnv(G) + " |- " + stringRep(e) + " : " + "TypeRef", TYPEAWAITEXPRESSION, e_applyRuleTypeAwaitExpression, e, new ErrorInformation[] { new ErrorInformation(e) });
return null;
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method lowerBoundImpl.
protected Result<TypeRef> lowerBoundImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef ptr) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleLowerBoundParameterizedTypeRef(G, _subtrace_, ptr);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("lowerBoundParameterizedTypeRef") + stringRepForEnv(G) + " |~ " + stringRep(ptr) + " \\/ " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleLowerBoundParameterizedTypeRef) {
lowerBoundThrowException(ruleName("lowerBoundParameterizedTypeRef") + stringRepForEnv(G) + " |~ " + stringRep(ptr) + " \\/ " + "TypeRef", LOWERBOUNDPARAMETERIZEDTYPEREF, e_applyRuleLowerBoundParameterizedTypeRef, ptr, new ErrorInformation[] { new ErrorInformation(ptr) });
return null;
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeIndexedAccessExpression.
protected Result<TypeRef> applyRuleTypeIndexedAccessExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final IndexedAccessExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* { expr.target === null || expr.index === null; T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { expr.target instanceof SuperLiteral T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { G |- expr.target : var TypeRef targetTypeRef targetTypeRef = typeSystemHelper.resolveType(G, targetTypeRef); G |- expr.index : var TypeRef indexTypeRef; val targetDeclType = targetTypeRef.declaredType; val targetIsLiteralOfStringBasedEnum = targetDeclType instanceof TEnum && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType); val indexIsNumeric = { G |- indexTypeRef <: G.numberTypeRef }; val indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.index); val memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue); if (indexIsNumeric && (targetTypeRef.isArrayLike || targetIsLiteralOfStringBasedEnum)) { if (targetDeclType.generic && targetTypeRef.typeArgs.isEmpty) { T = G.anyTypeRef } else { val G2 = G.wrap typeSystemHelper.addSubstitutions(G2, targetTypeRef) G2.addThisType(targetTypeRef) val elementTypeRef = if(targetIsLiteralOfStringBasedEnum) { G.stringType.elementType } else { targetDeclType.elementType }; G2 |- elementTypeRef ~> T } } else if (memberName!==null) { val staticAccess = (targetTypeRef instanceof TypeTypeRef) val checkVisibility = false val scope = memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess) val memberDesc = if(memberName!==null && !memberName.isEmpty()) { scope.getSingleElement(qualifiedNameConverter.toQualifiedName(memberName)) }; val member = if(memberDesc!==null && !IEObjectDescriptionWithError.isErrorDescription(memberDesc)) { memberDesc.getEObjectOrProxy() }; if(member instanceof TMember && !member.eIsProxy) { G |- (member as TMember) : var TypeRef memberTypeRef val G2 = G.wrap typeSystemHelper.addSubstitutions(G2,targetTypeRef) G2.addThisType(targetTypeRef) G2 |- memberTypeRef ~> T } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = G.anyTypeRef } } */
{
RuleFailedException previousFailure = null;
try {
/* expr.target === null || expr.index === null */
if (!((expr.getTarget() == null) || (expr.getIndex() == null))) {
sneakyThrowRuleFailedException("expr.target === null || expr.index === null");
}
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
/* { expr.target instanceof SuperLiteral T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } or { G |- expr.target : var TypeRef targetTypeRef targetTypeRef = typeSystemHelper.resolveType(G, targetTypeRef); G |- expr.index : var TypeRef indexTypeRef; val targetDeclType = targetTypeRef.declaredType; val targetIsLiteralOfStringBasedEnum = targetDeclType instanceof TEnum && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType); val indexIsNumeric = { G |- indexTypeRef <: G.numberTypeRef }; val indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.index); val memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue); if (indexIsNumeric && (targetTypeRef.isArrayLike || targetIsLiteralOfStringBasedEnum)) { if (targetDeclType.generic && targetTypeRef.typeArgs.isEmpty) { T = G.anyTypeRef } else { val G2 = G.wrap typeSystemHelper.addSubstitutions(G2, targetTypeRef) G2.addThisType(targetTypeRef) val elementTypeRef = if(targetIsLiteralOfStringBasedEnum) { G.stringType.elementType } else { targetDeclType.elementType }; G2 |- elementTypeRef ~> T } } else if (memberName!==null) { val staticAccess = (targetTypeRef instanceof TypeTypeRef) val checkVisibility = false val scope = memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess) val memberDesc = if(memberName!==null && !memberName.isEmpty()) { scope.getSingleElement(qualifiedNameConverter.toQualifiedName(memberName)) }; val member = if(memberDesc!==null && !IEObjectDescriptionWithError.isErrorDescription(memberDesc)) { memberDesc.getEObjectOrProxy() }; if(member instanceof TMember && !member.eIsProxy) { G |- (member as TMember) : var TypeRef memberTypeRef val G2 = G.wrap typeSystemHelper.addSubstitutions(G2,targetTypeRef) G2.addThisType(targetTypeRef) G2 |- memberTypeRef ~> T } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef } } else if (targetTypeRef.dynamic) { T = G.anyTypeRefDynamic } else { T = G.anyTypeRef } } */
{
try {
Expression _target = expr.getTarget();
/* expr.target instanceof SuperLiteral */
if (!(_target instanceof SuperLiteral)) {
sneakyThrowRuleFailedException("expr.target instanceof SuperLiteral");
}
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
} catch (Exception e_1) {
previousFailure = extractRuleFailedException(e_1);
/* G |- expr.target : var TypeRef targetTypeRef */
Expression _target_1 = expr.getTarget();
TypeRef targetTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, _target_1);
checkAssignableTo(result.getFirst(), TypeRef.class);
targetTypeRef = (TypeRef) result.getFirst();
targetTypeRef = this.typeSystemHelper.resolveType(G, targetTypeRef);
/* G |- expr.index : var TypeRef indexTypeRef */
Expression _index = expr.getIndex();
TypeRef indexTypeRef = null;
Result<TypeRef> result_1 = typeInternal(G, _trace_, _index);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
indexTypeRef = (TypeRef) result_1.getFirst();
final Type targetDeclType = targetTypeRef.getDeclaredType();
final boolean targetIsLiteralOfStringBasedEnum = ((targetDeclType instanceof TEnum) && AnnotationDefinition.STRING_BASED.hasAnnotation(targetDeclType));
/* G |- indexTypeRef <: G.numberTypeRef */
ParameterizedTypeRef _numberTypeRef = RuleEnvironmentExtensions.numberTypeRef(G);
boolean _ruleinvocation = subtypeSucceeded(G, _trace_, indexTypeRef, _numberTypeRef);
final boolean indexIsNumeric = _ruleinvocation;
final CompileTimeValue indexValue = ASTMetaInfoUtils.getCompileTimeValue(expr.getIndex());
final String memberName = N4JSLanguageUtils.derivePropertyNameFromCompileTimeValue(indexValue);
if ((indexIsNumeric && (targetTypeRef.isArrayLike() || targetIsLiteralOfStringBasedEnum))) {
if ((targetDeclType.isGeneric() && targetTypeRef.getTypeArgs().isEmpty())) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
this.typeSystemHelper.addSubstitutions(G2, targetTypeRef);
RuleEnvironmentExtensions.addThisType(G2, targetTypeRef);
TypeRef _xifexpression = null;
if (targetIsLiteralOfStringBasedEnum) {
_xifexpression = RuleEnvironmentExtensions.stringType(G).getElementType();
} else {
_xifexpression = targetDeclType.getElementType();
}
final TypeRef elementTypeRef = _xifexpression;
/* G2 |- elementTypeRef ~> T */
Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, elementTypeRef);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
}
} else {
if ((memberName != null)) {
final boolean staticAccess = (targetTypeRef instanceof TypeTypeRef);
final boolean checkVisibility = false;
final IScope scope = this.memberScopingHelper.createMemberScope(targetTypeRef, expr, checkVisibility, staticAccess);
IEObjectDescription _xifexpression_1 = null;
if (((memberName != null) && (!memberName.isEmpty()))) {
_xifexpression_1 = scope.getSingleElement(this.qualifiedNameConverter.toQualifiedName(memberName));
}
final IEObjectDescription memberDesc = _xifexpression_1;
EObject _xifexpression_2 = null;
if (((memberDesc != null) && (!IEObjectDescriptionWithError.isErrorDescription(memberDesc)))) {
_xifexpression_2 = memberDesc.getEObjectOrProxy();
}
final EObject member = _xifexpression_2;
if (((member instanceof TMember) && (!member.eIsProxy()))) {
/* G |- (member as TMember) : var TypeRef memberTypeRef */
TypeRef memberTypeRef = null;
Result<TypeRef> result_3 = typeInternal(G, _trace_, ((TMember) member));
checkAssignableTo(result_3.getFirst(), TypeRef.class);
memberTypeRef = (TypeRef) result_3.getFirst();
final RuleEnvironment G2_1 = RuleEnvironmentExtensions.wrap(G);
this.typeSystemHelper.addSubstitutions(G2_1, targetTypeRef);
RuleEnvironmentExtensions.addThisType(G2_1, targetTypeRef);
/* G2 |- memberTypeRef ~> T */
Result<TypeArgument> result_4 = substTypeVariablesInternal(G2_1, _trace_, memberTypeRef);
checkAssignableTo(result_4.getFirst(), TypeRef.class);
T = (TypeRef) result_4.getFirst();
} else {
boolean _isDynamic = targetTypeRef.isDynamic();
if (_isDynamic) {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
} else {
boolean _isDynamic_1 = targetTypeRef.isDynamic();
if (_isDynamic_1) {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
T = RuleEnvironmentExtensions.anyTypeRef(G);
}
}
}
}
}
}
}
return new Result<TypeRef>(T);
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method typeImpl.
protected Result<TypeRef> typeImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TSetter tsetter) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeTSetter(G, _subtrace_, tsetter);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeTSetter") + stringRepForEnv(G) + " |- " + stringRep(tsetter) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeTSetter) {
typeThrowException(ruleName("typeTSetter") + stringRepForEnv(G) + " |- " + stringRep(tsetter) + " : " + "TypeRef", TYPETSETTER, e_applyRuleTypeTSetter, tsetter, new ErrorInformation[] { new ErrorInformation(tsetter) });
return null;
}
}
Aggregations