use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class InterpreterUtil method multiply.
public static NumberValue multiply(NumberValue v1, NumberValue v2) {
UnitLiteral unit = (v1.getUnit() != null) ? v1.getUnit() : v2.getUnit();
if (v1 instanceof IntegerLiteral && v2 instanceof IntegerLiteral) {
long s1 = ((IntegerLiteral) v1).getValue();
long s2 = ((IntegerLiteral) v2).getValue();
IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
result.setValue(s1 * s2);
result.setUnit(unit);
return result;
} else {
double s1 = (v1 instanceof IntegerLiteral) ? ((IntegerLiteral) v1).getValue() : ((RealLiteral) v1).getValue();
double s2 = (v2 instanceof IntegerLiteral) ? ((IntegerLiteral) v2).getValue() : ((RealLiteral) v2).getValue();
RealLiteral result = Aadl2Factory.eINSTANCE.createRealLiteral();
result.setValue(s1 * s2);
result.setUnit(unit);
return result;
}
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class InterpreterUtil method round.
public static IntegerLiteral round(NumberValue nv) {
if (nv instanceof RealLiteral) {
long iv = Math.round(((RealLiteral) nv).getValue());
IntegerLiteral result = Aadl2Factory.eINSTANCE.createIntegerLiteral();
result.setValue(iv);
result.setUnit(nv.getUnit());
return result;
} else {
return (IntegerLiteral) nv;
}
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class AadlBaParserVisitor method clonePropertyExpression.
private PropertyExpression clonePropertyExpression(PropertyExpression sourcePropertyExpression) {
PropertyExpression targetPropertyExpression = null;
if (sourcePropertyExpression instanceof ListValue) {
ListValue sourceLV = (ListValue) sourcePropertyExpression;
ListValue targetLV = _coreFact.createListValue();
for (PropertyExpression propInList : sourceLV.getOwnedListElements()) {
targetLV.getOwnedListElements().add(clonePropertyExpression(propInList));
}
targetPropertyExpression = targetLV;
} else if (sourcePropertyExpression instanceof StringLiteral) {
StringLiteral sourceSL = (StringLiteral) sourcePropertyExpression;
StringLiteral targetSL = _coreFact.createStringLiteral();
targetSL.setValue(sourceSL.getValue());
targetPropertyExpression = targetSL;
} else if (sourcePropertyExpression instanceof IntegerLiteral) {
IntegerLiteral sourceIL = (IntegerLiteral) sourcePropertyExpression;
IntegerLiteral targetIL = _coreFact.createIntegerLiteral();
targetIL.setValue(sourceIL.getValue());
targetIL.setUnit(sourceIL.getUnit());
targetPropertyExpression = targetIL;
} else if (sourcePropertyExpression instanceof RealLiteral) {
RealLiteral sourceRL = (RealLiteral) sourcePropertyExpression;
RealLiteral targetRL = _coreFact.createRealLiteral();
targetRL.setValue(sourceRL.getValue());
targetRL.setUnit(sourceRL.getUnit());
targetPropertyExpression = targetRL;
} else if (sourcePropertyExpression instanceof RecordValue) {
RecordValue sourceRV = (RecordValue) sourcePropertyExpression;
RecordValue targetRV = _coreFact.createRecordValue();
targetRV.getOwnedFieldValues().addAll(sourceRV.getOwnedFieldValues());
targetPropertyExpression = targetRV;
} else if (sourcePropertyExpression instanceof BooleanLiteral) {
BooleanLiteral sourceBL = (BooleanLiteral) sourcePropertyExpression;
BooleanLiteral targetBL = _coreFact.createBooleanLiteral();
targetBL.setValue(sourceBL.getValue());
targetPropertyExpression = targetBL;
} else if (sourcePropertyExpression instanceof RangeValue) {
RangeValue sourceRV = (RangeValue) sourcePropertyExpression;
RangeValue targetRV = _coreFact.createRangeValue();
targetRV.setMinimum(clonePropertyExpression(sourceRV.getMinimum()));
targetRV.setMaximum(clonePropertyExpression(sourceRV.getMaximum()));
targetPropertyExpression = targetRV;
} else if (sourcePropertyExpression instanceof DeclarativeReferenceValue) {
DeclarativeReferenceValue sourceDRV = (DeclarativeReferenceValue) sourcePropertyExpression;
ReferenceValue targetRV = _coreFact.createReferenceValue();
targetRV.setPath(sourceDRV.getRef());
targetPropertyExpression = targetRV;
} else if (sourcePropertyExpression instanceof DeclarativeClassifierValue) {
DeclarativeClassifierValue sourceDCV = (DeclarativeClassifierValue) sourcePropertyExpression;
ClassifierValue targetCV = _coreFact.createClassifierValue();
targetCV.setClassifier(sourceDCV.getClassifier());
targetPropertyExpression = targetCV;
}
return targetPropertyExpression;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class AadlBaNameResolver method propertyExpressionResolver.
/**
* Resolves the property expressions used in behavior annex.
* @param p
*
* @return {@code true} if all names are resolved. {@code false} otherwise.
*/
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
QualifiedNamedElement qne = (QualifiedNamedElement) p;
String propertyName = "";
boolean hasNamespace = qne.getBaNamespace() != null;
if (hasNamespace) {
propertyName = qne.getBaNamespace().getId() + "::";
}
propertyName += qne.getBaName().getId();
boolean result = true;
if (pe instanceof DeclarativeListValue) {
ListValue dlv = (DeclarativeListValue) pe;
for (PropertyExpression peInList : dlv.getOwnedListElements()) {
result &= propertyExpressionResolver(bv, p, peInList);
}
} else if (pe instanceof IntegerLiteral) {
IntegerLiteral il = (IntegerLiteral) pe;
if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
result &= unitResolver(il, bv, p);
}
} else if (pe instanceof RealLiteral) {
RealLiteral rl = (RealLiteral) pe;
if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
result &= unitResolver(rl, bv, p);
}
} else if (pe instanceof RecordValue) {
RecordValue rv = (RecordValue) pe;
for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
if (bpa instanceof DeclarativeBasicPropertyAssociation) {
DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
String basicPropertyName = dbpa.getBasicPropertyName();
BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
if (basicProp == null) {
_errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
result = false;
}
dbpa.setProperty(basicProp);
}
}
} else if (pe instanceof RangeValue) {
RangeValue rv = (RangeValue) pe;
result &= propertyExpressionResolver(bv, p, rv.getMaximum());
result &= propertyExpressionResolver(bv, p, rv.getMinimum());
} else if (pe instanceof ReferenceValue) {
ReferenceValue rv = (ReferenceValue) pe;
Reference r = (Reference) (rv.getPath());
ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
ContainmentPathElement prevCne = null;
boolean first = true;
Classifier context = _baParentContainer;
for (Identifier subPath : r.getIds()) {
ContainmentPathElement currentCne;
if (!first) {
currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
} else {
currentCne = firstCne;
}
first = false;
NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
if (ne == null) {
ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
}
if (ne == null) {
_errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
result = false;
} else {
currentCne.setNamedElement(ne);
if (prevCne != null) {
prevCne.setPath(currentCne);
}
if (ne instanceof Subcomponent) {
Subcomponent sub = (Subcomponent) ne;
context = sub.getClassifier();
} else if (ne instanceof Feature) {
Feature f = (Feature) ne;
context = f.getClassifier();
}
}
prevCne = currentCne;
}
rv.setPath(firstCne);
} else if (pe instanceof ClassifierValue) {
ClassifierValue cv = (ClassifierValue) pe;
QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
String qneClassPackageName = "";
boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
if (qneClassHasNamespace) {
qneClassPackageName = classifierQne.getBaNamespace().getId();
}
boolean resolved = false;
for (PackageSection context : _contextsTab) {
NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
if (ne != null && ne instanceof Classifier) {
cv.setClassifier((Classifier) ne);
resolved = true;
break;
}
}
if (!resolved) {
String cvQualifiedName = "";
if (!qneClassPackageName.isEmpty()) {
cvQualifiedName += qneClassPackageName + "::";
}
cvQualifiedName += classifierQne.getBaName().getId();
_errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
result = false;
}
}
return result;
}
use of org.osate.aadl2.RealLiteral in project osate2 by osate.
the class ResoluteInterface method addParams.
private void addParams(FnCallExpr call, List<PropertyExpression> params) {
for (PropertyExpression p : params) {
if (p instanceof RealLiteral) {
RealExpr realval = ResoluteFactory.eINSTANCE.createRealExpr();
realval.setVal((RealLiteral) p);
call.getArgs().add(realval);
} else if (p instanceof IntegerLiteral) {
IntExpr intval = ResoluteFactory.eINSTANCE.createIntExpr();
intval.setVal((IntegerLiteral) p);
call.getArgs().add(intval);
} else if (p instanceof StringLiteral) {
StringExpr stringval = ResoluteFactory.eINSTANCE.createStringExpr();
stringval.setVal((StringLiteral) p);
call.getArgs().add(stringval);
} else if (p instanceof BooleanLiteral) {
BoolExpr boolval = ResoluteFactory.eINSTANCE.createBoolExpr();
boolval.setVal((BooleanLiteral) p);
call.getArgs().add(boolval);
} else if (p instanceof InstanceReferenceValue) {
Expr ref = createInstanceObjectReference(((InstanceReferenceValue) p).getReferencedInstanceObject());
call.getArgs().add(ref);
}
}
}
Aggregations