use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class ExecuteResoluteUtil method executeResoluteFunctionOnce.
/**
* invokes Resolute claim function on targetComponent or targetElement if not null.
* instanceroot is used to initialize the Resolute evaluation context.
* targetComponent is the evaluation context
* targetElement is the model element within the component instance or null.
* parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
* parameterObjects can be null or an empty list.
* The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
* If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
*/
public Diagnostic executeResoluteFunctionOnce(EObject fundef, final SystemInstance instanceroot, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
FunctionDefinition fd = (FunctionDefinition) fundef;
initializeResoluteContext(instanceroot);
EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
// check for claim function
FnCallExpr fcncall = createWrapperFunctionCall(fd, targetComponent, targetElement, parameterObjects);
if (fcncall != null) {
// using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
ResoluteProver prover = new ResoluteProver(context) {
@Override
protected ResoluteEvaluator createResoluteEvaluator() {
return new ResoluteEvaluator(context, varStack.peek()) {
@Override
public ResoluteValue caseThisExpr(ThisExpr object) {
NamedElement curr = context.getThisInstance();
if (object.getSub() != null) {
curr = object.getSub().getBase();
}
return new NamedElementValue(curr);
}
};
}
};
ResoluteResult res = prover.doSwitch(fcncall);
return doResoluteResults(res);
} else {
return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
}
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class UnitLiteralOperations method getAbsoluteFactor.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public static double getAbsoluteFactor(UnitLiteral unitLiteral, UnitLiteral target) {
double factor = 1.0;
if (Aadl2Util.sameUnit(unitLiteral, target)) {
return factor;
}
UnitLiteral current = unitLiteral;
while (current.getBaseUnit() != null && !Aadl2Util.sameUnit(current.getBaseUnit(), current)) {
double val = (current.getFactor() instanceof IntegerLiteral ? (double) ((IntegerLiteral) current.getFactor()).getValue() : ((RealLiteral) current.getFactor()).getValue());
factor *= val;
current = current.getBaseUnit();
if (Aadl2Util.sameUnit(current, target)) {
return factor;
}
}
// did not find target. Let's go in opposite direction
factor = 1.0;
current = target;
while (current.getBaseUnit() != null && !Aadl2Util.sameUnit(current.getBaseUnit(), current)) {
double val = (current.getFactor() instanceof IntegerLiteral ? (double) ((IntegerLiteral) current.getFactor()).getValue() : ((RealLiteral) current.getFactor()).getValue());
factor /= val;
current = current.getBaseUnit();
if (Aadl2Util.sameUnit(current, unitLiteral)) {
return factor;
}
}
return 1.0;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class CommonSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == Aadl2Package.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case Aadl2Package.AADL_BOOLEAN:
sequence_TypeRef(context, (AadlBoolean) semanticObject);
return;
case Aadl2Package.AADL_INTEGER:
sequence_TypeRef(context, (AadlInteger) semanticObject);
return;
case Aadl2Package.AADL_REAL:
sequence_TypeRef(context, (AadlReal) semanticObject);
return;
case Aadl2Package.AADL_STRING:
sequence_TypeRef(context, (AadlString) semanticObject);
return;
case Aadl2Package.BOOLEAN_LITERAL:
sequence_ABooleanLiteral(context, (BooleanLiteral) semanticObject);
return;
case Aadl2Package.INTEGER_LITERAL:
sequence_AIntegerTerm(context, (IntegerLiteral) semanticObject);
return;
case Aadl2Package.REAL_LITERAL:
sequence_ARealTerm(context, (RealLiteral) semanticObject);
return;
case Aadl2Package.STRING_LITERAL:
sequence_StringTerm(context, (StringLiteral) semanticObject);
return;
}
else if (epackage == CommonPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case CommonPackage.ABINARY_OPERATION:
sequence_AAdditiveExpression_AAndExpression_AEqualityExpression_AMultiplicativeExpression_AOrExpression_ARelationalExpression(context, (ABinaryOperation) semanticObject);
return;
case CommonPackage.ACONDITIONAL:
sequence_AIfExpression(context, (AConditional) semanticObject);
return;
case CommonPackage.AFUNCTION_CALL:
sequence_AFunctionCall(context, (AFunctionCall) semanticObject);
return;
case CommonPackage.AMODEL_REFERENCE:
sequence_AModelReference(context, (AModelReference) semanticObject);
return;
case CommonPackage.APROPERTY_REFERENCE:
if (rule == grammarAccess.getAModelOrPropertyReferenceRule() || rule == grammarAccess.getAExpressionRule() || rule == grammarAccess.getAOrExpressionRule() || action == grammarAccess.getAOrExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAAndExpressionRule() || action == grammarAccess.getAAndExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAEqualityExpressionRule() || action == grammarAccess.getAEqualityExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getARelationalExpressionRule() || action == grammarAccess.getARelationalExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAAdditiveExpressionRule() || action == grammarAccess.getAAdditiveExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAMultiplicativeExpressionRule() || action == grammarAccess.getAMultiplicativeExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAUnaryOperationRule() || rule == grammarAccess.getAUnitExpressionRule() || action == grammarAccess.getAUnitExpressionAccess().getAUnitExpressionExpressionAction_1_0() || rule == grammarAccess.getAPrimaryExpressionRule() || rule == grammarAccess.getAParenthesizedExpressionRule()) {
sequence_AModelOrPropertyReference_APropertyReference(context, (APropertyReference) semanticObject);
return;
} else if (rule == grammarAccess.getAPropertyReferenceRule()) {
sequence_APropertyReference(context, (APropertyReference) semanticObject);
return;
} else
break;
case CommonPackage.ARANGE:
sequence_ARangeExpression(context, (ARange) semanticObject);
return;
case CommonPackage.AUNARY_OPERATION:
sequence_AUnaryOperation(context, (AUnaryOperation) semanticObject);
return;
case CommonPackage.AUNIT_EXPRESSION:
if (rule == grammarAccess.getAExpressionRule() || rule == grammarAccess.getAOrExpressionRule() || action == grammarAccess.getAOrExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAAndExpressionRule() || action == grammarAccess.getAAndExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAEqualityExpressionRule() || action == grammarAccess.getAEqualityExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getARelationalExpressionRule() || action == grammarAccess.getARelationalExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAAdditiveExpressionRule() || action == grammarAccess.getAAdditiveExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAMultiplicativeExpressionRule() || action == grammarAccess.getAMultiplicativeExpressionAccess().getABinaryOperationLeftAction_1_0_0_0() || rule == grammarAccess.getAUnaryOperationRule() || rule == grammarAccess.getAUnitExpressionRule() || action == grammarAccess.getAUnitExpressionAccess().getAUnitExpressionExpressionAction_1_0() || rule == grammarAccess.getAPrimaryExpressionRule() || rule == grammarAccess.getAParenthesizedExpressionRule()) {
sequence_AUnitExpression(context, (AUnitExpression) semanticObject);
return;
} else if (rule == grammarAccess.getShowValueRule()) {
sequence_ShowValue(context, (AUnitExpression) semanticObject);
return;
} else
break;
case CommonPackage.AVARIABLE_REFERENCE:
sequence_AVariableReference(context, (AVariableReference) semanticObject);
return;
case CommonPackage.COMPUTE_DECLARATION:
sequence_ComputeDeclaration(context, (ComputeDeclaration) semanticObject);
return;
case CommonPackage.DESCRIPTION:
sequence_Description(context, (Description) semanticObject);
return;
case CommonPackage.DESCRIPTION_ELEMENT:
sequence_DescriptionElement(context, (DescriptionElement) semanticObject);
return;
case CommonPackage.IMAGE_REFERENCE:
sequence_ImageReference(context, (ImageReference) semanticObject);
return;
case CommonPackage.MODEL_REF:
sequence_TypeRef(context, (ModelRef) semanticObject);
return;
case CommonPackage.PROPERTY_REF:
sequence_PropertyRef(context, (PropertyRef) semanticObject);
return;
case CommonPackage.RATIONALE:
sequence_Rationale(context, (Rationale) semanticObject);
return;
case CommonPackage.TYPE_REF:
sequence_TypeRef(context, (TypeRef) semanticObject);
return;
case CommonPackage.UNCERTAINTY:
sequence_Uncertainty(context, (Uncertainty) semanticObject);
return;
case CommonPackage.VAL_DECLARATION:
sequence_ValDeclaration(context, (ValDeclaration) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class InterpreterUtil method compareTo.
public static int compareTo(NumberValue v1, NumberValue v2) {
UnitLiteral minUnit = smallerUnit(v1.getUnit(), v2.getUnit());
if (v1 instanceof IntegerLiteral && v2 instanceof IntegerLiteral) {
Long s1 = (v1.getUnit() == null) ? ((IntegerLiteral) v1).getValue() : Math.round(v1.getScaledValue(minUnit));
Long s2 = (v2.getUnit() == null) ? ((IntegerLiteral) v2).getValue() : Math.round(v2.getScaledValue(minUnit));
return s1.compareTo(s2);
} else {
Double s1 = (v1.getUnit() == null) ? (v1 instanceof IntegerLiteral) ? ((IntegerLiteral) v1).getValue() : ((RealLiteral) v1).getValue() : v1.getScaledValue(minUnit);
Double s2 = (v2.getUnit() == null) ? (v2 instanceof IntegerLiteral) ? ((IntegerLiteral) v2).getValue() : ((RealLiteral) v2).getValue() : v2.getScaledValue(minUnit);
return s1.compareTo(s2);
}
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class InterpreterUtil method ceil.
public static IntegerLiteral ceil(NumberValue nv) {
if (nv instanceof RealLiteral) {
long iv = new Double(Math.ceil(((RealLiteral) nv).getValue())).longValue();
IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
result.setValue(iv);
result.setUnit(nv.getUnit());
return result;
} else {
return (IntegerLiteral) nv;
}
}
Aggregations