Search in sources :

Example 1 with InputStatement

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

the class AgreeASTBuilder method getAgreeInputVars.

private GatheredVariablesAndConstraints getAgreeInputVars(List<SpecStatement> specs, ComponentInstance compInst) {
    GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
    for (SpecStatement spec : specs) {
        if (spec instanceof InputStatement) {
            EList<Arg> args = ((InputStatement) spec).getLhs();
            List<VarDecl> vars = agreeVarsFromArgs(args, compInst);
            for (VarDecl var : vars) {
                result.variables.add((AgreeVar) var);
            }
            result.assertions.addAll(getConstraintsFromArgs(args, spec));
        }
    }
    return result;
}
Also used : VarDecl(jkind.lustre.VarDecl) Arg(com.rockwellcollins.atc.agree.agree.Arg) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement)

Example 2 with InputStatement

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

the class LustreAstBuilder method addNodeCall.

protected static void addNodeCall(AgreeNode agreeNode, List<AgreeStatement> assertions, String prefix, Expr clockExpr, Node lustreNode) {
    List<Expr> inputIds = new ArrayList<>();
    for (VarDecl var : lustreNode.inputs) {
        String suffix = "";
        // if this component implementation is using the latched semantics
        if (agreeNode.timing == TimingModel.LATCHED) {
            EObject ref = ((AgreeVar) var).reference;
            if (ref instanceof DataPortImpl && ((DataPortImpl) ref).isIn() || (ref instanceof EventDataPortImpl && ((EventDataPortImpl) ref).isIn() || (ref instanceof Arg && ref.eContainer() instanceof InputStatement))) {
                suffix = AgreeInlineLatchedConnections.LATCHED_SUFFIX;
            }
        }
        inputIds.add(new IdExpr(prefix + var.id + suffix));
    }
    if (agreeNode.timing == TimingModel.ASYNC || agreeNode.timing == TimingModel.LATCHED) {
        // the clock expr should be the last input to the node
        inputIds.set(inputIds.size() - 1, clockExpr);
    }
    Expr condactExpr = new NodeCallExpr(lustreNode.id, inputIds);
    AgreeStatement condactCall = new AgreeStatement("", condactExpr, null);
    assertions.add(condactCall);
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) EventDataPortImpl(org.osate.aadl2.impl.EventDataPortImpl) DataPortImpl(org.osate.aadl2.impl.DataPortImpl) ArrayList(java.util.ArrayList) EventDataPortImpl(org.osate.aadl2.impl.EventDataPortImpl) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement)

Example 3 with InputStatement

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

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

the class AgreeValidator method checkLatchedExpr.

@Check(CheckType.FAST)
public void checkLatchedExpr(LatchedExpr latched) {
    // get container
    EObject container = latched.eContainer();
    AgreeContract contract = null;
    while (!(container instanceof ComponentClassifier)) {
        if (container instanceof AgreeContract) {
            contract = (AgreeContract) container;
        }
        container = container.eContainer();
    }
    if (container instanceof ComponentImplementation) {
        boolean foundLatchedStatement = false;
        for (SpecStatement spec : contract.getSpecs()) {
            if (spec instanceof LatchedStatement) {
                foundLatchedStatement = true;
                break;
            }
        }
        if (!foundLatchedStatement) {
            error(latched, "Latched expressions can appear only in component implementations " + "that contain a latched synchrony statement");
        }
    } else {
        error(latched, "Latched expressions can appear only in component implementations");
    }
    Expr expr = latched.getExpr();
    Expr nestId = null;
    if (expr instanceof NamedElmExpr) {
        nestId = expr;
    } else if (expr instanceof EventExpr) {
        EventExpr eventExpr = (EventExpr) expr;
        nestId = eventExpr.getPort();
    }
    if (nestId != null) {
        NamedElement namedEl = null;
        if (nestId instanceof NamedElmExpr) {
            namedEl = ((NamedElmExpr) nestId).getElm();
        } else if (nestId instanceof SelectionExpr) {
            namedEl = ((SelectionExpr) nestId).getField();
        }
        if ((namedEl instanceof DataPort) && ((DataPort) namedEl).isIn()) {
            return;
        } else if ((namedEl instanceof EventDataPort) && ((EventDataPort) namedEl).isIn()) {
            return;
        } else {
            // check to see if it is an "agree_input"
            EObject namedElContainer = namedEl.eContainer();
            if (namedElContainer instanceof InputStatement) {
                return;
            }
        }
    }
    error(latched, "Latched expressions are valid only for input data ports or event expressions over input event data ports");
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) 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) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) 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) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) 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) Expr(com.rockwellcollins.atc.agree.agree.Expr) 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) EObject(org.eclipse.emf.ecore.EObject) LatchedStatement(com.rockwellcollins.atc.agree.agree.LatchedStatement) EventDataPort(org.osate.aadl2.EventDataPort) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Check(org.eclipse.xtext.validation.Check)

Example 5 with InputStatement

use of com.rockwellcollins.atc.agree.agree.InputStatement 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

InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)10 EqStatement (com.rockwellcollins.atc.agree.agree.EqStatement)6 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)6 Arg (com.rockwellcollins.atc.agree.agree.Arg)5 EObject (org.eclipse.emf.ecore.EObject)5 ArrayList (java.util.ArrayList)4 NamedElement (org.osate.aadl2.NamedElement)4 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)3 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)3 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)3 EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)3 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)3 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 ComponentType (org.osate.aadl2.ComponentType)3 Property (org.osate.aadl2.Property)3 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)2 AssertStatement (com.rockwellcollins.atc.agree.agree.AssertStatement)2 AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)2 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)2