use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseExistsExpr.
@Override
public Expr caseExistsExpr(ExistsExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseExistsExpr - '" + agreeType.getClass() + "' not handled");
}
NamedID binding = expr.getBinding();
Expr final_expr = new BoolExpr(false);
for (int i = 0; i < size; ++i) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
final_expr = LustreExprFactory.makeORExpr(final_expr, body);
}
return final_expr;
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method getSynchConstraint.
private Expr getSynchConstraint(SynchStatement spec, List<AgreeNode> subNodes) {
int val1 = Integer.decode(spec.getVal());
if (val1 == 0) {
return new BoolExpr(true);
}
List<Expr> clockIds = new ArrayList<>();
Expr clockAssertion;
for (AgreeNode subNode : subNodes) {
clockIds.add(new IdExpr(subNode.clockVar.id));
}
String dfaPrefix = getObjectLocationPrefix(spec);
if (spec.getVal2() == null) {
Node dfaNode = AgreeCalendarUtils.getDFANode(dfaPrefix + "__DFA_NODE", val1);
Node calNode = AgreeCalendarUtils.getCalendarNode(dfaPrefix + "__CALENDAR_NODE", dfaNode.id, clockIds.size());
// we do not need to make copies of the nodes if they exist
if (!nodeNameExists(dfaNode.id)) {
if (nodeNameExists(calNode.id)) {
throw new AgreeException("The calander node should not exist if the dfa node does not exist");
}
addToNodeList(dfaNode);
addToNodeList(calNode);
}
clockAssertion = new NodeCallExpr(calNode.id, clockIds);
} else {
int val2 = Integer.decode(spec.getVal2());
String nodeName = "__calendar_node_" + val1 + "_" + val2;
nodeName = dfaPrefix + nodeName;
Node calNode = AgreeCalendarUtils.getMNCalendar(nodeName, val1, val2);
if (!nodeNameExists(calNode.id)) {
addToNodeList(calNode);
}
clockAssertion = new BoolExpr(true);
int i, j;
for (i = 0; i < clockIds.size(); i++) {
Expr clock1 = clockIds.get(i);
for (j = i + 1; j < clockIds.size(); j++) {
Expr clock2 = clockIds.get(j);
NodeCallExpr nodeCall = new NodeCallExpr(nodeName, clock1, clock2);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
nodeCall = new NodeCallExpr(nodeName, clock2, clock1);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
}
}
}
return clockAssertion;
}
use of jkind.lustre.BoolExpr 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;
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeCalendarUtils method getExplicitCalendarNode.
public static Node getExplicitCalendarNode(String nodeName, List<IdExpr> calendar, List<Expr> clocks) {
// filter the calendar if some clocks are not present
List<IdExpr> filteredCalendar = new ArrayList<>();
Map<String, List<Integer>> clockTickMap = new HashMap<>();
for (IdExpr calId : calendar) {
for (Expr clockExpr : clocks) {
IdExpr clockId = (IdExpr) clockExpr;
if (calId.id.equals(clockId.id)) {
filteredCalendar.add(clockId);
break;
}
}
}
int i = 0;
for (IdExpr clockId : filteredCalendar) {
List<Integer> ticks = clockTickMap.get(clockId.id);
if (ticks == null) {
ticks = new ArrayList<>();
clockTickMap.put(clockId.id, ticks);
}
ticks.add(i++);
}
for (Expr clockExpr : clocks) {
IdExpr clockId = (IdExpr) clockExpr;
if (clockTickMap.get(clockId.id) == null) {
throw new AgreeException("Clock Id '" + clockId.id + "' is not present in calendar statement");
}
}
// add all of the clocks to to the inputs of the node
List<VarDecl> inputs = new ArrayList<>();
for (Expr clockExpr : clocks) {
VarDecl input = new VarDecl(((IdExpr) clockExpr).id, NamedType.BOOL);
inputs.add(input);
}
// the output is the variable asserting the calendar
List<VarDecl> outputs = new ArrayList<>();
IdExpr outputAssert = new IdExpr("__CALENDAR_ASSERTION");
outputs.add(new VarDecl(outputAssert.id, NamedType.BOOL));
// create a variable that counts through the calendar elements
List<VarDecl> locals = new ArrayList<>();
VarDecl clockCounterVar = new VarDecl("__CALANDER_COUNTER", NamedType.INT);
locals.add(clockCounterVar);
List<Equation> equations = new ArrayList<>();
// create the expression for the counter variable
IdExpr clockCountId = new IdExpr(clockCounterVar.id);
IntExpr calendarSize = new IntExpr(BigInteger.valueOf(filteredCalendar.size() - 1));
Expr preClockCount = new UnaryExpr(UnaryOp.PRE, clockCountId);
Expr preLast = new BinaryExpr(preClockCount, BinaryOp.EQUAL, calendarSize);
Expr prePlus = new BinaryExpr(preClockCount, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
Expr ifClock = new IfThenElseExpr(preLast, new IntExpr(BigInteger.ZERO), prePlus);
Expr clockArrow = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, ifClock);
Equation clockCountEq = new Equation(clockCountId, clockArrow);
equations.add(clockCountEq);
// create constraints for which calendar element is ticking
Expr calendarConstraint = new BoolExpr(true);
for (Expr clockExpr : clocks) {
IdExpr clockId = (IdExpr) clockExpr;
List<Integer> ticks = clockTickMap.get(clockId.id);
Expr clockTicking = new BoolExpr(false);
for (Integer tick : ticks) {
Expr clockIsTickValue = new BinaryExpr(clockCountId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(tick.longValue())));
clockTicking = new BinaryExpr(clockTicking, BinaryOp.OR, clockIsTickValue);
}
Expr ifExpr = new IfThenElseExpr(clockTicking, clockId, new UnaryExpr(UnaryOp.NOT, clockId));
calendarConstraint = new BinaryExpr(calendarConstraint, BinaryOp.AND, ifExpr);
}
Equation outEq = new Equation(outputAssert, calendarConstraint);
equations.add(outEq);
NodeBuilder builder = new NodeBuilder(nodeName);
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
return builder.build();
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeCalendarUtils method getSingleTick.
public static Expr getSingleTick(List<Expr> clocks) {
Expr returnExpr = new BoolExpr(false);
for (Expr clock0 : clocks) {
Expr tickExpr = clock0;
for (Expr clock1 : clocks) {
if (clock0 != clock1) {
Expr notClock1 = new UnaryExpr(UnaryOp.NOT, clock1);
tickExpr = new BinaryExpr(tickExpr, BinaryOp.AND, notClock1);
}
}
returnExpr = new BinaryExpr(tickExpr, BinaryOp.OR, returnExpr);
}
return returnExpr;
}
Aggregations