Search in sources :

Example 26 with Abstract

use of org.osate.aadl2.Abstract in project osate2 by osate.

the class Aadl2Validator method checkDirectionOfFeatureGroupMembers.

/**
 * Checks that direction of matching features in feature group are opposite or the same.
 * This method is useful when the feature group types of the source and destination are independently specified
 * We check that by checking whether the connection has SUBSET, EQUIVALNCE, CONVERSION
 */
private void checkDirectionOfFeatureGroupMembers(Connection connection) {
    if (!(connection.getAllLastSource() instanceof FeatureGroup) || !(connection.getAllLastDestination() instanceof FeatureGroup)) {
        return;
    }
    FeatureGroup source = (FeatureGroup) connection.getAllLastSource();
    FeatureGroup destination = (FeatureGroup) connection.getAllLastDestination();
    FeatureGroupType sourceType = source.getAllFeatureGroupType();
    FeatureGroupType destinationType = destination.getAllFeatureGroupType();
    if (sourceType == null || destinationType == null) {
        return;
    }
    Context srcContext = connection.getAllSourceContext();
    Context dstContext = connection.getAllDestinationContext();
    // connection across or through a component
    boolean isSibling = (srcContext instanceof Subcomponent && dstContext instanceof Subcomponent);
    final ClassifierMatchingRule classifierMatchingRuleValue = org.osate.aadl2.contrib.modeling.ModelingProperties.getClassifierMatchingRule(connection).orElse(ClassifierMatchingRule.CLASSIFIER_MATCH);
    if (classifierMatchingRuleValue == ClassifierMatchingRule.EQUIVALENCE || classifierMatchingRuleValue == ClassifierMatchingRule.CONVERSION || classifierMatchingRuleValue == ClassifierMatchingRule.SUBSET) {
        EList<Feature> srcFeatures = sourceType.getAllFeatures();
        EList<Feature> dstFeatures = destinationType.getAllFeatures();
        if (srcFeatures.isEmpty() || dstFeatures.isEmpty()) {
            return;
        }
        for (Feature destinationFeature : dstFeatures) {
            if (destinationFeature instanceof DirectedFeature && !((DirectedFeature) destinationFeature).getDirection().equals(DirectionType.IN_OUT)) {
                DirectionType destinationDirection = ((DirectedFeature) destinationFeature).getDirection();
                List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
                destinationChain.add(destinationFeature);
                if (isInvertNeeded(destinationChain)) {
                    destinationDirection = destinationDirection.getInverseDirection();
                }
                for (Feature sourceFeature : srcFeatures) {
                    if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
                        if (sourceFeature instanceof DirectedFeature && !((DirectedFeature) sourceFeature).getDirection().equals(DirectionType.IN_OUT)) {
                            DirectionType sourceDirection = ((DirectedFeature) sourceFeature).getDirection();
                            List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
                            sourceChain.add(sourceFeature);
                            if (isInvertNeeded(sourceChain)) {
                                sourceDirection = sourceDirection.getInverseDirection();
                            }
                            // check for opposite or matching direction
                            if (isSibling) {
                                // opposite direction
                                if (sourceDirection == destinationDirection) {
                                    error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
                                }
                            } else {
                                // matching direction
                                if (sourceDirection != destinationDirection) {
                                    error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
                                }
                            }
                        } else {
                            // source not a directional feature while destination is
                            if (!(destinationFeature instanceof AbstractFeature && destinationDirection == DirectionType.IN_OUT && sourceFeature instanceof Access)) {
                                error(connection, "The source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group directional feature '" + destination.getName() + "." + destinationFeature.getName());
                            }
                        }
                    }
                }
            } else if (destinationFeature instanceof Access) {
                AccessType destinationDirection = ((Access) destinationFeature).getKind();
                List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
                destinationChain.add(destinationFeature);
                if (isInvertNeeded(destinationChain)) {
                    destinationDirection = destinationDirection.getInverseType();
                }
                for (Feature sourceFeature : srcFeatures) {
                    if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
                        if (sourceFeature instanceof Access) {
                            AccessType sourceDirection = ((Access) sourceFeature).getKind();
                            List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
                            sourceChain.add(sourceFeature);
                            if (isInvertNeeded(sourceChain)) {
                                sourceDirection = sourceDirection.getInverseType();
                            }
                            // check for opposite or matching direction
                            if (isSibling) {
                                // opposite direction
                                if (sourceDirection == destinationDirection) {
                                    error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
                                }
                            } else {
                                // matching direction
                                if (sourceDirection != destinationDirection) {
                                    error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
                                }
                            }
                        } else {
                            // destination not a directional feature while is. Must be an abstract to be ok
                            if (!(sourceFeature instanceof AbstractFeature && ((AbstractFeature) sourceFeature).getDirection() == DirectionType.IN_OUT)) {
                                error(connection, "The source feature group directional feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Aadl2GrammarAccess(org.osate.xtext.aadl2.services.Aadl2GrammarAccess) ClassifierMatchingRule(org.osate.aadl2.contrib.modeling.ClassifierMatchingRule) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) BasicInternalEList(org.eclipse.emf.ecore.util.BasicInternalEList) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList)

Example 27 with Abstract

use of org.osate.aadl2.Abstract in project osate2 by osate.

the class SetFeatureClassifierPropertySection method setFeatureClassifier.

private static void setFeatureClassifier(final NamedElement feature, final Object classifier) {
    if (classifier != null) {
        // Import its package if necessary
        final AadlPackage pkg = (AadlPackage) feature.getElementRoot();
        if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
            final PackageSection section = pkg.getPublicSection();
            final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
            if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
                AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
            }
        }
        // If the feature is an abstract feature, need to reset the feature prototype. Only a prototype or a classifier may be set.
        if (feature instanceof AbstractFeature) {
            ((AbstractFeature) feature).setFeaturePrototype(null);
        }
    }
    final FeatureClassifierMetadata setterInfo = featureTypeToMetadataMap.get(feature.eClass());
    try {
        final Method method = feature.getClass().getMethod(setterInfo.setterName, setterInfo.classifierClass);
        method.invoke(feature, classifier);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) AbstractFeature(org.osate.aadl2.AbstractFeature) AbstractFeatureClassifier(org.osate.aadl2.AbstractFeatureClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) BusFeatureClassifier(org.osate.aadl2.BusFeatureClassifier) FeatureClassifier(org.osate.aadl2.FeatureClassifier) DataClassifier(org.osate.aadl2.DataClassifier) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 28 with Abstract

use of org.osate.aadl2.Abstract in project AGREE by loonwerks.

the class AgreeASTBuilder method gatherUnspecifiedAadlProperties.

private void gatherUnspecifiedAadlProperties(Map<String, GetPropertyExpr> unspecifiedAadlProperties, List<AgreeVar> inputs, List<AgreeStatement> assumptions, List<AgreeStatement> guarantees) {
    for (Entry<String, GetPropertyExpr> entry : unspecifiedAadlProperties.entrySet()) {
        String propInputName = entry.getKey();
        GetPropertyExpr expr = entry.getValue();
        Property prop = (Property) expr.getProp();
        Expr propInputIdExpr = new IdExpr(propInputName);
        Type type;
        Expr bound = null;
        if (prop.getReferencedPropertyType() instanceof AadlBoolean) {
            type = NamedType.BOOL;
        } else if (prop.getReferencedPropertyType() instanceof AadlInteger) {
            AadlInteger aadlInteger = (AadlInteger) prop.getReferencedPropertyType();
            type = NamedType.INT;
            if (aadlInteger.getRange() != null) {
                PropertyExpression lowerBound = aadlInteger.getRange().getLowerBound();
                PropertyExpression upperBound = aadlInteger.getRange().getUpperBound();
                Expr lowVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) lowerBound).getScaledValue()).toBigInteger());
                Expr highVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) upperBound).getScaledValue()).toBigInteger());
                Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
                Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
                bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
            }
        } else if (prop.getReferencedPropertyType() instanceof AadlReal) {
            AadlReal aadlReal = (AadlReal) prop.getReferencedPropertyType();
            type = NamedType.REAL;
            if (aadlReal.getRange() != null) {
                PropertyExpression lowerBound = aadlReal.getRange().getLowerBound();
                PropertyExpression upperBound = aadlReal.getRange().getUpperBound();
                Expr lowVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) lowerBound).getValue()));
                Expr highVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) upperBound).getValue()));
                Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
                Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
                bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
            }
        } else {
            throw new AgreeException("Could not locate property value '\" + prop.getFullName() + \"' in component '\"\n" + "//						+ compName.getName() + \"'.   Analysis on abstract values not supported for " + "AADL property type " + prop.getReferencedPropertyType() + ".");
        }
        AgreeVar propInputVar = new AgreeVar(propInputName, type, expr, curInst, null);
        Expr constraint = getUnchangingConstraintExpr(propInputIdExpr);
        if (bound != null) {
            constraint = LustreExprFactory.makeANDExpr(constraint, bound);
        }
        inputs.add(propInputVar);
        assumptions.add(new AgreeStatement("", constraint, prop));
    }
}
Also used : AadlReal(org.osate.aadl2.AadlReal) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealLiteral(org.osate.aadl2.RealLiteral) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) AadlBoolean(org.osate.aadl2.AadlBoolean) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) PropertyExpression(org.osate.aadl2.PropertyExpression) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AadlInteger(org.osate.aadl2.AadlInteger) IntExpr(jkind.lustre.IntExpr) Property(org.osate.aadl2.Property) RealExpr(jkind.lustre.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Aggregations

Classifier (org.osate.aadl2.Classifier)8 Element (org.osate.aadl2.Element)8 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)7 ArrayList (java.util.ArrayList)6 ComponentImplementation (org.osate.aadl2.ComponentImplementation)6 Property (org.osate.aadl2.Property)6 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)6 BasicEList (org.eclipse.emf.common.util.BasicEList)5 ComponentCategory (org.osate.aadl2.ComponentCategory)5 NamedElement (org.osate.aadl2.NamedElement)5 AbstractImplementation (org.osate.aadl2.AbstractImplementation)4 AbstractType (org.osate.aadl2.AbstractType)4 HashSet (java.util.HashSet)3 EList (org.eclipse.emf.common.util.EList)3 EObject (org.eclipse.emf.ecore.EObject)3 Aadl2Package (org.osate.aadl2.Aadl2Package)3 AbstractFeature (org.osate.aadl2.AbstractFeature)3 BusImplementation (org.osate.aadl2.BusImplementation)3 BusType (org.osate.aadl2.BusType)3 ComponentClassifier (org.osate.aadl2.ComponentClassifier)3