Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AGREE ConstStatement and EqStatement Recursive Validation Check Required #131

Open
aaurandt opened this issue Aug 18, 2023 · 0 comments
Open

Comments

@aaurandt
Copy link
Contributor

Currently a cyclic expression is checked by performing the following (lines 1856-1865 specifically):

@Check(CheckType.FAST)
public void checkConstStatement(ConstStatement constStat) {
TypeDef expected = AgreeTypeSystem.typeDefFromType(constStat.getType());
TypeDef actual = AgreeTypeSystem.infer(constStat.getExpr());
if (!AgreeTypeSystem.typesEqual(expected, actual)) {
error(constStat, "The assumed type of constant statement '" + constStat.getName() + "' is '"
+ nameOfTypeDef(expected) + "' but the actual type is '" + nameOfTypeDef(actual) + "'");
}
ExprCycleVisitor cycleVisitor = new ExprCycleVisitor();
Set<EObject> cycleObjects = cycleVisitor.doSwitch(constStat.getExpr());
if (cycleObjects == null) {
throw new IllegalArgumentException("something went wrong with the cycle checker");
}
for (EObject obj : cycleObjects) {
if (obj.equals(constStat)) {
error(constStat.getExpr(), "Cyclic reference to variable '" + constStat.getName() + "'");
}
}
for (Expr e : EcoreUtil2.getAllContentsOfType(constStat.getExpr(), Expr.class)) {
if (!exprIsConstant(e)) {
error(e, "Non-constant expression in constant declaration");
return;
}
}
}

The ExprCycleVisitor just goes down the AST, but it does not search for recursive loops. For example, the following code should produce an error, but it does not:

package TestPackage
public

system sys
	annex agree {**
		eq test1 : int = test2 + 10;
		eq test2 : int = test1 - 10;
	**};
end sys;

end TestPackage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant