use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkArrayLiteralExpr.
@Check(CheckType.FAST)
public void checkArrayLiteralExpr(ArrayLiteralExpr alit) {
// =======
// public void checkRecordType(RecordType recType) {
// DoubleDotRef recId = recType.getRecord();
// NamedElement finalId = recId.getElm();
// >>>>>>> origin/develop
List<Expr> exprs = alit.getElems();
if (exprs.size() == 0) {
error(alit, "Array literal must have at least one element");
}
Expr target = exprs.get(0);
checkTypeExists(target);
TypeDef t1 = AgreeTypeSystem.infer(target);
for (Expr e : exprs) {
checkTypeExists(e);
TypeDef t2 = AgreeTypeSystem.infer(e);
if (!AgreeTypeSystem.typesEqual(t1, t2)) {
error(e, "type of element must be " + nameOfTypeDef(t1) + ", but has type " + nameOfTypeDef(t2));
}
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AMASE by loonwerks.
the class SafetyScopeProvider method scope_RecordUpdateExpr_key.
IScope scope_RecordUpdateExpr_key(RecordUpdateExpr ctx, EReference ref) {
IScope prevScope = prevScope(ctx, ref);
TypeDef typ = AgreeTypeSystem.infer(ctx.getRecord());
if (typ instanceof RecordTypeDef) {
NamedElement ne = ((RecordTypeDef) typ).namedElement;
return Scopes.scopeFor(getFieldsOfNE(ne), prevScope);
} else {
return IScope.NULLSCOPE;
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef in project AGREE by loonwerks.
the class AgreeScopeProvider method scope_RecordUpdateExpr_key.
IScope scope_RecordUpdateExpr_key(RecordUpdateExpr ctx, EReference ref) {
IScope prevScope = prevScope(ctx, ref);
TypeDef typ = AgreeTypeSystem.infer(ctx.getRecord());
if (typ instanceof RecordTypeDef) {
NamedElement ne = ((RecordTypeDef) typ).namedElement;
return Scopes.scopeFor(getFieldsOfNE(ne), prevScope);
} else {
return IScope.NULLSCOPE;
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef 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.AgreeTypeSystem.TypeDef 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.)");
}
}
Aggregations