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 NewTarget nt) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeNewTarget(G, _subtrace_, nt);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeNewTarget") + stringRepForEnv(G) + " |- " + stringRep(nt) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeNewTarget) {
typeThrowException(ruleName("typeNewTarget") + stringRepForEnv(G) + " |- " + stringRep(nt) + " : " + "TypeRef", TYPENEWTARGET, e_applyRuleTypeNewTarget, nt, new ErrorInformation[] { new ErrorInformation(nt) });
return null;
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method substTypeVariablesImpl.
protected Result<TypeArgument> substTypeVariablesImpl(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeArgument type) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeArgument> _result_ = applyRuleSubstTypeVariablesBaseCase(G, _subtrace_, type);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("substTypeVariablesBaseCase") + stringRepForEnv(G) + " |- " + stringRep(type) + " ~> " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleSubstTypeVariablesBaseCase) {
substTypeVariablesThrowException(ruleName("substTypeVariablesBaseCase") + stringRepForEnv(G) + " |- " + stringRep(type) + " ~> " + "TypeArgument", SUBSTTYPEVARIABLESBASECASE, e_applyRuleSubstTypeVariablesBaseCase, type, new ErrorInformation[] { new ErrorInformation(type) });
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 ModuleNamespaceVirtualType t) throws RuleFailedException {
try {
final RuleApplicationTrace _subtrace_ = newTrace(_trace_);
final Result<TypeRef> _result_ = applyRuleTypeModuleNamespace(G, _subtrace_, t);
addToTrace(_trace_, new Provider<Object>() {
public Object get() {
return ruleName("typeModuleNamespace") + stringRepForEnv(G) + " |- " + stringRep(t) + " : " + stringRep(_result_.getFirst());
}
});
addAsSubtrace(_trace_, _subtrace_);
return _result_;
} catch (Exception e_applyRuleTypeModuleNamespace) {
typeThrowException(ruleName("typeModuleNamespace") + stringRepForEnv(G) + " |- " + stringRep(t) + " : " + "TypeRef", TYPEMODULENAMESPACE, e_applyRuleTypeModuleNamespace, t, new ErrorInformation[] { new ErrorInformation(t) });
return null;
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class N4JSValidatorErrorGenerator method generateErrors.
/**
* Copied from super class to create error messages from RuleFailedExceptions via method
* {@link TypeSystemErrorExtensions#compileMessage(RuleFailedException)}.
*/
@Override
protected void generateErrors(ValidationMessageAcceptor validationMessageAcceptor, RuleFailedException ruleFailedException, EObject originalSource) {
if (ruleFailedException == null) {
return;
}
Iterable<RuleFailedException> allFailures = filter.filterRuleFailedExceptions(ruleFailedException);
// the last information about a model element with error
ErrorInformation lastErrorInformationWithSource = null;
// an associated model element
for (RuleFailedException ruleFailedException2 : allFailures) {
lastErrorInformationWithSource = generateErrors(validationMessageAcceptor, // only change w.r.t. super-class method:
TypeSystemErrorExtensions.compileMessage(ruleFailedException2), // ================================================================
ruleFailedException2.getIssue(), filter.filterErrorInformation(ruleFailedException2), lastErrorInformationWithSource, originalSource);
}
}
use of org.eclipse.xsemantics.runtime.RuleFailedException in project n4js by eclipse.
the class InternalTypeSystem method applyRuleTypeCallExpression.
protected Result<TypeRef> applyRuleTypeCallExpression(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedCallExpression expr) throws RuleFailedException {
// output parameter
TypeRef T = null;
/* G |- expr.target : var TypeRef targetTypeRef */
Expression _target = expr.getTarget();
TypeRef targetTypeRef = null;
Result<TypeRef> result = typeInternal(G, _trace_, _target);
checkAssignableTo(result.getFirst(), TypeRef.class);
targetTypeRef = (TypeRef) result.getFirst();
if ((targetTypeRef instanceof FunctionTypeExprOrRef)) {
final FunctionTypeExprOrRef F = ((FunctionTypeExprOrRef) targetTypeRef);
final TFunction tFunction = F.getFunctionType();
/* { val inferring = env(G, GUARD_TYPE_CALL_EXPRESSION -> expr, TypeRef) G |- inferring ~> T } or { val G2 = G.wrap; G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) if(expr.eContainer instanceof AwaitExpression && expr.eContainmentFeature === N4JSPackage.eINSTANCE.getAwaitExpression_Expression() && tFunction!==null && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction)) { T = promisifyHelper.extractPromisifiedReturnType(expr); } else { T = F.returnTypeRef ?: G.anyTypeRef; } typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef); G2 |- T ~> T T = versionResolver.resolveVersion(T, F); if (T instanceof BoundThisTypeRef && !(expr.receiver instanceof ThisLiteral || expr.receiver instanceof SuperLiteral)) { G2 |~ T /\ T } } */
{
RuleFailedException previousFailure = null;
try {
Pair<String, ParameterizedCallExpression> _mappedTo = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
final TypeRef inferring = this.<TypeRef>env(G, _mappedTo, TypeRef.class);
/* G |- inferring ~> T */
Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, inferring);
checkAssignableTo(result_1.getFirst(), TypeRef.class);
T = (TypeRef) result_1.getFirst();
} catch (Exception e) {
previousFailure = extractRuleFailedException(e);
final RuleEnvironment G2 = RuleEnvironmentExtensions.wrap(G);
Pair<String, ParameterizedCallExpression> _mappedTo_1 = Pair.<String, ParameterizedCallExpression>of(RuleEnvironmentExtensions.GUARD_TYPE_CALL_EXPRESSION, expr);
boolean _add = G2.add(_mappedTo_1, F.getReturnTypeRef());
/* G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef) */
if (!_add) {
sneakyThrowRuleFailedException("G2.add(GUARD_TYPE_CALL_EXPRESSION -> expr, F.returnTypeRef)");
}
if (((((expr.eContainer() instanceof AwaitExpression) && (expr.eContainmentFeature() == N4JSPackage.eINSTANCE.getAwaitExpression_Expression())) && (tFunction != null)) && AnnotationDefinition.PROMISIFIABLE.hasAnnotation(tFunction))) {
T = this.promisifyHelper.extractPromisifiedReturnType(expr);
} else {
TypeRef _elvis = null;
TypeRef _returnTypeRef = F.getReturnTypeRef();
if (_returnTypeRef != null) {
_elvis = _returnTypeRef;
} else {
ParameterizedTypeRef _anyTypeRef = RuleEnvironmentExtensions.anyTypeRef(G);
_elvis = _anyTypeRef;
}
T = _elvis;
}
this.typeSystemHelper.addSubstitutions(G2, expr, targetTypeRef);
/* G2 |- T ~> T */
Result<TypeArgument> result_2 = substTypeVariablesInternal(G2, _trace_, T);
checkAssignableTo(result_2.getFirst(), TypeRef.class);
T = (TypeRef) result_2.getFirst();
T = this.versionResolver.<TypeRef, FunctionTypeExprOrRef>resolveVersion(T, F);
if (((T instanceof BoundThisTypeRef) && (!((expr.getReceiver() instanceof ThisLiteral) || (expr.getReceiver() instanceof SuperLiteral))))) {
/* G2 |~ T /\ T */
Result<TypeRef> result_3 = upperBoundInternal(G2, _trace_, T);
checkAssignableTo(result_3.getFirst(), TypeRef.class);
T = (TypeRef) result_3.getFirst();
}
}
}
} else {
Type _declaredType = null;
if (targetTypeRef != null) {
_declaredType = targetTypeRef.getDeclaredType();
}
TObjectPrototype _functionType = RuleEnvironmentExtensions.functionType(G);
boolean _tripleEquals = (_declaredType == _functionType);
if (_tripleEquals) {
T = RuleEnvironmentExtensions.anyTypeRef(G);
} else {
boolean _isDynamic = targetTypeRef.isDynamic();
if (_isDynamic) {
T = RuleEnvironmentExtensions.anyTypeRefDynamic(G);
} else {
T = TypeRefsFactory.eINSTANCE.createUnknownTypeRef();
}
}
}
return new Result<TypeRef>(T);
}
Aggregations