use of org.osate.aadl2.NamedElement in project VERDICT by ge-high-assurance.
the class Aadl2CsvTranslator method buildScnBusBindingsTable.
/**
* Build the scenario bus bindings table
*/
Table buildScnBusBindingsTable() {
Table scnBusBindingsTable = new Table("Scenario", "Comp", "Impl", "ActualConnectionBindingSrcComp", "ActualConnectionBindingSrcImpl", "ActualConnectionBindingSrcCompInst", "ActualConnectionBindingSrcBusInst", "ActualConnectionBindingDestConnComp", "ActualConnectionBindingDestConnImpl", "ActualConnectionBindingDestConnCompInst", "ActualConnectionBindingDestConn");
for (ComponentImplementation sysImpl : compImpls) {
for (PropertyAssociation propAssoc : sysImpl.getOwnedPropertyAssociations()) {
if (propAssoc.getOwnedValues().size() != 1) {
throw new RuntimeException("Unexpected number of property owned values: " + propAssoc.getOwnedValues().size());
}
PropertyExpression expr = propAssoc.getOwnedValues().get(0).getOwnedValue();
// Obtain the bus reference values
String[] compImplInstBusNames = getStrRepofExpr(expr);
// We only consider the case where the length of compImplInstBusNames is 4
if (compImplInstBusNames.length != 4) {
throw new RuntimeException("Unexpected number of values in property expression: " + compImplInstBusNames.length);
}
// property: bus connection binding applies to connections
for (ContainedNamedElement appliesToImpl : propAssoc.getAppliesTos()) {
PortConnection appliesToConn = null;
SystemSubcomponent appliesToSubcomp = null;
scnBusBindingsTable.addValue(scenario);
scnBusBindingsTable.addValue(sysImpl.getTypeName());
scnBusBindingsTable.addValue(sysImpl.getName());
scnBusBindingsTable.addValue(compImplInstBusNames[0]);
scnBusBindingsTable.addValue(compImplInstBusNames[1]);
scnBusBindingsTable.addValue(compImplInstBusNames[2]);
scnBusBindingsTable.addValue(compImplInstBusNames[3]);
if (appliesToImpl.getContainmentPathElements().size() > 2) {
throw new RuntimeException("Unexpected number of values in ContainedNamedElement: " + appliesToImpl.getContainmentPathElements().size());
}
for (ContainmentPathElement element : appliesToImpl.getContainmentPathElements()) {
NamedElement namedElement = element.getNamedElement();
if (namedElement instanceof SystemSubcomponent) {
appliesToSubcomp = (SystemSubcomponent) namedElement;
} else if (namedElement instanceof PortConnection) {
appliesToConn = (PortConnection) namedElement;
} else {
throw new RuntimeException("Unexpected value: " + namedElement);
}
}
if (appliesToSubcomp != null) {
ComponentImplementation compImpl = appliesToSubcomp.getComponentImplementation();
scnBusBindingsTable.addValue(compImpl.getTypeName());
scnBusBindingsTable.addValue(compImpl.getName());
scnBusBindingsTable.addValue(appliesToSubcomp.getName());
} else {
scnBusBindingsTable.addValue(sysImpl.getTypeName());
scnBusBindingsTable.addValue(sysImpl.getName());
scnBusBindingsTable.addValue("");
}
scnBusBindingsTable.addValue(appliesToConn.getName());
scnBusBindingsTable.capRow();
}
}
}
return scnBusBindingsTable;
}
use of org.osate.aadl2.NamedElement in project VERDICT by ge-high-assurance.
the class Agree2Vdm method getVdmExpressionFromAgreeExpression.
// method to translate expression in Agree to expression in vdm
private Expression getVdmExpressionFromAgreeExpression(Expr agreeExpr, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl, Model model) {
Expression vdmExpr = new Expression();
if (agreeExpr instanceof IfThenElseExpr) {
IfThenElseExpr ifexpr = (IfThenElseExpr) agreeExpr;
// for vdm model
IfThenElse ifThenElseVal = new IfThenElse();
Expression condExpr = getVdmExpressionFromAgreeExpression(ifexpr.getA(), dataTypeDecl, nodeDecl, model);
ifThenElseVal.setCondition(condExpr);
Expression thenBranchExpr = getVdmExpressionFromAgreeExpression(ifexpr.getB(), dataTypeDecl, nodeDecl, model);
ifThenElseVal.setThenBranch(thenBranchExpr);
Expression elseBranchExpr = getVdmExpressionFromAgreeExpression(ifexpr.getC(), dataTypeDecl, nodeDecl, model);
ifThenElseVal.setElseBranch(elseBranchExpr);
vdmExpr.setConditionalExpression(ifThenElseVal);
} else if (agreeExpr instanceof CallExpr) {
CallExpr callExpr = (CallExpr) agreeExpr;
DoubleDotRef ddref = (DoubleDotRef) callExpr.getRef();
if (ddref.getElm() instanceof NodeDef) {
NodeDef nodeDef = (NodeDef) ddref.getElm();
addNodeDefToTypeDeclarations(nodeDef, dataTypeDecl, nodeDecl, model);
// create node call in vdm model
NodeCall vdmNodeCall = new NodeCall();
// setting node name
vdmNodeCall.setNodeId(nodeDef.getName());
EList<Expr> callExprArgs = callExpr.getArgs();
// below are the parameters passed to the function call
for (Expr callExprArg : callExprArgs) {
Expression argExpr = getVdmExpressionFromAgreeExpression(callExprArg, dataTypeDecl, nodeDecl, model);
// setting node arguments
vdmNodeCall.getArgument().add(argExpr);
}
vdmExpr.setCall(vdmNodeCall);
} else {
System.out.println("Unmapped Typed");
}
} else if (agreeExpr instanceof NamedElmExpr) {
NamedElmExpr nmExpr = (NamedElmExpr) agreeExpr;
vdmExpr.setIdentifier(nmExpr.getElm().getName());
// define corresponding types in the VDM if not already defined
if (nmExpr.getElm() instanceof Arg) {
Arg nmElmArg = (Arg) nmExpr.getElm();
// define corresponding type in the VDM if not already defined
Type argType = nmElmArg.getType();
defineDataTypeDataImplementationTypeInVDM(argType, dataTypeDecl, model);
} else if (nmExpr.getElm() instanceof Port) {
Port nmElmPort = (Port) nmExpr.getElm();
// define corresponding type in the VDM if not already defined
if (nmElmPort instanceof DataPortImpl) {
DataPort nmElmDataPort = (DataPort) nmElmPort;
DataSubcomponentType dSubCompType = nmElmDataPort.getDataFeatureClassifier();
defineDataTypeDataImplementationTypeInVDM(dSubCompType, dataTypeDecl, model);
} else if (nmElmPort instanceof EventDataPortImpl) {
EventDataPort nmElmDataPort = (EventDataPort) nmElmPort;
DataSubcomponentType dSubCompType = nmElmDataPort.getDataFeatureClassifier();
defineDataTypeDataImplementationTypeInVDM(dSubCompType, dataTypeDecl, model);
} else {
if (!(nmElmPort instanceof EventPort)) {
System.out.println("Unresolved Port Type");
}
}
} else if (nmExpr.getElm() instanceof ConstStatement) {
ConstStatement nmElmConstStatement = (ConstStatement) nmExpr.getElm();
String nmElmConstStatementName = nmElmConstStatement.getName();
// add const declaration to VDM if not already defined
if (!dataTypeDecl.contains(nmElmConstStatementName)) {
dataTypeDecl.add(nmElmConstStatementName);
ConstantDeclaration vdmConstDeclaration = new ConstantDeclaration();
vdmConstDeclaration.setName(nmElmConstStatementName);
vdmConstDeclaration.setDefinition(getVdmExpressionFromAgreeExpression(nmElmConstStatement.getExpr(), dataTypeDecl, nodeDecl, model));
vdmConstDeclaration.setDataType(getVdmTypeFromAgreeType(nmElmConstStatement.getType(), dataTypeDecl, model));
LustreProgram lustreProgram = model.getDataflowCode();
lustreProgram.getConstantDeclaration().add(vdmConstDeclaration);
model.setDataflowCode(lustreProgram);
}
} else {
System.out.println("Unresolved/unmapped NamedExprElm: " + nmExpr.getElm().getName());
}
} else if (agreeExpr instanceof SelectionExpr) {
// selection expression corresponds to record projection in VDM
RecordProjection vdmRecordProj = new RecordProjection();
SelectionExpr selExpr = (SelectionExpr) agreeExpr;
if (selExpr.getField() == null) {
System.out.println("Null Selection Expr field: " + selExpr.getField());
} else {
NamedElement field = selExpr.getField();
// set record-projection's reference
if (selExpr.getTarget() != null) {
// target can be NamedElmExpr or a SelectionExpr
vdmRecordProj.setRecordReference(getVdmExpressionFromAgreeExpression(selExpr.getTarget(), dataTypeDecl, nodeDecl, model));
}
// set record-projection's field id
vdmRecordProj.setFieldId(field.getName());
// also set the name of the field's type as the record-projection's record-type
if (field instanceof DataPortImpl) {
DataPort dport = (DataPort) field;
DataSubcomponentType dSubCompType = dport.getDataFeatureClassifier();
defineDataTypeDataImplementationTypeInVDM(dSubCompType, dataTypeDecl, model);
vdmRecordProj.setRecordType(dSubCompType.getName());
} else if (field instanceof DataSubcomponentImpl) {
DataSubcomponent dSubComp = (DataSubcomponent) field;
DataSubcomponentType dSubCompType = dSubComp.getDataSubcomponentType();
defineDataTypeDataImplementationTypeInVDM(dSubCompType, dataTypeDecl, model);
vdmRecordProj.setRecordType(dSubCompType.getName());
} else if (field instanceof ArgImpl) {
Arg arg = (Arg) field;
Type argType = arg.getType();
defineDataTypeDataImplementationTypeInVDM(argType, dataTypeDecl, model);
if (argType instanceof PrimType) {
vdmRecordProj.setRecordType(getDataTypeName(argType));
} else {
System.out.println("Unresolved Arg Type so not setting record-type in record-projection.");
}
} else {
System.out.println("Unresolved type of field.");
}
}
vdmExpr.setRecordProjection(vdmRecordProj);
} else if (agreeExpr instanceof BinaryExpr) {
BinaryExpr binExpr = (BinaryExpr) agreeExpr;
// for vdm
BinaryOperation binoper = new BinaryOperation();
// set left operand
Expression leftOperand = getVdmExpressionFromAgreeExpression(binExpr.getLeft(), dataTypeDecl, nodeDecl, model);
binoper.setLhsOperand(leftOperand);
// set right operand
Expression rightOperand = getVdmExpressionFromAgreeExpression(binExpr.getRight(), dataTypeDecl, nodeDecl, model);
binoper.setRhsOperand(rightOperand);
// set appropriate operator
String operator = binExpr.getOp();
if (operator.equalsIgnoreCase("->")) {
vdmExpr.setArrow(binoper);
} else if (operator.equalsIgnoreCase("=>")) {
vdmExpr.setImplies(binoper);
} else if (operator.equalsIgnoreCase("and")) {
vdmExpr.setAnd(binoper);
} else if (operator.equalsIgnoreCase("or")) {
vdmExpr.setOr(binoper);
} else if (operator.equalsIgnoreCase("=")) {
vdmExpr.setEqual(binoper);
} else if (operator.equalsIgnoreCase(">")) {
vdmExpr.setGreaterThan(binoper);
} else if (operator.equalsIgnoreCase("<")) {
vdmExpr.setLessThan(binoper);
} else if (operator.equalsIgnoreCase(">=")) {
vdmExpr.setGreaterThanOrEqualTo(binoper);
} else if (operator.equalsIgnoreCase("<=")) {
vdmExpr.setLessThanOrEqualTo(binoper);
} else if (operator.equalsIgnoreCase("+")) {
vdmExpr.setPlus(binoper);
} else if (operator.equalsIgnoreCase("-")) {
vdmExpr.setMinus(binoper);
} else if (operator.equalsIgnoreCase("!=") || operator.equalsIgnoreCase("<>")) {
vdmExpr.setNotEqual(binoper);
} else if (operator.equalsIgnoreCase("/")) {
vdmExpr.setDiv(binoper);
} else if (operator.equalsIgnoreCase("*")) {
vdmExpr.setTimes(binoper);
} else {
System.out.println("Unmapped binary operator: " + operator);
}
} else if (agreeExpr instanceof UnaryExpr) {
UnaryExpr unExpr = (UnaryExpr) agreeExpr;
Expression singleOperand = getVdmExpressionFromAgreeExpression(unExpr.getExpr(), dataTypeDecl, nodeDecl, model);
String operator = unExpr.getOp();
if (operator.equalsIgnoreCase("this")) {
vdmExpr.setCurrent(singleOperand);
} else if (operator.equalsIgnoreCase("not")) {
vdmExpr.setNot(singleOperand);
} else if (operator.equalsIgnoreCase("-")) {
vdmExpr.setNegative(singleOperand);
} else {
System.out.println("Unmapped unary operator.");
}
} else if (agreeExpr instanceof BoolLitExpr) {
BoolLitExpr boolExpr = (BoolLitExpr) agreeExpr;
vdmExpr.setBoolLiteral(boolExpr.getVal().getValue());
} else if (agreeExpr instanceof EnumLitExpr) {
EnumLitExpr enumExpr = (EnumLitExpr) agreeExpr;
// check if elm is DataImplementationImpl or DataTypeImpl -- if yes add definition to type declarations if not already present
DoubleDotRef enumType = enumExpr.getEnumType();
if (enumType.getElm() instanceof DataTypeImpl) {
org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) enumType.getElm();
resolveAADLDataType(aadlDType, dataTypeDecl, model);
} else {
System.out.println("Unexpected Elm type for EnumLitExpr");
}
vdmExpr.setIdentifier(enumExpr.getValue());
} else if (agreeExpr instanceof PreExpr) {
PreExpr preExpr = (PreExpr) agreeExpr;
Expression expr = getVdmExpressionFromAgreeExpression(preExpr.getExpr(), dataTypeDecl, nodeDecl, model);
vdmExpr.setPre(expr);
} else if (agreeExpr instanceof RecordLitExpr) {
RecordLiteral vdmRecordLiteral = new RecordLiteral();
RecordLitExpr recLitExpr = (RecordLitExpr) agreeExpr;
if (recLitExpr.getRecordType() instanceof DoubleDotRef) {
DoubleDotRef recType = (DoubleDotRef) recLitExpr.getRecordType();
if (recType.getElm().getName() != null) {
// check if elm is DataImplementationImpl -- if yes add definition to type declarations if not already present
if (recType.getElm() instanceof DataImplementation) {
org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) recType.getElm();
resolveAADLDataImplementationType(aadlDImpl, dataTypeDecl, model);
} else {
System.out.println("Unexpected Elm type for EnumLitExpr");
}
// set name of the record literal in the vdm model
vdmRecordLiteral.setRecordType(recType.getElm().getName());
// get args and arg-expr and set them as field identifier and value in the vdm model
EList<NamedElement> recLitArgs = recLitExpr.getArgs();
EList<Expr> recLitArgsExpr = recLitExpr.getArgExpr();
// below are the values set to variable
for (int ind = 0; ind < recLitArgs.size(); ind++) {
FieldDefinition fieldDef = new FieldDefinition();
fieldDef.setFieldIdentifier(recLitArgs.get(ind).getName());
fieldDef.setFieldValue(getVdmExpressionFromAgreeExpression(recLitArgsExpr.get(ind), dataTypeDecl, nodeDecl, model));
// set field definitions in the record literal in the vdm model
vdmRecordLiteral.getFieldDefinition().add(fieldDef);
}
vdmExpr.setRecordLiteral(vdmRecordLiteral);
} else {
System.out.println("Unexpected Literal's Record Type that has null named elm.");
}
} else {
System.out.println("Unresolved or unmapped record literal expression.");
}
} else if (agreeExpr instanceof IntLitExpr) {
IntLitExpr intLitExpr = (IntLitExpr) agreeExpr;
BigInteger bigInt = new BigInteger(intLitExpr.getVal());
vdmExpr.setIntLiteral(bigInt);
} else if (agreeExpr instanceof RealLitExpr) {
RealLitExpr realLitExpr = (RealLitExpr) agreeExpr;
BigDecimal bigDecimal = new BigDecimal(realLitExpr.getVal());
vdmExpr.setRealLiteral(bigDecimal);
} else if (agreeExpr instanceof EventExpr) {
EventExpr eventExpr = (EventExpr) agreeExpr;
if (eventExpr.getPort() != null) {
vdmExpr.setEvent(getVdmExpressionFromAgreeExpression(eventExpr.getPort(), dataTypeDecl, nodeDecl, model));
} else {
System.out.println("EventExpr does not have port infornation.");
}
} else if (agreeExpr instanceof RealCast) {
RealCast realCastExpr = (RealCast) agreeExpr;
vdmExpr.setToReal(getVdmExpressionFromAgreeExpression(realCastExpr.getExpr(), dataTypeDecl, nodeDecl, model));
} else {
System.out.println("Unresolved/umapped agree expr" + agreeExpr.toString());
}
return vdmExpr;
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeASTBuilder method caseRecordLitExpr.
@Override
public Expr caseRecordLitExpr(RecordLitExpr recExpr) {
EList<NamedElement> agreeArgs = recExpr.getArgs();
EList<com.rockwellcollins.atc.agree.agree.Expr> agreeArgExprs = recExpr.getArgExpr();
Map<String, Expr> argExprMap = new HashMap<>();
for (int i = 0; i < agreeArgs.size(); i++) {
NamedElement agreeArg = agreeArgs.get(i);
com.rockwellcollins.atc.agree.agree.Expr agreeExpr = agreeArgExprs.get(i);
Expr lustreExpr = doSwitch(agreeExpr);
String argName = agreeArg.getName();
argExprMap.put(argName, lustreExpr);
}
DoubleDotRef recId = recExpr.getRecordType();
String recName = recId.getElm().getQualifiedName().replace("::", "__").replace(".", dotChar);
return new jkind.lustre.RecordExpr(recName, argExprMap);
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeASTBuilder method caseTimeOfExpr.
@Override
public Expr caseTimeOfExpr(TimeOfExpr timeExpr) {
NamedElement namedEl = timeExpr.getId();
String idStr = namedEl.getName();
AgreeVar var = timeOfVarMap.get(idStr);
if (var == null) {
String varStr = idStr + AgreePatternTranslator.TIME_SUFFIX;
var = new AgreeVar(varStr, NamedType.REAL, namedEl);
timeOfVarMap.put(idStr, var);
}
return new IdExpr(var.id);
}
use of org.osate.aadl2.NamedElement in project AGREE by loonwerks.
the class AgreeASTBuilder method portToAgreeVar.
private void portToAgreeVar(List<AgreeVar> outputs, List<AgreeVar> inputs, FeatureInstance feature, List<AgreeStatement> assumptions, List<AgreeStatement> guarantees) {
Feature dataFeature = feature.getFeature();
NamedElement dataClass;
if (dataFeature instanceof DataPort) {
DataPort dataPort = (DataPort) dataFeature;
dataClass = dataPort.getDataFeatureClassifier();
} else if (dataFeature instanceof EventDataPort) {
EventDataPort eventDataPort = (EventDataPort) dataFeature;
dataClass = eventDataPort.getDataFeatureClassifier();
} else {
dataClass = null;
}
String name = feature.getName();
boolean isEvent = feature.getCategory() == FeatureCategory.EVENT_DATA_PORT || feature.getCategory() == FeatureCategory.EVENT_PORT;
if (isEvent) {
AgreeVar var = new AgreeVar(name + eventSuffix, NamedType.BOOL, feature.getFeature(), feature.getComponentInstance(), feature);
switch(feature.getDirection()) {
case IN:
inputs.add(var);
break;
case OUT:
outputs.add(var);
break;
default:
throw new AgreeException("Unable to reason about bi-directional event port: " + dataFeature.getQualifiedName());
}
}
if (dataClass == null) {
// we do not reason about this type
return;
}
AgreeTypeSystem.TypeDef td = AgreeTypeSystem.inferFromNamedElement(dataFeature);
Type type = symbolTable.updateLustreTypeMap(td);
if (type == null) {
// we do not reason about this type
return;
}
AgreeVar agreeVar = new AgreeVar(name, type, feature.getFeature(), feature.getComponentInstance(), feature);
switch(feature.getDirection()) {
case IN:
inputs.add(agreeVar);
if (dataClass instanceof DataClassifier) {
List<Expr> constraints = getConstraintsFromTypeDef(name, td);
if (!constraints.isEmpty()) {
assumptions.add(getDataClassifierTypePredicate(feature.getName(), constraints, dataFeature));
}
}
break;
case OUT:
outputs.add(agreeVar);
if (dataClass instanceof DataClassifier) {
List<Expr> constraints = getConstraintsFromTypeDef(name, td);
if (!constraints.isEmpty()) {
guarantees.add(getDataClassifierTypePredicate(feature.getName(), constraints, dataFeature));
}
}
break;
default:
throw new AgreeException("Unable to reason about bi-directional event port: " + dataFeature.getQualifiedName());
}
}
Aggregations