use of com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkArraySubExpr.
@Check(CheckType.FAST)
public void checkArraySubExpr(ArraySubExpr asub) {
Expr arrExp = asub.getExpr();
checkTypeExists(arrExp);
TypeDef arrType = AgreeTypeSystem.infer(arrExp);
Expr index = asub.getIndex();
checkTypeExists(index);
TypeDef indexType = AgreeTypeSystem.infer(index);
if (!AgreeTypeSystem.typesEqual(indexType, AgreeTypeSystem.Prim.IntTypeDef)) {
error(index, "index must be an int");
}
if (arrType instanceof ArrayTypeDef) {
ArrayTypeDef arrayTypeDef = (ArrayTypeDef) arrType;
int arraySize = arrayTypeDef.size;
BigInteger indexValue = evaluateIndexExpr(index);
if (indexValue != null) {
if (!(indexValue.compareTo(BigInteger.ONE) >= 0 && indexValue.compareTo(BigInteger.valueOf(arraySize)) <= 0)) {
error(index, "Index value " + indexValue + " is out of array bounds [1 .. " + arraySize + "]");
}
} else {
warning(index, "Could not statically compute array index value");
}
} else {
error(arrExp, "expression must evaluate to an array");
}
}
use of com.rockwellcollins.atc.agree.AgreeTypeSystem.ArrayTypeDef in project AGREE by loonwerks.
the class AgreeValidator method checkArrayUpdateExpr.
@Check(CheckType.FAST)
public void checkArrayUpdateExpr(ArrayUpdateExpr arrup) {
List<Expr> exprs = arrup.getValueExprs();
Expr arrExpr = arrup.getArray();
checkTypeExists(arrExpr);
TypeDef arrType = AgreeTypeSystem.infer(arrExpr);
if (arrType instanceof ArrayTypeDef) {
TypeDef t = ((ArrayTypeDef) arrType).stemType;
TypeDef elmType = AgreeTypeSystem.infer(exprs.get(0));
if (!AgreeTypeSystem.typesEqual(elmType, t)) {
error(exprs.get(0), "type of element must be " + nameOfTypeDef(elmType) + ", but has type " + nameOfTypeDef(t));
}
} else {
error(arrExpr, "expression must evaluate to an array");
}
}
Aggregations