use of jkind.lustre.ArrayType in project AGREE by loonwerks.
the class ExpressionFlattener method flattenEqualsExpression.
private void flattenEqualsExpression(final BinaryExpr expr, final List<BinaryExpr> results) {
// Assume that both sides of the binary expression are the same type
final Type leftType = expr.left.accept(typeReconstructor);
if (leftType instanceof ArrayType) {
flattenArrayEquality(expr, (ArrayType) leftType, results);
} else if (leftType instanceof RecordType) {
flattenRecordEquality(expr, (RecordType) leftType, results);
} else if (leftType instanceof NamedType) {
// Flatten both sides of the expression
final Expr newLeft = flattenExpression(expr.left);
final Expr newRight = flattenExpression(expr.right);
if (newLeft != null && newRight != null) {
results.add(new BinaryExpr(newLeft, expr.op, newRight));
}
}
}
use of jkind.lustre.ArrayType 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.ArrayType in project AGREE by loonwerks.
the class TypeTable method getLustreType.
public Type getLustreType(AgreeTypeSystem.TypeDef agreeType) {
if (agreeType == AgreeTypeSystem.Prim.IntTypeDef) {
return NamedType.INT;
} else if (agreeType == AgreeTypeSystem.Prim.RealTypeDef) {
return NamedType.REAL;
} else if (agreeType == AgreeTypeSystem.Prim.BoolTypeDef) {
return NamedType.BOOL;
} else if (agreeType instanceof AgreeTypeSystem.RangeIntTypeDef) {
return NamedType.INT;
} else if (agreeType instanceof AgreeTypeSystem.RangeRealTypeDef) {
return NamedType.REAL;
} else if (agreeType instanceof AgreeTypeSystem.RecordTypeDef) {
String name = ((AgreeTypeSystem.RecordTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
Map<String, AgreeTypeSystem.TypeDef> agreeFields = ((AgreeTypeSystem.RecordTypeDef) agreeType).fields;
Map<String, Type> lustreFields = new HashMap<>();
for (Entry<String, AgreeTypeSystem.TypeDef> entry : agreeFields.entrySet()) {
String key = entry.getKey();
Type lt = updateLustreTypeMap(entry.getValue());
if (lt != null) {
lustreFields.put(key, lt);
}
}
RecordType lustreRecType = new RecordType(name, lustreFields);
return lustreRecType;
} else if (agreeType instanceof AgreeTypeSystem.EnumTypeDef) {
String name = ((AgreeTypeSystem.EnumTypeDef) agreeType).name.replace("::", "__").replace(".", "__");
List<String> enumValues = new ArrayList<String>();
for (String raw : ((AgreeTypeSystem.EnumTypeDef) agreeType).values) {
String enumValue = raw.replace("::", "__").replace(".", "__");
enumValues.add(enumValue);
}
EnumType lustreEnumType = new EnumType(name, enumValues);
return lustreEnumType;
} else if (agreeType instanceof AgreeTypeSystem.ArrayTypeDef) {
AgreeTypeSystem.TypeDef agreeBaseType = ((AgreeTypeSystem.ArrayTypeDef) agreeType).stemType;
int dimension = ((AgreeTypeSystem.ArrayTypeDef) agreeType).size;
Type lustreBaseType = updateLustreTypeMap(agreeBaseType);
if (lustreBaseType != null) {
ArrayType lustreArrayType = new ArrayType(lustreBaseType, dimension);
return lustreArrayType;
}
}
// Jkind does not reason over this.
return null;
}
Aggregations