Search in sources :

Example 46 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreePatternTranslator method addPatternConstraintProperty.

private void addPatternConstraintProperty(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    AgreeVar newCause = new AgreeVar(NEW_CAUSE_PREFIX + causeId.id + patternIndex, NamedType.BOOL, pattern);
    builder.addLocal(newCause);
    AgreeVar timeCauseVar = getTimeOf(causeId.id, builder, pattern);
    IdExpr timeCauseId = new IdExpr(timeCauseVar.id);
    IdExpr newCauseId = new IdExpr(newCause.id);
    Expr preTimeCause = new UnaryExpr(UnaryOp.PRE, timeCauseId);
    Expr newCauseExpr = new BinaryExpr(preTimeCause, BinaryOp.NOTEQUAL, timeCauseId);
    newCauseExpr = new BinaryExpr(newCauseExpr, BinaryOp.AND, new BinaryExpr(preTimeCause, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO)));
    builder.addLocalEquation(new AgreeEquation(newCauseId, newCauseExpr, pattern));
    if (pattern.effectType == TriggerType.EVENT) {
        AgreeVar timeEffectVar = getTimeOf(effectId.id, builder, pattern);
        IdExpr timeEffectId = new IdExpr(timeEffectVar.id);
        Expr preTimeCausePlusL = new BinaryExpr(preTimeCause, BinaryOp.PLUS, pattern.effectInterval.low);
        BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
        Expr inInterval = new BinaryExpr(preTimeCausePlusL, left, timeEffectId);
        Expr propExpr = new BinaryExpr(newCauseId, BinaryOp.IMPLIES, inInterval);
        propExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, propExpr);
        AgreeStatement statement = new AgreeStatement(" pattern " + patternIndex + " in bounds", propExpr, pattern);
        builder.addPatternProp(statement);
    } else {
        AgreeVar timeEndVar = new AgreeVar(END_INTERVAL + patternIndex, NamedType.REAL, pattern);
        builder.addLocal(timeEndVar);
        Equation eq = equation("timeEnd = timeCause + h;", to("timeEnd", timeEndVar), to("timeCause", timeCauseId), to("h", pattern.effectInterval.high));
        builder.addLocalEquation(new AgreeEquation(eq, pattern));
        Expr expr = expr("true -> (newCause => pre(timeEnd) < time)", to("timeEnd", timeEndVar), to("newCause", newCauseId), to("time", timeExpr));
        AgreeStatement statement = new AgreeStatement(" pattern " + patternIndex + " in bounds", expr, pattern);
        builder.addPatternProp(statement);
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Example 47 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreePatternTranslator method translatePatternEffectEventConstraint.

private Expr translatePatternEffectEventConstraint(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    AgreeVar effectTimeRangeVar = new AgreeVar(EFFECT_TIME_RANGE_PREFIX + patternIndex, NamedType.REAL, pattern);
    builder.addInput(effectTimeRangeVar);
    IdExpr effectTimeRangeId = new IdExpr(effectTimeRangeVar.id);
    AgreeVar timeEffectVar = new AgreeVar(TIME_WILL_PREFIX + patternIndex, NamedType.REAL, pattern);
    builder.addOutput(timeEffectVar);
    IdExpr timeEffectId = new IdExpr(timeEffectVar.id);
    Expr effectTimeRangeConstraint = getTimeRangeConstraint(effectTimeRangeId, pattern.effectInterval);
    builder.addAssertion(new AgreeStatement(null, effectTimeRangeConstraint, pattern.reference));
    // make a constraint that triggers when the event WILL happen
    Expr expr = expr("timeEffect = if causeId then effectTimeRangeId else (-1.0 -> pre timeEffect)", to("timeEffect", timeEffectId), to("causeId", causeId), to("effectTimeRangeId", effectTimeRangeId));
    builder.addAssertion(new AgreeStatement(null, expr, pattern));
    // a lemma that may be helpful
    Expr lemma = expr("timeEffect <= time + intHigh", to("timeEffect", timeEffectVar), to("time", timeExpr), to("intHigh", pattern.effectInterval.high));
    builder.addAssertion(new AgreeStatement(null, lemma, pattern));
    lemma = expr("timeWill <= causeTime + high and (causeTime >= 0.0 => causeTime + low <= timeWill)", to("timeWill", timeEffectVar), to("causeTime", getTimeOf(causeId.id, builder, pattern)), to("high", pattern.effectInterval.high), to("low", pattern.effectInterval.low));
    builder.addAssertion(new AgreeStatement(null, lemma, pattern));
    lemma = expr("timeWill <= time => timeWill <= timeEffect", to("timeWill", timeEffectVar), to("timeEffect", getTimeOf(effectId.id, builder, pattern)));
    builder.addAssertion((new AgreeStatement(null, lemma, pattern)));
    // Expr lemmaExpr = expr("timeEffect <= effectTimeRangeId and timeEffect
    // >= -1.0",
    // to("timeEffect", timeEffectId),
    // to("effectTimeRangeId", effectTimeRangeId));
    // 
    // //add this assertion to help with proofs (it should always be true)
    // builder.addAssertion(new AgreeStatement(null, lemmaExpr, pattern));
    // register the event time
    builder.addEventTime(timeEffectVar);
    // make the equation that triggers the event at the correct ime
    Expr timeEqualsEffectTime = new BinaryExpr(timeExpr, BinaryOp.EQUAL, timeEffectId);
    // if the event is exclusive it only occurs when scheduled
    BinaryOp effectOp = pattern.effectIsExclusive ? BinaryOp.EQUAL : BinaryOp.IMPLIES;
    Expr impliesEffect = new BinaryExpr(timeEqualsEffectTime, effectOp, effectId);
    return impliesEffect;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Example 48 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class VerifyHandler method addKind2Properties.

protected void addKind2Properties(AgreeNode agreeNode, List<String> properties, AgreeRenaming renaming, String prefix, String userPropPrefix) {
    int i = 0;
    String propPrefix = (userPropPrefix.equals("")) ? "" : userPropPrefix + ": ";
    for (AgreeStatement statement : agreeNode.lemmas) {
        renaming.addExplicitRename(prefix + "[" + (++i) + "]", propPrefix + statement.string);
        properties.add(prefix.replaceAll("\\.", AgreeASTBuilder.dotChar) + "[" + i + "]");
    }
    for (AgreeStatement statement : agreeNode.guarantees) {
        renaming.addExplicitRename(prefix + "[" + (++i) + "]", propPrefix + statement.string);
        properties.add(prefix.replaceAll("\\.", AgreeASTBuilder.dotChar) + "[" + i + "]");
    }
    userPropPrefix = userPropPrefix.equals("") ? "" : userPropPrefix + ".";
    for (AgreeNode subNode : agreeNode.subNodes) {
        addKind2Properties(subNode, properties, renaming, prefix + "." + subNode.id, userPropPrefix + subNode.id);
    }
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)

Example 49 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreeASTMapVisitor method visit.

@Override
public AgreeStatement visit(AgreeStatement e) {
    String string = e.string;
    Expr expr = e.expr.accept(this);
    EObject reference = e.reference;
    return new AgreeStatement(string, expr, reference);
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) EObject(org.eclipse.emf.ecore.EObject)

Example 50 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreeASTMapVisitor method visit.

@Override
public AgreeConnection visit(AgreeConnection e) {
    if (e instanceof AgreeAADLConnection) {
        AgreeAADLConnection aadlConn = (AgreeAADLConnection) e;
        AgreeNode sourceNode = null;
        if (aadlConn.sourceNode != null) {
            sourceNode = visitedNodes.get(aadlConn.sourceNode.compInst);
        }
        AgreeNode destinationNode = null;
        if (aadlConn.destinationNode != null) {
            destinationNode = visitedNodes.get(aadlConn.destinationNode.compInst);
        }
        AgreeVar sourVar = visit(aadlConn.sourceVarName);
        AgreeVar destVar = visit(aadlConn.destinationVarName);
        ConnectionType type = aadlConn.type;
        boolean latched = aadlConn.latched;
        boolean delayed = aadlConn.delayed;
        EObject reference = aadlConn.reference;
        return new AgreeAADLConnection(sourceNode, destinationNode, sourVar, destVar, type, latched, delayed, reference);
    } else if (e instanceof AgreeOverriddenConnection) {
        AgreeOverriddenConnection overriddenCon = (AgreeOverriddenConnection) e;
        AgreeStatement statement = visit(overriddenCon.statement);
        return new AgreeOverriddenConnection(statement, overriddenCon.aadlConn);
    }
    throw new AgreeException("Unhandled Agree connection type " + e.getClass());
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreeAADLConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection) EObject(org.eclipse.emf.ecore.EObject) AgreeOverriddenConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeOverriddenConnection) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)56 IdExpr (jkind.lustre.IdExpr)50 Expr (jkind.lustre.Expr)49 BinaryExpr (jkind.lustre.BinaryExpr)47 NodeCallExpr (jkind.lustre.NodeCallExpr)45 BoolExpr (jkind.lustre.BoolExpr)44 UnaryExpr (jkind.lustre.UnaryExpr)40 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)39 IfThenElseExpr (jkind.lustre.IfThenElseExpr)28 ArrayList (java.util.ArrayList)25 IntExpr (jkind.lustre.IntExpr)23 RecordAccessExpr (jkind.lustre.RecordAccessExpr)19 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)15 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 RealExpr (jkind.lustre.RealExpr)13 VarDecl (jkind.lustre.VarDecl)13 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11 Equation (jkind.lustre.Equation)11 TupleExpr (jkind.lustre.TupleExpr)11