use of com.rockwellcollins.atc.agree.agree.ArraySubExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseArraySubExpr.
@Override
public Expr caseArraySubExpr(ArraySubExpr expr) {
// Note: AADL/AGREE arrays are indexed starting at 1, JKind arrays are indexed starting at zero
Expr index = new BinaryExpr(doSwitch(expr.getIndex()), BinaryOp.MINUS, new IntExpr(1));
Expr array = doSwitch(expr.getExpr());
return new ArrayAccessExpr(array, index);
}
use of com.rockwellcollins.atc.agree.agree.ArraySubExpr 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");
}
}
Aggregations