use of com.rockwellcollins.atc.agree.agree.NamedElmExpr in project AGREE by loonwerks.
the class AgreeValidator method checkEventExpr.
@Check(CheckType.FAST)
public void checkEventExpr(EventExpr event) {
if (isInLinearizationBody(event)) {
error(event, "'event' expressions not allowed in linearization body expressions");
return;
}
Expr expr = event.getPort();
NamedElement namedEl = null;
if (expr instanceof NamedElmExpr) {
namedEl = ((NamedElmExpr) expr).getElm();
} else if (expr instanceof SelectionExpr) {
namedEl = ((SelectionExpr) expr).getField();
}
if (namedEl == null || !(namedEl instanceof EventPort || namedEl instanceof EventDataPort)) {
error(event, "Argument of event expression must be an event port or event data port");
}
}
use of com.rockwellcollins.atc.agree.agree.NamedElmExpr in project AMASE by loonwerks.
the class SafetyAnnexContentAssist method getNestedDotIDCandidates.
private List<String> getNestedDotIDCandidates(SelectionExpr id) {
NamedElement base = ((NamedElmExpr) id).getElm();
NamedElement namedEl = null;
if (base instanceof Arg) {
Type type = ((Arg) base).getType();
DoubleDotRef elID = ((DoubleDotRef) type);
namedEl = elID.getElm();
} else if (base instanceof DataPort) {
namedEl = ((DataPort) base).getDataFeatureClassifier();
} else if (base instanceof EventDataPort) {
namedEl = ((EventDataPort) base).getDataFeatureClassifier();
} else if (base instanceof AadlPackage) {
return getNestedDotIDCandidates((AadlPackage) base);
} else {
return new ArrayList<>();
}
return getNestedDotIDCandidates(namedEl);
}
use of com.rockwellcollins.atc.agree.agree.NamedElmExpr in project AGREE by loonwerks.
the class LinearizationRewriter method generateAgreeConstraintForm.
private static NodeDef generateAgreeConstraintForm(LinearizationDef linDef, BoundingSegments segs) {
NodeDef result = af.createNodeDef();
result.setName(getConstraintFormName(AgreeUtils.getNodeName(linDef)));
Arg inputArg = af.createArg();
PrimType inputArgType = af.createPrimType();
inputArgType.setName("real");
inputArg.setType(inputArgType);
inputArg.setName("inp");
result.getArgs().add(inputArg);
Arg outputArg = af.createArg();
PrimType outputArgType = af.createPrimType();
outputArgType.setName("real");
outputArg.setType(outputArgType);
outputArg.setName("result");
result.getArgs().add(outputArg);
Arg constraintArg = af.createArg();
PrimType constraintArgType = af.createPrimType();
constraintArgType.setName("bool");
constraintArg.setType(constraintArgType);
constraintArg.setName("constraint");
result.getRets().add(constraintArg);
NamedElmExpr inputId = af.createNamedElmExpr();
inputId.setElm(EcoreUtil.copy(inputArg));
RealLitExpr domainCheckLowerLit = af.createRealLitExpr();
domainCheckLowerLit.setVal(Double.toString(segs.lower.getFirst().startX));
BinaryExpr domainCheckLowerExpr = af.createBinaryExpr();
domainCheckLowerExpr.setOp("<=");
domainCheckLowerExpr.setLeft(domainCheckLowerLit);
domainCheckLowerExpr.setRight(EcoreUtil.copy(inputId));
RealLitExpr domainCheckUpperLit = af.createRealLitExpr();
domainCheckUpperLit.setVal(Double.toString(segs.lower.getLast().stopX));
BinaryExpr domainCheckUpperExpr = af.createBinaryExpr();
domainCheckUpperExpr.setOp("<=");
domainCheckUpperExpr.setLeft(EcoreUtil.copy(inputId));
domainCheckUpperExpr.setRight(domainCheckUpperLit);
BinaryExpr domainCheckExpr = af.createBinaryExpr();
domainCheckExpr.setOp("and");
domainCheckExpr.setLeft(domainCheckLowerExpr);
domainCheckExpr.setRight(domainCheckUpperExpr);
BoolLitExpr trueLitExpr = af.createBoolLitExpr();
BooleanLiteral trueLitValue = aadlF.createBooleanLiteral();
trueLitValue.setValue(true);
trueLitExpr.setVal(trueLitValue);
Expr upperBoundExpr = EcoreUtil.copy(trueLitExpr);
for (Segment seg : segs.upper) {
BinaryExpr andExpr = af.createBinaryExpr();
andExpr.setOp("and");
andExpr.setLeft(upperBoundExpr);
andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, "<=", seg));
upperBoundExpr = andExpr;
}
Expr lowerBoundExpr = EcoreUtil.copy(trueLitExpr);
for (Segment seg : segs.lower) {
BinaryExpr andExpr = af.createBinaryExpr();
andExpr.setOp("and");
andExpr.setLeft(lowerBoundExpr);
andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, ">=", seg));
lowerBoundExpr = andExpr;
}
BinaryExpr boundsCheckExpr = af.createBinaryExpr();
boundsCheckExpr.setOp("and");
boundsCheckExpr.setLeft(upperBoundExpr);
boundsCheckExpr.setRight(lowerBoundExpr);
BinaryExpr constraintExpr = af.createBinaryExpr();
constraintExpr.setOp("and");
constraintExpr.setLeft(domainCheckExpr);
constraintExpr.setRight(boundsCheckExpr);
NodeEq constraintEq = af.createNodeEq();
constraintEq.getLhs().add(constraintArg);
constraintEq.setExpr(constraintExpr);
NodeBodyExpr nodeBody = af.createNodeBodyExpr();
nodeBody.getStmts().add(constraintEq);
result.setNodeBody(nodeBody);
NodeLemma domainCheckLemma = af.createNodeLemma();
domainCheckLemma.setStr(result.getName() + " domain check");
domainCheckLemma.setExpr(EcoreUtil.copy(domainCheckExpr));
nodeBody.getStmts().add(domainCheckLemma);
return result;
}
use of com.rockwellcollins.atc.agree.agree.NamedElmExpr in project AGREE by loonwerks.
the class LinearizationRewriter method generateAgreeLinearBoundImplicationExpr.
private static Expr generateAgreeLinearBoundImplicationExpr(Arg inputArg, Arg resultArg, String relop, Segment seg) {
RealLitExpr inputMinExpr = af.createRealLitExpr();
inputMinExpr.setVal(Double.toString(seg.startX));
RealLitExpr inputMaxExpr = af.createRealLitExpr();
inputMaxExpr.setVal(Double.toString(seg.stopX));
RealLitExpr resultOriginExpr = af.createRealLitExpr();
resultOriginExpr.setVal(Double.toString(seg.startY));
RealLitExpr resultSlopeExpr = af.createRealLitExpr();
resultSlopeExpr.setVal(Double.toString((seg.stopY - seg.startY) / (seg.stopX - seg.startX)));
NamedElmExpr inputId = af.createNamedElmExpr();
inputId.setElm(EcoreUtil.copy(inputArg));
NamedElmExpr resultId = af.createNamedElmExpr();
resultId.setElm(EcoreUtil.copy(resultArg));
// =======
//
// NestedDotID resultId = af.createNestedDotID();
// resultId.setBase(EcoreUtil.copy(resultArg));
// >>>>>>> origin/develop
BinaryExpr rangeMinExpr = af.createBinaryExpr();
rangeMinExpr.setOp(">=");
rangeMinExpr.setLeft(EcoreUtil.copy(inputId));
rangeMinExpr.setRight(EcoreUtil.copy(inputMinExpr));
BinaryExpr rangeMaxExpr = af.createBinaryExpr();
rangeMaxExpr.setOp("<=");
rangeMaxExpr.setLeft(EcoreUtil.copy(inputId));
rangeMaxExpr.setRight(EcoreUtil.copy(inputMaxExpr));
BinaryExpr rangeExpr = af.createBinaryExpr();
rangeExpr.setOp("and");
rangeExpr.setLeft(EcoreUtil.copy(rangeMinExpr));
rangeExpr.setRight(EcoreUtil.copy(rangeMaxExpr));
BinaryExpr shiftExpr = af.createBinaryExpr();
shiftExpr.setOp("-");
shiftExpr.setLeft(EcoreUtil.copy(inputId));
shiftExpr.setRight(EcoreUtil.copy(inputMinExpr));
BinaryExpr multiplyExpr = af.createBinaryExpr();
multiplyExpr.setOp("*");
multiplyExpr.setLeft(EcoreUtil.copy(resultSlopeExpr));
multiplyExpr.setRight(shiftExpr);
BinaryExpr additionExpr = af.createBinaryExpr();
additionExpr.setOp("+");
additionExpr.setLeft(EcoreUtil.copy(resultOriginExpr));
additionExpr.setRight(multiplyExpr);
BinaryExpr linearBoundExpr = af.createBinaryExpr();
linearBoundExpr.setOp(relop);
linearBoundExpr.setLeft(EcoreUtil.copy(resultId));
linearBoundExpr.setRight(additionExpr);
BinaryExpr result = af.createBinaryExpr();
result.setOp("=>");
result.setLeft(rangeExpr);
result.setRight(linearBoundExpr);
return result;
}
use of com.rockwellcollins.atc.agree.agree.NamedElmExpr in project AGREE by loonwerks.
the class AgreeValidator method checkNodeStmt.
@Check(CheckType.FAST)
public void checkNodeStmt(NodeStmt nodeStmt) {
List<NamedElmExpr> dotIds = EcoreUtil2.getAllContentsOfType(nodeStmt, NamedElmExpr.class);
for (NamedElmExpr dotId : dotIds) {
NamedElement id = dotId.getElm();
// restrict the elements that are single names or the last projection.
boolean restrictedElm = true;
if (dotId.eContainer() instanceof SelectionExpr) {
NamedElement ne = ((SelectionExpr) dotId.eContainer()).getField();
restrictedElm = ne == id && !(dotId.eContainer().eContainer() instanceof SelectionExpr);
}
if (restrictedElm && !(id instanceof Arg) && !(id instanceof ConstStatement) && !(id instanceof NodeDef) && !(id instanceof FnDef) && !(id instanceof UninterpretedFnDef) && !(id instanceof DataSubcomponent) && !(id instanceof DoubleDotRef) && !(id instanceof DataImplementation) && !(id instanceof RecordDef) && !(id instanceof NamedID)) {
error(dotId, "Only arguments, constants, and node calls allowed within a node");
}
}
}
Aggregations