use of com.rockwellcollins.atc.agree.agree.AssignStatement in project AGREE by loonwerks.
the class AgreeASTBuilder method getAssignmentStatements.
private List<AgreeStatement> getAssignmentStatements(EList<SpecStatement> specs) {
List<AgreeStatement> assigns = new ArrayList<>();
for (SpecStatement spec : specs) {
if (spec instanceof AssignStatement) {
Expr expr = doSwitch(((AssignStatement) spec).getExpr());
NamedElement id = ((AssignStatement) spec).getId();
expr = new BinaryExpr(new IdExpr(id.getName()), BinaryOp.EQUAL, expr);
assigns.add(new AgreeStatement("", expr, spec));
}
}
return assigns;
}
use of com.rockwellcollins.atc.agree.agree.AssignStatement 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() + "'");
}
}
}
}
}
}
}
}
}
}
Aggregations