Search in sources :

Example 1 with EnumStatement

use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.

the class AgreeValidator method getEnumValueDefLocation.

private String getEnumValueDefLocation(NamedID id) {
    EObject container = id.eContainer();
    EnumStatement enumStatement = (EnumStatement) container;
    String enumName = enumStatement.getName();
    while (!(container instanceof AadlPackage) && !(container instanceof ComponentClassifier)) {
        container = container.eContainer();
    }
    return ((NamedElement) container).getQualifiedName() + "::" + enumName;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) NamedElement(org.osate.aadl2.NamedElement)

Example 2 with EnumStatement

use of com.rockwellcollins.atc.agree.agree.EnumStatement 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 3 with EnumStatement

use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.

the class AgreeTypeSystem method typeDefFromNE.

public static TypeDef typeDefFromNE(NamedElement ne) {
    if (ne instanceof Classifier) {
        return typeDefFromClassifier((Classifier) ne);
    } else if (ne instanceof RecordDef) {
        EList<Arg> args = ((RecordDef) ne).getArgs();
        Map<String, TypeDef> fields = new HashMap<>();
        for (Arg arg : args) {
            String key = arg.getName();
            TypeDef typeDef = typeDefFromType(arg.getType());
            fields.put(key, typeDef);
        }
        return new RecordTypeDef(ne.getQualifiedName(), fields, ne);
    } else if (ne instanceof EnumStatement) {
        String name = ne.getQualifiedName();
        List<String> enumValues = new ArrayList<String>();
        for (NamedID nid : ((EnumStatement) ne).getEnums()) {
            String enumValue = name + "_" + nid.getName();
            enumValues.add(enumValue);
        }
        return new EnumTypeDef(name, enumValues, ne);
    } else if (ne instanceof Arg) {
        return typeDefFromType(((Arg) ne).getType());
    } else {
        return Prim.ErrorTypeDef;
    }
}
Also used : ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) AadlString(org.osate.aadl2.AadlString) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) EList(org.eclipse.emf.common.util.EList) Arg(com.rockwellcollins.atc.agree.agree.Arg) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) Map(java.util.Map) HashMap(java.util.HashMap) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 4 with EnumStatement

use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.

the class AgreeLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof UninterpretedFnDef) {
                        if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 5 with EnumStatement

use of com.rockwellcollins.atc.agree.agree.EnumStatement in project AGREE by loonwerks.

the class AgreeScopeProvider method getNamedElementsFromSpecs.

private Map<String, NamedElement> getNamedElementsFromSpecs(EList<SpecStatement> specs) {
    Map<String, NamedElement> nelms = new HashMap<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof NamedElement) {
            nelms.put(((NamedElement) spec).getName(), (NamedElement) spec);
        }
        if (spec instanceof EqStatement) {
            EqStatement eq = (EqStatement) spec;
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(eq.getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof ConstStatement) {
            ConstStatement c = (ConstStatement) spec;
            nelms.put(c.getName(), c);
        } else if (spec instanceof InputStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((InputStatement) spec).getLhs());
            nelms.putAll(toNamedElementMap(nes));
        } else if (spec instanceof EnumStatement) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((EnumStatement) spec).getEnums());
            nelms.putAll(toNamedElementMap(nes));
        }
    }
    return nelms;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) HashMap(java.util.HashMap) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)7 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)4 NamedElement (org.osate.aadl2.NamedElement)4 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)3 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)3 InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)3 NamedID (com.rockwellcollins.atc.agree.agree.NamedID)3 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)3 AadlPackage (org.osate.aadl2.AadlPackage)3 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)2 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)2 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)2 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EList (org.eclipse.emf.common.util.EList)2 EObject (org.eclipse.emf.ecore.EObject)2 AnnexLibrary (org.osate.aadl2.AnnexLibrary)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2