Search in sources :

Example 16 with NamedElement

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

the class AgreeValidator method checkNamedElement.

@Check(CheckType.FAST)
public void checkNamedElement(NamedElement namedEl) {
    // check for namespace collision in component types of component
    // implementations
    // and for collisions between subcomponent and feature names
    EObject container = namedEl.eContainer();
    if (container == null) {
        return;
    }
    if (container instanceof RecordDef || container instanceof NodeDef) {
        // TODO: perhaps we can ignore all arguments?
        return;
    }
    while (!(container instanceof AadlPackage || container instanceof ComponentImplementation || container instanceof ComponentType)) {
        container = container.eContainer();
    }
    ComponentImplementation compImpl = null;
    ComponentType type = null;
    if (container instanceof ComponentImplementation) {
        compImpl = (ComponentImplementation) container;
        type = compImpl.getType();
        checkDupNames(namedEl, type, compImpl);
    } else if (container instanceof ComponentType) {
        type = (ComponentType) container;
    }
    if (type != null && (namedEl.getName() != null)) {
        for (Feature feat : type.getAllFeatures()) {
            if (namedEl.getName().equals(feat.getName())) {
                error(feat, "Element of the same name ('" + namedEl.getName() + "') in AGREE Annex in '" + (compImpl == null ? type.getName() : compImpl.getName()) + "'");
                error(namedEl, "Feature of the same name ('" + namedEl.getName() + "') in component type");
            }
        }
    }
// check name space collision with enumerated types
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) Feature(org.osate.aadl2.Feature) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Example 17 with NamedElement

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

the class AgreeValidator method checkOrderStatement.

@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
    Classifier container = order.getContainingClassifier();
    if (container instanceof ComponentImplementation) {
        ComponentImplementation compImpl = (ComponentImplementation) container;
        for (int index = 0; index < order.getComps().size(); ++index) {
            NamedElement comp = order.getComps().get(index);
            if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
                error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
            }
        }
        List<NamedElement> notPresent = new ArrayList<>();
        for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
            boolean found = false;
            for (NamedElement el : order.getComps()) {
                if (el.equals(subcomp)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                notPresent.add(subcomp);
            }
        }
        if (notPresent.size() != 0) {
            String delim = "";
            StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
            for (NamedElement subcomp : notPresent) {
                errorStr.append(delim);
                errorStr.append(subcomp.getName());
                delim = ", ";
            }
            error(order, errorStr.toString());
        }
    } else {
        error(order, "Ordering statements can appear only in component implementations");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Example 18 with NamedElement

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

the class AgreeValidator method checkArg.

@Check(CheckType.FAST)
public void checkArg(Arg arg) {
    Type type = arg.getType();
    if (type instanceof PrimType) {
        PrimType primType = (PrimType) type;
        String strType = primType.getName();
        String rangeLow = primType.getRangeLow();
        String rangeHigh = primType.getRangeHigh();
        if (rangeLow != null && rangeHigh != null) {
            // this is a ranged argument. It can show up only in an equation statement
            EObject container = arg.eContainer();
            if (!(container instanceof EqStatement || container instanceof InputStatement)) {
                error(arg, "Ranged arguments can appear only in equation statements or agree_input statements");
            }
            boolean rangeLowDot = rangeLow.contains(".");
            boolean rangeHighDot = rangeHigh.contains(".");
            if (rangeLowDot != rangeHighDot) {
                error(arg, "The range intervals are of differing types");
            }
            if (strType.equals("int") && (rangeLowDot || rangeHighDot)) {
                error(arg, "Ranged variable of type 'int' contains a 'real' value in its interval");
            }
            if (strType.equals("real") && (!rangeLowDot || !rangeHighDot)) {
                error(arg, "Ranged variable of type 'real' contains an 'int' value in its interval");
            }
            float low = Float.valueOf(rangeLow);
            float high = Float.valueOf(rangeHigh);
            low *= primType.getLowNeg() == null ? 1.0 : -1.0;
            high *= primType.getHighNeg() == null ? 1.0 : -1.0;
            if (low >= high) {
                error(arg, "The low value of the interval is greater than or equal to the high end");
            }
        }
    } else if (type instanceof DoubleDotRef) {
        DoubleDotRef recType = (DoubleDotRef) type;
        NamedElement finalId = recType.getElm();
        if (!(finalId instanceof DataImplementation) && !(finalId instanceof RecordDef) && !(finalId instanceof DataType) && !(finalId instanceof EnumStatement)) {
            error(recType, "types must be record definition, array definition, data implementation, enumeration, or datatype");
        }
        if (finalId instanceof DataImplementation) {
            if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
                error(recType, "Data Implementations with no subcomponents must extend" + " a Base_Type that AGREE can reason about.");
                return;
            }
            if (((DataImplementation) finalId).getAllSubcomponents().size() != 0) {
                if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.BoolTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.IntTypeDef) || AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.RealTypeDef)) {
                    error(finalId, "Data implementations with subcomponents cannot be" + " interpreted by AGREE if they extend Base_Types");
                }
            }
            // dataImplCycleCheck(recId);
            return;
        }
        if (finalId instanceof DataType) {
            if (AgreeTypeSystem.typesEqual(AgreeTypeSystem.typeDefFromType(recType), AgreeTypeSystem.Prim.ErrorTypeDef)) {
                error(recType, "AADL Datatypes must extend" + " a Base_Type that AGREE can reason about.");
                return;
            }
        }
    }
}
Also used : DataImplementation(org.osate.aadl2.DataImplementation) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) CheckType(org.eclipse.xtext.validation.CheckType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentType(org.osate.aadl2.ComponentType) Type(com.rockwellcollins.atc.agree.agree.Type) DirectionType(org.osate.aadl2.DirectionType) EObject(org.eclipse.emf.ecore.EObject) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) DataType(org.osate.aadl2.DataType) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Example 19 with NamedElement

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

the class AgreeValidator method checkMultiAssignEq.

private void checkMultiAssignEq(EObject src, List<Arg> lhsArgs, Expr rhsExpr) {
    if (rhsExpr == null) {
        return;
    }
    if (lhsArgs.size() == 1) {
        // we should only need to check for cycles for single equations
        String name = lhsArgs.get(0).getName();
        ExprCycleVisitor cycleVisitor = new ExprCycleVisitor(name);
        Set<EObject> cycleObjects = cycleVisitor.doSwitch(rhsExpr);
        if (cycleObjects == null) {
            throw new IllegalArgumentException("something went wrong with the cycle checker");
        }
        for (EObject obj : cycleObjects) {
            error(obj, "Cyclic reference to variable '" + name + "'");
        }
    }
    if (argsContainRangeValue(lhsArgs)) {
        error(src, "Equation statements cannot contain a ranged value and a right hand side expression");
    }
    List<TypeDef> agreeLhsTypes = new ArrayList<>();
    for (Arg arg : lhsArgs) {
        agreeLhsTypes.add(AgreeTypeSystem.typeDefFromType(arg.getType()));
    }
    List<TypeDef> agreeRhsTypes = new ArrayList<>();
    if (rhsExpr instanceof CallExpr) {
        NamedElement namedEl = ((CallExpr) rhsExpr).getRef().getElm();
        if (namedEl instanceof NodeDef) {
            NodeDef nodeDef = (NodeDef) namedEl;
            for (Arg var : nodeDef.getRets()) {
                agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(var.getType()));
            }
        } else if (namedEl instanceof FnDef) {
            FnDef fnDef = (FnDef) namedEl;
            agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
        } else if (namedEl instanceof UninterpretedFnDef) {
            UninterpretedFnDef uninterpretedFnDef = (UninterpretedFnDef) namedEl;
            agreeRhsTypes.add(AgreeTypeSystem.typeDefFromType(uninterpretedFnDef.getType()));
        } else {
            // parse error
            return;
        }
    } else {
        checkTypeExists(rhsExpr);
        TypeDef rhsType = AgreeTypeSystem.infer(rhsExpr);
        agreeRhsTypes.add(rhsType);
    }
    if (agreeLhsTypes.size() != agreeRhsTypes.size()) {
        error(src, "Equation assigns " + agreeLhsTypes.size() + " variables, but right side returns " + agreeRhsTypes.size() + " values");
        return;
    }
    for (int i = 0; i < agreeLhsTypes.size(); i++) {
        TypeDef lhsType = agreeLhsTypes.get(i);
        TypeDef rhsType = agreeRhsTypes.get(i);
        if (!AgreeTypeSystem.typesEqual(rhsType, lhsType)) {
            error(src, "The variable '" + lhsArgs.get(i).getName() + "' on the left side of equation is of type '" + nameOfTypeDef(lhsType) + "' but must be of type '" + nameOfTypeDef(rhsType) + "'");
        }
    }
}
Also used : NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) ArrayList(java.util.ArrayList) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ExprCycleVisitor(com.rockwellcollins.atc.agree.visitors.ExprCycleVisitor) AgreeTypeSystem.nameOfTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.nameOfTypeDef) ArrayTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef) RecordTypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.RecordTypeDef) TypeDef(com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) NamedElement(org.osate.aadl2.NamedElement)

Example 20 with NamedElement

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

the class AgreeValidator method checkNoDuplicateIdInSpec.

@Check(CheckType.NORMAL)
public void checkNoDuplicateIdInSpec(AadlPackage toppkg) {
    // namedSpecs associates an agree spec ID with all the agree specs that have that ID
    HashMultimap<String, NamedSpecStatement> namedSpecs = HashMultimap.create();
    // Get the set of packages referenced in model
    Set<AadlPackage> pkgs = new HashSet<>();
    getPackageDependencies(toppkg, pkgs);
    for (AadlPackage pkg : pkgs) {
        // Get the list of agree specs in each package
        List<NamedSpecStatement> specs = getNamedSpecStatements(pkg);
        for (NamedSpecStatement spec : specs) {
            String id = spec.getName();
            if (id != null) {
                namedSpecs.put(id, spec);
            }
        }
    }
    // Get the agree specs in the current package
    List<NamedSpecStatement> specs = getNamedSpecStatements(toppkg);
    Iterator<NamedSpecStatement> i = specs.iterator();
    while (i.hasNext()) {
        NamedSpecStatement spec = i.next();
        String id = spec.getName();
        // If the current spec name is associated with multiple agree specs, we've found a duplicate
        if (namedSpecs.get(id).size() > 1) {
            Iterator<NamedSpecStatement> ii = namedSpecs.get(id).iterator();
            while (ii.hasNext()) {
                String pkgName = AadlUtil.getContainingPackage(ii.next()).getName();
                // // If the specs are from the same package, the error will be generated from the
                // // NamedElement check.
                // if (!pkgName.contentEquals(AadlUtil.getContainingPackage(spec).getName())) {
                error("Duplicate AGREE property ID in package " + pkgName, spec, Aadl2Package.eINSTANCE.getNamedElement_Name());
            // }
            }
            namedSpecs.removeAll(id);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Aggregations

Property (org.osate.aadl2.Property)351 PropertyExpression (org.osate.aadl2.PropertyExpression)291 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)236 NamedElement (org.osate.aadl2.NamedElement)229 BasicProperty (org.osate.aadl2.BasicProperty)90 ListValue (org.osate.aadl2.ListValue)63 EObject (org.eclipse.emf.ecore.EObject)50 UnitLiteral (org.osate.aadl2.UnitLiteral)48 Classifier (org.osate.aadl2.Classifier)46 ArrayList (java.util.ArrayList)45 TimeUnits (org.osate.aadl2.contrib.aadlproject.TimeUnits)41 PropertyAssociation (org.osate.aadl2.PropertyAssociation)38 ComponentClassifier (org.osate.aadl2.ComponentClassifier)37 Subcomponent (org.osate.aadl2.Subcomponent)35 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)32 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)32 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)31 ComponentImplementation (org.osate.aadl2.ComponentImplementation)30 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)28 Element (org.osate.aadl2.Element)28