use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.
the class OperationImpl method evaluate.
public EvaluatedProperty evaluate(EvaluationContext ctx, int depth) throws InvalidModelException {
if (ownedPropertyExpressions.size() < 1) {
throw new InvalidModelException(ctx.getInstanceObject(), "Property expression has no operands");
}
EvaluatedProperty left = ownedPropertyExpressions.get(0).evaluate(ctx, depth);
EvaluatedProperty right = null;
PropertyExpression arg1 = null;
PropertyExpression arg2 = null;
if (left.size() == 0) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
}
if (left.size() != 1 || left.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
}
arg1 = left.first().getValue();
if (arg1 == null) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
}
// check for required arguments to operation
switch(op) {
case AND:
case OR:
if (ownedPropertyExpressions.size() < 2) {
throw new InvalidModelException(ctx.getInstanceObject(), "Second operand missing for binary operation");
}
if (ownedPropertyExpressions.size() > 2) {
throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
}
right = ownedPropertyExpressions.get(1).evaluate(ctx, depth);
if (right.size() != 1 || right.first().isModal()) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to operation cannot be modal");
}
if (right.size() == 0) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument has no value");
}
arg2 = right.first().getValue();
if (arg2 == null) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument missing");
}
break;
default:
if (ownedPropertyExpressions.size() > 1) {
throw new InvalidModelException(ctx.getInstanceObject(), "Too many operands in expression");
}
break;
}
// check argument types
switch(op) {
case NOT:
if (!(arg1 instanceof BooleanLiteral)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument to NOT does not evaluate to a boolean value");
}
// fall through!
case AND:
case OR:
if (!(arg2 instanceof BooleanLiteral)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Second argument does not evaluate to a boolean value");
}
break;
default:
if (!(arg1 instanceof NumberValue)) {
throw new InvalidModelException(ctx.getInstanceObject(), "Argument does not evaluate to a numeric value");
}
break;
}
// calculate result
EvaluatedProperty result = null;
switch(op) {
case AND:
BooleanLiteral abv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
abv.setValue(((BooleanLiteral) arg1).getValue() && ((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(abv);
break;
case OR:
BooleanLiteral obv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
obv.setValue(((BooleanLiteral) arg1).getValue() || ((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(obv);
break;
case NOT:
BooleanLiteral nbv = Aadl2Factory.eINSTANCE.createBooleanLiteral();
nbv.setValue(!((BooleanLiteral) arg1).getValue());
result = new EvaluatedProperty(nbv);
break;
case PLUS:
result = left;
break;
case MINUS:
result = new EvaluatedProperty(((NumberValue) arg1).cloneAndInvert());
break;
default:
throw new AssertionError("Unexpected enum literal: " + getOp());
}
return result;
}
use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.
the class Arinc653 method getSystemPartition.
public static Optional<Boolean> getSystemPartition(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getSystemPartition_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((BooleanLiteral) resolved).getValue());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.
the class CodeGenerationProperties method getReturnParameter.
public static Optional<Boolean> getReturnParameter(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getReturnParameter_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((BooleanLiteral) resolved).getValue());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.
the class Sei method getBroadcastProtocol.
public static Optional<Boolean> getBroadcastProtocol(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getBroadcastProtocol_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((BooleanLiteral) resolved).getValue());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.BooleanLiteral in project osate2 by osate.
the class Sei method getIsPartition.
public static Optional<Boolean> getIsPartition(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getIsPartition_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((BooleanLiteral) resolved).getValue());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
Aggregations