use of jkind.lustre.ArrayAccessExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseFoldLeftExpr.
@Override
public Expr caseFoldLeftExpr(FoldLeftExpr expr) {
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(expr.getArray());
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseFoldLeftExpr");
}
Expr array = doSwitch(expr.getArray());
Expr accExpr = doSwitch(expr.getInitial());
NamedID binding = expr.getBinding();
NamedID accBinding = expr.getAccumulator();
for (int i = 0; i < size; i++) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
accExpr = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess)).accept(new SubstitutionVisitor(accBinding.getName(), accExpr));
}
return accExpr;
}
use of jkind.lustre.ArrayAccessExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method caseForallExpr.
@Override
public Expr caseForallExpr(ForallExpr expr) {
com.rockwellcollins.atc.agree.agree.Expr arrayExpr = expr.getArray();
Expr array = doSwitch(arrayExpr);
AgreeTypeSystem.TypeDef agreeType = AgreeTypeSystem.infer(arrayExpr);
int size = 0;
if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
size = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
} else {
throw new AgreeException("ERROR: caseForallExpr - '" + agreeType.getClass() + "' not handled");
}
NamedID binding = expr.getBinding();
Expr final_expr = new BoolExpr(true);
for (int i = 0; i < size; ++i) {
Expr arrayAccess = new ArrayAccessExpr(array, i);
Expr body = doSwitch(expr.getExpr()).accept(new SubstitutionVisitor(binding.getName(), arrayAccess));
final_expr = LustreExprFactory.makeANDExpr(final_expr, body);
}
return final_expr;
}
use of jkind.lustre.ArrayAccessExpr in project AGREE by loonwerks.
the class AGREESimulationStateElementFactory method addChildElementsForVariable.
private static void addChildElementsForVariable(final Collection<AGREESimulationStateElement> elements, final AGREESimulationStateElement parent, final String variableName, jkind.lustre.Type variableType, final Expr lustreExpr, final Map<String, jkind.lustre.Type> typeIdToTypeMap, final FeatureInstance featureInstance, final EObject declReference, final boolean hidden) {
assert elements != null;
assert variableName != null;
assert variableType != null;
assert lustreExpr != null;
variableType = resolveType(variableType, typeIdToTypeMap);
if (variableType == NamedType.INT || variableType == NamedType.REAL || variableType == NamedType.BOOL) {
elements.add(new AGREESimulationStateElement(parent, variableName, lustreTypeToSimType(variableType), lustreExpr, featureInstance, declReference, hidden));
} else if (variableType instanceof RecordType) {
final AGREESimulationStateElement newElement = new AGREESimulationStateElement(parent, variableName, edu.uah.rsesc.aadlsimulator.VariableType.NONE, null, featureInstance, declReference, hidden);
final RecordType recordType = (RecordType) variableType;
final List<AGREESimulationStateElement> recordElements = new ArrayList<AGREESimulationStateElement>();
for (final Entry<String, jkind.lustre.Type> field : recordType.fields.entrySet()) {
addChildElementsForVariable(recordElements, newElement, field.getKey(), field.getValue(), new RecordAccessExpr(lustreExpr, field.getKey()), typeIdToTypeMap, null, null, hidden);
}
newElement.setChildren(recordElements);
elements.add(newElement);
} else if (variableType instanceof ArrayType) {
final ArrayType arrayType = (ArrayType) variableType;
final Type elementType = arrayType.base;
for (int i = 0; i < arrayType.size; i++) {
// Offset array origin since AGREE/AADL arrays are one based and JKind arrays are 0 based
final String indexStr = "[" + (i + 1) + "]";
addChildElementsForVariable(elements, parent, variableName + indexStr, elementType, new ArrayAccessExpr(lustreExpr, i), typeIdToTypeMap, featureInstance, declReference, hidden);
}
} else {
throw new RuntimeException("Unsupported variable type: " + variableType);
}
}
use of jkind.lustre.ArrayAccessExpr in project AGREE by loonwerks.
the class ExpressionFlattener method flattenArrayExpression.
private static void flattenArrayExpression(final Expr expr, final ArrayType arrayType, final Expr[] results) {
if (expr instanceof ArrayUpdateExpr) {
final ArrayUpdateExpr updateExpr = (ArrayUpdateExpr) expr;
// Handle base array
flattenArrayExpression(updateExpr.array, arrayType, results);
// Handle the update
if (updateExpr.index instanceof IntExpr) {
final BigInteger bigIndex = ((IntExpr) updateExpr.index).value;
try {
final int index = bigIndex.intValueExact();
results[index] = updateExpr.value;
} catch (ArithmeticException ex) {
// Ignore
}
}
} else if (expr instanceof ArrayExpr) {
final ArrayExpr arrayExpr = (ArrayExpr) expr;
final int elementExpressions = Math.min(arrayType.size, arrayExpr.elements.size());
for (int i = 0; i < elementExpressions; i++) {
results[i] = arrayExpr.elements.get(i);
}
} else {
// IdExpr
for (int i = 0; i < arrayType.size; i++) {
results[i] = new ArrayAccessExpr(expr, i);
}
}
}
Aggregations