use of jkind.lustre.Expr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseIndicesExpr.
@Override
public Expr caseIndicesExpr(IndicesExpr expr) {
AgreeTypeSystem.TypeDef arrayTypeDef = AgreeTypeSystem.infer(expr.getArray());
if (arrayTypeDef instanceof AgreeTypeSystem.ArrayTypeDef) {
int size = ((AgreeTypeSystem.ArrayTypeDef) arrayTypeDef).size;
List<Expr> elems = new ArrayList<>();
for (int i = 0; i < size; i++) {
elems.add(new IntExpr(i + 1));
}
return new ArrayExpr(elems);
}
throw new RuntimeException("Error caseIndicesExpr");
}
use of jkind.lustre.Expr 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.Expr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseIfThenElseExpr.
@Override
public Expr caseIfThenElseExpr(com.rockwellcollins.atc.agree.agree.IfThenElseExpr expr) {
Expr condExpr = doSwitch(expr.getA());
Expr thenExpr = doSwitch(expr.getB());
Expr elseExpr = doSwitch(expr.getC());
Expr result = new IfThenElseExpr(condExpr, thenExpr, elseExpr);
return result;
}
use of jkind.lustre.Expr in project AGREE by loonwerks.
the class AgreeASTBuilder method portToAgreeVar.
private void portToAgreeVar(List<AgreeVar> outputs, List<AgreeVar> inputs, FeatureInstance feature, List<AgreeStatement> assumptions, List<AgreeStatement> guarantees) {
Feature dataFeature = feature.getFeature();
NamedElement dataClass;
if (dataFeature instanceof DataPort) {
DataPort dataPort = (DataPort) dataFeature;
dataClass = dataPort.getDataFeatureClassifier();
} else if (dataFeature instanceof EventDataPort) {
EventDataPort eventDataPort = (EventDataPort) dataFeature;
dataClass = eventDataPort.getDataFeatureClassifier();
} else {
dataClass = null;
}
String name = feature.getName();
boolean isEvent = feature.getCategory() == FeatureCategory.EVENT_DATA_PORT || feature.getCategory() == FeatureCategory.EVENT_PORT;
if (isEvent) {
AgreeVar var = new AgreeVar(name + eventSuffix, NamedType.BOOL, feature.getFeature(), feature.getComponentInstance(), feature);
switch(feature.getDirection()) {
case IN:
inputs.add(var);
break;
case OUT:
outputs.add(var);
break;
default:
throw new AgreeException("Unable to reason about bi-directional event port: " + dataFeature.getQualifiedName());
}
}
if (dataClass == null) {
// we do not reason about this type
return;
}
AgreeTypeSystem.TypeDef td = AgreeTypeSystem.inferFromNamedElement(dataFeature);
Type type = symbolTable.updateLustreTypeMap(td);
if (type == null) {
// we do not reason about this type
return;
}
AgreeVar agreeVar = new AgreeVar(name, type, feature.getFeature(), feature.getComponentInstance(), feature);
switch(feature.getDirection()) {
case IN:
inputs.add(agreeVar);
if (dataClass instanceof DataClassifier) {
List<Expr> constraints = getConstraintsFromTypeDef(name, td);
if (!constraints.isEmpty()) {
assumptions.add(getDataClassifierTypePredicate(feature.getName(), constraints, dataFeature));
}
}
break;
case OUT:
outputs.add(agreeVar);
if (dataClass instanceof DataClassifier) {
List<Expr> constraints = getConstraintsFromTypeDef(name, td);
if (!constraints.isEmpty()) {
guarantees.add(getDataClassifierTypePredicate(feature.getName(), constraints, dataFeature));
}
}
break;
default:
throw new AgreeException("Unable to reason about bi-directional event port: " + dataFeature.getQualifiedName());
}
}
use of jkind.lustre.Expr 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;
}
Aggregations