Search in sources :

Example 1 with EnumerationLiteral

use of org.osate.aadl2.EnumerationLiteral in project VERDICT by ge-high-assurance.

the class Agree2Vdm method updateVDMDatatypeUsingProperties.

/**
 *  @param vdm dataType,
 * 	@param list of property associations
 *  this method checks if the property indicates if it is an enum definition
 *  and gets information from the properties to define the enum in the VDM
 *  *
 */
public boolean updateVDMDatatypeUsingProperties(verdict.vdm.vdm_data.DataType dtype, EList<PropertyAssociation> properties) {
    if (properties.size() == 2) {
        // check if the property specifies it is enum type
        PropertyAssociation firstProperty = properties.get(0);
        EList<ModalPropertyValue> firstPropertyValues = firstProperty.getOwnedValues();
        if (firstPropertyValues.size() == 1) {
            PropertyExpression ownedval = firstPropertyValues.get(0).getOwnedValue();
            if (ownedval instanceof NamedValueImpl) {
                NamedValue namedVal = (NamedValue) ownedval;
                if (namedVal.getNamedValue() instanceof EnumerationLiteralImpl) {
                    EnumerationLiteral namedValEnumLit = (EnumerationLiteral) namedVal.getNamedValue();
                    if (namedValEnumLit.getName().equalsIgnoreCase("Enum")) {
                        EnumType vdmEnumType = new EnumType();
                        // Fetch the enum values which are defined as the next property
                        PropertyAssociation secondProperty = properties.get(1);
                        EList<ModalPropertyValue> secondPropertyValues = secondProperty.getOwnedValues();
                        if (firstPropertyValues.size() == 1) {
                            PropertyExpression secPropValue = secondPropertyValues.get(0).getOwnedValue();
                            // enum should have multiple values so check if a list of values are defined
                            if (secPropValue instanceof ListValueImpl) {
                                ListValueImpl listValueImpl = (ListValueImpl) secPropValue;
                                EList<PropertyExpression> listOfValues = listValueImpl.getOwnedListElements();
                                for (PropertyExpression enumvalue : listOfValues) {
                                    if (enumvalue instanceof StringLiteralImpl) {
                                        StringLiteralImpl stringEnumVal = (StringLiteralImpl) enumvalue;
                                        vdmEnumType.getEnumValue().add(stringEnumVal.getValue());
                                    } else {
                                        System.out.println("Unexpected non-string value for data type of type enum.");
                                    }
                                }
                                dtype.setEnumType(vdmEnumType);
                                return true;
                            } else {
                                System.out.println("The second property of the data definition is not of ListValueImp type");
                            }
                        } else {
                            System.out.println("Unresolved data property. The first property of the data definition has no values or multiple values.");
                        }
                    } else {
                        System.out.println("Unresolved data property value. Property's owned value's named value does not contain Enum");
                    }
                } else {
                    System.out.println("Unresolved data property value. Property's owned value's named value is not EnumerationLiteralImpl type.");
                }
            } else {
                System.out.println("Unresolved data property value. Property's owned value is not NamedValueImpl type.");
            }
        } else {
            System.out.println("Unresolved data property with no values or multiple values.");
        }
    } else {
        System.out.println("Unresolved data property. Data definition has 0 or more than 2 properties associated with it");
    }
    return false;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteralImpl(org.osate.aadl2.impl.StringLiteralImpl) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EnumType(verdict.vdm.vdm_data.EnumType) NamedValueImpl(org.osate.aadl2.impl.NamedValueImpl) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) ListValueImpl(org.osate.aadl2.impl.ListValueImpl) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) EnumerationLiteralImpl(org.osate.aadl2.impl.EnumerationLiteralImpl)

Example 2 with EnumerationLiteral

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

the class AgreeASTBuilder method caseGetPropertyExpr.

@Override
public Expr caseGetPropertyExpr(GetPropertyExpr expr) {
    NamedElement propName = expr.getProp();
    PropertyExpression propVal;
    if (propName instanceof Property) {
        ComponentRef cr = expr.getComponentRef();
        NamedElement compName = null;
        if (cr instanceof DoubleDotRef) {
            compName = ((DoubleDotRef) cr).getElm();
        } else if (cr instanceof ThisRef) {
            compName = curInst;
        }
        Property prop = (Property) propName;
        propVal = AgreeUtils.getPropExpression(compName, prop);
        if (propVal == null) {
            if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_UNSPECIFIED_AADL_PROPERTIES)) {
                String propInputName = unspecifiedAadlPropertyPrefix + compName.getName() + dotChar + prop.getName();
                unspecifiedAadlProperties.put(propInputName, expr);
                return new IdExpr(propInputName);
            } else {
                throw new AgreeException("Could not locate property value '" + prop.getQualifiedName() + "' in component '" + compName.getName() + "'.  Is it possible " + "that a 'this' statement is used in a context in which it wasn't supposed to?" + "  Analysis of unspecified AADL properties as inputs may be enabled in the AGREE preferences.");
            }
        }
    } else {
        propVal = AgreeUtils.getPropExpression((PropertyConstant) propName);
        if (propVal == null) {
            throw new AgreeException("Could not locate property value '" + propName.getQualifiedName());
        }
    }
    Expr res = null;
    if (propVal != null) {
        if (propVal instanceof StringLiteral) {
            // nodeStr += value.getValue() + ")";
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of string type");
        } else if (propVal instanceof NamedValue) {
            // EnumerationLiteral enVal = (EnumerationLiteral) absVal;
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of enumeration type");
        } else if (propVal instanceof BooleanLiteral) {
            BooleanLiteral value = (BooleanLiteral) propVal;
            res = new BoolExpr(value.getValue());
        } else if (propVal instanceof IntegerLiteral) {
            IntegerLiteral value = (IntegerLiteral) propVal;
            res = new IntExpr(BigInteger.valueOf((long) value.getScaledValue()));
        } else {
            assert (propVal instanceof RealLiteral);
            RealLiteral value = (RealLiteral) propVal;
            res = new RealExpr(BigDecimal.valueOf(value.getValue()));
        }
    }
    assert (res != null);
    return res;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BooleanLiteral(org.osate.aadl2.BooleanLiteral) NamedValue(org.osate.aadl2.NamedValue) PropertyConstant(org.osate.aadl2.PropertyConstant) RealLiteral(org.osate.aadl2.RealLiteral) 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) StringLiteral(org.osate.aadl2.StringLiteral) ThisRef(com.rockwellcollins.atc.agree.agree.ThisRef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PropertyExpression(org.osate.aadl2.PropertyExpression) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IntExpr(jkind.lustre.IntExpr) ComponentRef(com.rockwellcollins.atc.agree.agree.ComponentRef) NamedElement(org.osate.aadl2.NamedElement) Property(org.osate.aadl2.Property) RealExpr(jkind.lustre.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 3 with EnumerationLiteral

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

the class AgreeAADLPropertyUtils method getPropertyEnumString.

public static String getPropertyEnumString(NamedElement namedEl, String property) {
    Property prop = Aadl2GlobalScopeUtil.get(namedEl, Aadl2Package.eINSTANCE.getProperty(), property);
    EnumerationLiteral lit = PropertyUtils.getEnumLiteral(namedEl, prop);
    return lit.getName();
}
Also used : Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 4 with EnumerationLiteral

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

the class AgreeTypeSystem method hasBooleanDataRepresentation.

public static boolean hasBooleanDataRepresentation(Classifier classifier) {
    boolean result = false;
    EList<PropertyAssociation> propertyAssociations = classifier.getAllPropertyAssociations();
    for (PropertyAssociation propertyAssociation : propertyAssociations) {
        Property property = propertyAssociation.getProperty();
        try {
            PropertyExpression propertyExpr = classifier.getSimplePropertyValue(property);
            if ("Data_Model::Data_Representation".equals(property.getQualifiedName()) && propertyExpr instanceof NamedValue) {
                AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpr).getNamedValue();
                if (abstractNamedValue instanceof EnumerationLiteral && "Boolean".equals(((EnumerationLiteral) abstractNamedValue).getName())) {
                    result = true;
                }
            }
        } catch (Exception e) {
            continue;
        }
    }
    return result;
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) PropertyExpression(org.osate.aadl2.PropertyExpression) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 5 with EnumerationLiteral

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

the class ThreadCheck method perform.

@Override
public void perform(SystemInstance si) {
    final List<ComponentInstance> allThreads = si.getAllComponentInstances().stream().filter(comp -> (comp.getCategory() == ComponentCategory.THREAD)).collect(Collectors.toList());
    /**
     * Each thread needs to specify the dispatch protocol "periodic" or
     * "sporadic"
     */
    allThreads.stream().filter(comp -> {
        EnumerationLiteral protocol = GetProperties.getDispatchProtocol(comp);
        return protocol == null || !(protocol.toString().equalsIgnoreCase(AadlProject.PERIODIC_LITERAL) || protocol.toString().equalsIgnoreCase(AadlProject.SPORADIC_LITERAL));
    }).forEach(thr -> addError(new ErrorReport(thr, "Thread needs a Thread_Properties::Dispatch_Protocol property of 'Periodic' or 'Sporadic'")));
    /**
     * Each thread needs to specify period
     */
    final List<ComponentInstance> threadMissingPeriod = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getPeriod, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
    for (ComponentInstance thr : threadMissingPeriod) {
        addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Period"));
    }
    final List<ComponentInstance> threadMissingDeadline = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getDeadline, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
    for (ComponentInstance thr : threadMissingDeadline) {
        addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Deadline"));
    }
    for (ComponentInstance ci : allThreads) {
        ComponentClassifier cc = ci.getComponentClassifier();
        if (cc instanceof ThreadImplementation) {
            ThreadImplementation ti = (ThreadImplementation) cc;
            for (SubprogramCall sc : ti.getSubprogramCalls()) {
                NamedElement cs = (NamedElement) sc.getCalledSubprogram();
                if (GetProperties.getSourceName(cs) == null) {
                    addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Name"));
                }
                if (GetProperties.getSourceText(cs).size() == 0) {
                    addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Text"));
                }
                if (GetProperties.getSourceLanguage(cs).size() == 0) {
                    addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Language"));
                }
            }
        }
    }
/**
 * FIXME JD Each thread needs to specify execution time
 */
// List<ComponentInstance> threadMissingExecutionTime =
// (List<ComponentInstance>) si.getAllComponentInstances().stream().
// filter( comp -> (comp.getCategory() == ComponentCategory.THREAD) &&
// (GetProperties.get > 0.0));
// for (ComponentInstance thr : threadMissingPeriod)
// {
// addError (new ErrorReport (thr, "Thread needs to define a period"));
// }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) ThreadImplementation(org.osate.aadl2.ThreadImplementation) PropertyUtils(org.osate.pluginsupport.properties.PropertyUtils) AadlProject(org.osate.xtext.aadl2.properties.util.AadlProject) Collectors(java.util.stream.Collectors) ErrorReport(org.osate.codegen.checker.report.ErrorReport) ComponentClassifier(org.osate.aadl2.ComponentClassifier) List(java.util.List) TimingProperties(org.osate.aadl2.contrib.timing.TimingProperties) ComponentCategory(org.osate.aadl2.ComponentCategory) TimeUnits(org.osate.aadl2.contrib.aadlproject.TimeUnits) GetProperties(org.osate.xtext.aadl2.properties.util.GetProperties) NamedElement(org.osate.aadl2.NamedElement) SubprogramCall(org.osate.aadl2.SubprogramCall) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) ErrorReport(org.osate.codegen.checker.report.ErrorReport) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ThreadImplementation(org.osate.aadl2.ThreadImplementation) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) SubprogramCall(org.osate.aadl2.SubprogramCall) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)40 NamedValue (org.osate.aadl2.NamedValue)25 Property (org.osate.aadl2.Property)24 PropertyExpression (org.osate.aadl2.PropertyExpression)21 BasicProperty (org.osate.aadl2.BasicProperty)18 PropertyAssociation (org.osate.aadl2.PropertyAssociation)13 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)12 ListValue (org.osate.aadl2.ListValue)8 AadlString (org.osate.aadl2.AadlString)7 StringLiteral (org.osate.aadl2.StringLiteral)7 ArrayList (java.util.ArrayList)6 ArraySizeProperty (org.osate.aadl2.ArraySizeProperty)6 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)6 NamedElement (org.osate.aadl2.NamedElement)6 PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)6 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)5 RecordValue (org.osate.aadl2.RecordValue)5 Classifier (org.osate.aadl2.Classifier)4 ClassifierValue (org.osate.aadl2.ClassifierValue)4 EnumerationType (org.osate.aadl2.EnumerationType)4