use of com.rockwellcollins.atc.agree.agree.PrimType in project AMASE by loonwerks.
the class SafetyValidator method checkIntervalEqStatement.
/**
* Interval eq stmts:
* Checks:
* - Only primitive types supported for intervals.
* - The interval type matches high and low parameters of interval.
* - High and low parameters of interval are same type.
* @param intervalEq
*/
@Check(CheckType.FAST)
public void checkIntervalEqStatement(IntervalEq intervalEq) {
Arg arg = intervalEq.getLhs_int();
String typeName = "";
SafetyInterval interval = intervalEq.getInterv();
Expr low = interval.getLow();
Expr high = interval.getHigh();
if (arg.getType() instanceof PrimType) {
typeName = ((PrimType) arg.getType()).getName();
if (typeName.equalsIgnoreCase("bool")) {
error(arg, "Boolean intervals are not allowed. Only real or int intervals are supported.");
}
} else {
error(arg, "The only types that are supported for intervals are real and int.");
}
// Negative values are allowed: hence the check for UnaryExpr
if (low instanceof UnaryExpr) {
UnaryExpr unex_low = (UnaryExpr) low;
if (!(unex_low.getExpr() instanceof IntLitExpr) & !(unex_low.getExpr() instanceof RealLitExpr)) {
error(low, "Only real and integer types are supported for intervals.");
}
if (high instanceof UnaryExpr) {
UnaryExpr unex_high = (UnaryExpr) high;
if (!(unex_high.getExpr() instanceof IntLitExpr) & !(unex_high.getExpr() instanceof RealLitExpr)) {
error(high, "Only real and integer types are supported for intervals.");
}
testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), unex_high.getExpr());
} else {
testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), high);
}
} else {
testLowAndHighTypes(intervalEq, typeName, low, high);
}
}
use of com.rockwellcollins.atc.agree.agree.PrimType in project AGREE by loonwerks.
the class LinearizationRewriter method generateAgreeConstraintForm.
private static NodeDef generateAgreeConstraintForm(LinearizationDef linDef, BoundingSegments segs) {
NodeDef result = af.createNodeDef();
result.setName(getConstraintFormName(AgreeUtils.getNodeName(linDef)));
Arg inputArg = af.createArg();
PrimType inputArgType = af.createPrimType();
inputArgType.setName("real");
inputArg.setType(inputArgType);
inputArg.setName("inp");
result.getArgs().add(inputArg);
Arg outputArg = af.createArg();
PrimType outputArgType = af.createPrimType();
outputArgType.setName("real");
outputArg.setType(outputArgType);
outputArg.setName("result");
result.getArgs().add(outputArg);
Arg constraintArg = af.createArg();
PrimType constraintArgType = af.createPrimType();
constraintArgType.setName("bool");
constraintArg.setType(constraintArgType);
constraintArg.setName("constraint");
result.getRets().add(constraintArg);
NamedElmExpr inputId = af.createNamedElmExpr();
inputId.setElm(EcoreUtil.copy(inputArg));
RealLitExpr domainCheckLowerLit = af.createRealLitExpr();
domainCheckLowerLit.setVal(Double.toString(segs.lower.getFirst().startX));
BinaryExpr domainCheckLowerExpr = af.createBinaryExpr();
domainCheckLowerExpr.setOp("<=");
domainCheckLowerExpr.setLeft(domainCheckLowerLit);
domainCheckLowerExpr.setRight(EcoreUtil.copy(inputId));
RealLitExpr domainCheckUpperLit = af.createRealLitExpr();
domainCheckUpperLit.setVal(Double.toString(segs.lower.getLast().stopX));
BinaryExpr domainCheckUpperExpr = af.createBinaryExpr();
domainCheckUpperExpr.setOp("<=");
domainCheckUpperExpr.setLeft(EcoreUtil.copy(inputId));
domainCheckUpperExpr.setRight(domainCheckUpperLit);
BinaryExpr domainCheckExpr = af.createBinaryExpr();
domainCheckExpr.setOp("and");
domainCheckExpr.setLeft(domainCheckLowerExpr);
domainCheckExpr.setRight(domainCheckUpperExpr);
BoolLitExpr trueLitExpr = af.createBoolLitExpr();
BooleanLiteral trueLitValue = aadlF.createBooleanLiteral();
trueLitValue.setValue(true);
trueLitExpr.setVal(trueLitValue);
Expr upperBoundExpr = EcoreUtil.copy(trueLitExpr);
for (Segment seg : segs.upper) {
BinaryExpr andExpr = af.createBinaryExpr();
andExpr.setOp("and");
andExpr.setLeft(upperBoundExpr);
andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, "<=", seg));
upperBoundExpr = andExpr;
}
Expr lowerBoundExpr = EcoreUtil.copy(trueLitExpr);
for (Segment seg : segs.lower) {
BinaryExpr andExpr = af.createBinaryExpr();
andExpr.setOp("and");
andExpr.setLeft(lowerBoundExpr);
andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, ">=", seg));
lowerBoundExpr = andExpr;
}
BinaryExpr boundsCheckExpr = af.createBinaryExpr();
boundsCheckExpr.setOp("and");
boundsCheckExpr.setLeft(upperBoundExpr);
boundsCheckExpr.setRight(lowerBoundExpr);
BinaryExpr constraintExpr = af.createBinaryExpr();
constraintExpr.setOp("and");
constraintExpr.setLeft(domainCheckExpr);
constraintExpr.setRight(boundsCheckExpr);
NodeEq constraintEq = af.createNodeEq();
constraintEq.getLhs().add(constraintArg);
constraintEq.setExpr(constraintExpr);
NodeBodyExpr nodeBody = af.createNodeBodyExpr();
nodeBody.getStmts().add(constraintEq);
result.setNodeBody(nodeBody);
NodeLemma domainCheckLemma = af.createNodeLemma();
domainCheckLemma.setStr(result.getName() + " domain check");
domainCheckLemma.setExpr(EcoreUtil.copy(domainCheckExpr));
nodeBody.getStmts().add(domainCheckLemma);
return result;
}
use of com.rockwellcollins.atc.agree.agree.PrimType in project AGREE by loonwerks.
the class RenamingVisitor method argToString.
private String argToString(Arg arg) {
String result = arg.getName() + " : ";
if (arg.getType() instanceof PrimType) {
PrimType primType = (PrimType) arg.getType();
result += primType.getName();
String lowLit = (primType.getLowNeg() != null) ? primType.getLowNeg() : "";
String highLit = (primType.getHighNeg() != null) ? primType.getHighNeg() : "";
if (primType.getRangeLow() != null) {
result += " [" + lowLit + primType.getRangeLow() + ", " + highLit + primType.getRangeHigh() + "]";
}
} else {
result += ((DoubleDotRef) arg.getType()).getElm().getName();
}
return result;
}
use of com.rockwellcollins.atc.agree.agree.PrimType in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromType.
public static TypeDef typeDefFromType(Type t) {
if (t instanceof PrimType) {
int lowSign = ((PrimType) t).getLowNeg() == null ? 1 : -1;
int highSign = ((PrimType) t).getHighNeg() == null ? 1 : -1;
String lowStr = ((PrimType) t).getRangeLow();
String highStr = ((PrimType) t).getRangeHigh();
if (((PrimType) t).getName().equals("int")) {
if (lowStr == null || highStr == null) {
return Prim.IntTypeDef;
} else {
long low = Long.valueOf(lowStr) * lowSign;
long high = Long.valueOf(highStr) * highSign;
return new RangeIntTypeDef(low, high);
}
} else if (((PrimType) t).getName().equals("real")) {
if (lowStr == null || highStr == null) {
return Prim.RealTypeDef;
} else {
double low = Double.valueOf(lowStr) * lowSign;
double high = Double.valueOf(highStr) * highSign;
return new RangeRealTypeDef(low, high);
}
} else if (((PrimType) t).getName().equals("bool")) {
return Prim.BoolTypeDef;
} else {
return Prim.ErrorTypeDef;
}
} else if (t instanceof ArrayType) {
String size = ((ArrayType) t).getSize();
TypeDef baseTypeDef = typeDefFromType(((ArrayType) t).getStem());
return new ArrayTypeDef(baseTypeDef, Integer.parseInt(size), Optional.empty());
} else if (t instanceof DoubleDotRef) {
return typeDefFromNE(((DoubleDotRef) t).getElm());
} else {
return Prim.ErrorTypeDef;
}
}
Aggregations