use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class LatchedExprImpl method basicSetExpr.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetExpr(Expr newExpr, NotificationChain msgs) {
Expr oldExpr = expr;
expr = newExpr;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.LATCHED_EXPR__EXPR, oldExpr, newExpr);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class NodeStmtImpl method basicSetExpr.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetExpr(Expr newExpr, NotificationChain msgs) {
Expr oldExpr = expr;
expr = newExpr;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.NODE_STMT__EXPR, oldExpr, newExpr);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkAssign.
@Check(CheckType.FAST)
public void checkAssign(AssignStatement assign) {
if (!(assign.getId() instanceof NamedElement)) {
error(assign.getId(), "The Id on the left hand side of an assignment statement " + "must not contain a \".\"");
return;
}
NamedElement namedEl = assign.getId();
Expr expr = assign.getExpr();
if (namedEl == null || expr == null) {
return;
}
ComponentImplementation compImpl = EcoreUtil2.getContainerOfType(assign, ComponentImplementation.class);
if (compImpl == null) {
error(assign, "Assignment statements are allowed only in component implementations");
return;
}
if (namedEl.eContainer() instanceof InputStatement) {
error(assign, "Assignment to agree_input variables is illegal.");
return;
}
if (compImpl != null) {
List<EObject> assignableElements = new ArrayList<>();
List<AgreeContract> implContracts = EcoreUtil2.getAllContentsOfType(compImpl, AgreeContract.class);
for (AgreeContract ac : implContracts) {
assignableElements.addAll(EcoreUtil2.getAllContentsOfType(ac, EqStatement.class).stream().map(eq -> eq.getLhs()).flatMap(List::stream).collect(Collectors.toList()));
}
ComponentType compType = compImpl.getType();
if (compType != null) {
List<AgreeContract> typeContracts = EcoreUtil2.getAllContentsOfType(compType, AgreeContract.class);
for (AgreeContract ac : typeContracts) {
assignableElements.addAll(EcoreUtil2.getAllContentsOfType(ac, EqStatement.class).stream().map(eq -> eq.getLhs()).flatMap(List::stream).collect(Collectors.toList()));
}
}
assignableElements.addAll(compImpl.getAllFeatures().stream().map(cf -> flattenFeatureGroups(Collections.singletonList(cf))).flatMap(List::stream).filter(feat -> feat instanceof EventDataPort || feat instanceof DataPort).filter(feat -> DirectionType.OUT.equals(((Port) feat).getDirection())).collect(Collectors.toList()));
if (!assignableElements.contains(namedEl)) {
error("LHS of assignment must be an AGREE 'eq' variable or an output port of this component", assign, AgreePackage.Literals.ASSIGN_STATEMENT__ID);
}
}
TypeDef lhsType = (AgreeTypeSystem.inferFromNamedElement(namedEl));
TypeDef rhsType = (AgreeTypeSystem.infer(expr));
if (!AgreeTypeSystem.typesEqual(lhsType, rhsType)) {
error(assign, "The left hand side of the assignment statement is of type '" + nameOfTypeDef(lhsType) + "' but the right hand side is of type '" + nameOfTypeDef(rhsType) + "'");
}
for (EObject container : EcoreUtil2.getAllContainers(assign)) {
if (container instanceof Classifier) {
for (AnnexSubclause annexSubclause : AnnexUtil.getAllAnnexSubclauses((Classifier) container, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
for (AgreeContract contract : EcoreUtil2.getAllContentsOfType(annexSubclause, AgreeContract.class)) {
if (contract != null) {
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof AssignStatement && spec != assign) {
NamedElement otherEl = ((AssignStatement) spec).getId();
if (otherEl.equals(namedEl)) {
error(spec, "Mulitiple assignments to variable '" + namedEl.getName() + "'");
error(assign, "Mulitiple assignments to variable '" + namedEl.getName() + "'");
}
} else if (spec instanceof EqStatement) {
EqStatement eqStmt = (EqStatement) spec;
for (NamedElement otherEl : eqStmt.getLhs()) {
if (eqStmt.getExpr() != null && otherEl.equals(namedEl)) {
error(spec, "Mulitiple assignments to variable '" + namedEl.getName() + "'");
error(assign, "Mulitiple assignments to variable '" + namedEl.getName() + "'");
}
}
}
}
}
}
}
}
}
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method checkAssert.
@Check(CheckType.FAST)
public void checkAssert(AssertStatement asser) {
Classifier comp = asser.getContainingClassifier();
if (!(comp instanceof ComponentImplementation)) {
error(asser, "Assert statements are allowed only in component implementations.");
}
// the expression could be null if a pattern is used
Expr expr = asser.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(asser, "Expression for assert statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
warning(asser, "We highly discourage the use of assert statements. " + "They can easily lead to inconsistent or unrealizable systems. " + "Note that our realizability check does not verify that component " + "assertions are realizable. It is likely that you can specify the " + "behavior you want by changing the subcomponent contracts or " + "by using assignment statements.");
if (asser.getName() == null) {
info(asser, "It is recommended that assert statements be named." + " (Hint: an identifier may be placed between the \"assert\" keyword and the quoted description.)");
}
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeValidator method isInLinearizationBody.
public static boolean isInLinearizationBody(Expr expr) {
boolean result = false;
EObject current = expr;
while (current != null && current instanceof Expr) {
EObject container = current.eContainer();
if (container instanceof LinearizationDef) {
result = ((LinearizationDef) container).getExprBody().equals(current);
}
current = container;
}
return result;
}
Aggregations