Search in sources :

Example 1 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class ExpressionsTypeInferrer method validateParameters.

/**
 * Takes the operation parameter type and performs a lookup for all contained
 * type parameters by using the given type parameter inference map.<br>
 * The parameter types are validated against the operation call's argument
 * types.
 *
 * @throws TypeParameterInferrenceException
 */
public Map<TypeParameter, InferenceResult> validateParameters(Map<TypeParameter, InferenceResult> typeParameterMapping, Operation operation, List<Expression> args, IValidationIssueAcceptor acceptor) {
    List<Parameter> parameters = operation.getParameters();
    for (int i = 0; i < parameters.size(); i++) {
        if (args.size() > i) {
            Parameter parameter = parameters.get(i);
            Expression argument = args.get(i);
            InferenceResult parameterType = inferTypeDispatch(parameter);
            InferenceResult argumentType = inferTypeDispatch(argument);
            parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
            assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
        }
    }
    if (operation.isVariadic() && args.size() - 1 >= operation.getVarArgIndex()) {
        Parameter parameter = operation.getParameters().get(operation.getVarArgIndex());
        List<Expression> varArgs = args.subList(operation.getVarArgIndex(), args.size() - 1);
        InferenceResult parameterType = inferTypeDispatch(parameter);
        for (Expression expression : varArgs) {
            parameterType = typeParameterInferrer.buildInferenceResult(parameterType, typeParameterMapping, acceptor);
            InferenceResult argumentType = inferTypeDispatch(expression);
            assertAssignable(parameterType, argumentType, String.format(INCOMPATIBLE_TYPES, argumentType, parameterType));
        }
    }
    return typeParameterMapping;
}
Also used : ConditionalExpression(org.yakindu.base.expressions.expressions.ConditionalExpression) LogicalRelationExpression(org.yakindu.base.expressions.expressions.LogicalRelationExpression) LogicalAndExpression(org.yakindu.base.expressions.expressions.LogicalAndExpression) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) LogicalOrExpression(org.yakindu.base.expressions.expressions.LogicalOrExpression) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ShiftExpression(org.yakindu.base.expressions.expressions.ShiftExpression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) PostFixUnaryExpression(org.yakindu.base.expressions.expressions.PostFixUnaryExpression) BitwiseAndExpression(org.yakindu.base.expressions.expressions.BitwiseAndExpression) BitwiseXorExpression(org.yakindu.base.expressions.expressions.BitwiseXorExpression) TypeCastExpression(org.yakindu.base.expressions.expressions.TypeCastExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) NumericalAddSubtractExpression(org.yakindu.base.expressions.expressions.NumericalAddSubtractExpression) LogicalNotExpression(org.yakindu.base.expressions.expressions.LogicalNotExpression) NumericalUnaryExpression(org.yakindu.base.expressions.expressions.NumericalUnaryExpression) PrimitiveValueExpression(org.yakindu.base.expressions.expressions.PrimitiveValueExpression) BitwiseOrExpression(org.yakindu.base.expressions.expressions.BitwiseOrExpression) Parameter(org.yakindu.base.types.Parameter) TypeParameter(org.yakindu.base.types.TypeParameter)

Example 2 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class TypeCastExpressionImpl method basicSetOperand.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetOperand(Expression newOperand, NotificationChain msgs) {
    Expression oldOperand = operand;
    operand = newOperand;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ExpressionsPackage.TYPE_CAST_EXPRESSION__OPERAND, oldOperand, newOperand);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TypeCastExpression(org.yakindu.base.expressions.expressions.TypeCastExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class OperationOverloadingResolver method isCallable.

protected boolean isCallable(Operation operation, ArgumentExpression expression) {
    EList<Expression> orderedExpressions = ArgumentSorter.getOrderedExpressions(expression.getArguments(), operation);
    List<Type> argumentTypes = orderedExpressions.stream().map(it -> inferrer.infer(it).getType()).filter(t -> t != null).collect(Collectors.toList());
    List<Type> parameterTypes = operation.getParameters().stream().map(it -> it.getType()).collect(Collectors.toList());
    if (argumentTypes.size() != parameterTypes.size())
        return false;
    for (int i = 0; i < argumentTypes.size(); i++) {
        Type type1 = argumentTypes.get(i);
        Type type2 = parameterTypes.get(i);
        if (!typeSystem.isSuperType(type2, type1))
            return false;
    }
    return true;
}
Also used : ArgumentSorter(org.yakindu.base.expressions.expressions.util.ArgumentSorter) ITypeSystem(org.yakindu.base.types.typesystem.ITypeSystem) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) Inject(com.google.inject.Inject) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) Parameter(org.yakindu.base.types.Parameter) List(java.util.List) ITypeSystemInferrer(org.yakindu.base.types.inferrer.ITypeSystemInferrer) TypesPackage(org.yakindu.base.types.TypesPackage) Operation(org.yakindu.base.types.Operation) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Type(org.yakindu.base.types.Type) Expression(org.yakindu.base.expressions.expressions.Expression) Type(org.yakindu.base.types.Type) ArgumentExpression(org.yakindu.base.expressions.expressions.ArgumentExpression) Expression(org.yakindu.base.expressions.expressions.Expression)

Example 4 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class ParenthesizedExpressionImpl method basicSetExpression.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetExpression(Expression newExpression, NotificationChain msgs) {
    Expression oldExpression = expression;
    expression = newExpression;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ExpressionsPackage.PARENTHESIZED_EXPRESSION__EXPRESSION, oldExpression, newExpression);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ParenthesizedExpression(org.yakindu.base.expressions.expressions.ParenthesizedExpression) Expression(org.yakindu.base.expressions.expressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 5 with Expression

use of org.yakindu.base.expressions.expressions.Expression in project statecharts by Yakindu.

the class ArgumentImpl method basicSetValue.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetValue(Expression newValue, NotificationChain msgs) {
    Expression oldValue = value;
    value = newValue;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ExpressionsPackage.ARGUMENT__VALUE, oldValue, newValue);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Aggregations

Expression (org.yakindu.base.expressions.expressions.Expression)48 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)24 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)11 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)10 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)9 EObject (org.eclipse.emf.ecore.EObject)7 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)6 PrimitiveValueExpression (org.yakindu.base.expressions.expressions.PrimitiveValueExpression)6 Effect (org.yakindu.sct.model.sgraph.Effect)6 ArrayList (java.util.ArrayList)5 ParenthesizedExpression (org.yakindu.base.expressions.expressions.ParenthesizedExpression)5 PostFixUnaryExpression (org.yakindu.base.expressions.expressions.PostFixUnaryExpression)5 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)5 Test (org.junit.Test)4 ConditionalExpression (org.yakindu.base.expressions.expressions.ConditionalExpression)4 LogicalAndExpression (org.yakindu.base.expressions.expressions.LogicalAndExpression)4 LogicalOrExpression (org.yakindu.base.expressions.expressions.LogicalOrExpression)4 NumericalMultiplyDivideExpression (org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression)4 Scope (org.yakindu.sct.model.sgraph.Scope)4 Transition (org.yakindu.sct.model.sgraph.Transition)4