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);
}
}
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;
}
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);
}
}
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);
}
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());
}
Aggregations