use of com.rockwellcollins.atc.agree.agree.AgreeContract in project VERDICT by ge-high-assurance.
the class Agree2Vdm method translateAgreeAnnex.
private Model translateAgreeAnnex(List<SystemType> systemTypes, List<SystemImplementation> systemImpls, Model model, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl) {
LustreProgram lustreProgram = new LustreProgram();
// Initializing the lustre program in the VDM
model.setDataflowCode(lustreProgram);
// System.out.println("Processing "+systemTypes.size()+" SystemTypes for agree annexes");
for (SystemType sysType : systemTypes) {
// unpacking sysType
for (AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("agree")) {
// annex is of type DefaultAnnexSubclause
DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
// AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
// populating agree contracts in the vdm component type -- SHOULD ADD THIS CODE TO AADL2VDM
verdict.vdm.vdm_lustre.ContractSpec contractSpec = new verdict.vdm.vdm_lustre.ContractSpec();
EList<EObject> annexContents = agreeAnnex.eContents();
if (annexContents.isEmpty()) {
System.out.println("Empty Agree Annex.");
}
for (EObject clause : annexContents) {
// mapping to AgreeContractclause
AgreeContract agreeContract = (AgreeContract) clause;
// getting specStatements
EList<SpecStatement> specStatements = agreeContract.getSpecs();
for (SpecStatement specStatement : specStatements) {
if (specStatement instanceof EqStatement) {
EqStatement eqStmt = (EqStatement) specStatement;
// translate EqStatement in Agree to SymbolDefinition in vdm
SymbolDefinition symbDef = translateEqStatement(eqStmt, model, dataTypeDecl, nodeDecl);
// Add agree variable/symbol definition to the contractSpec in vdm
contractSpec.getSymbol().add(symbDef);
} else if (specStatement instanceof GuaranteeStatement) {
GuaranteeStatement guaranteeStmt = (GuaranteeStatement) specStatement;
ContractItem contractItem = translateGuaranteeStatement(guaranteeStmt, dataTypeDecl, nodeDecl, model);
contractSpec.getGuarantee().add(contractItem);
} else if (specStatement instanceof AssumeStatement) {
AssumeStatement assumeStmt = (AssumeStatement) specStatement;
ContractItem contractItem = translateAssumeStatement(assumeStmt, dataTypeDecl, nodeDecl, model);
contractSpec.getAssume().add(contractItem);
} else {
if (!(specStatement instanceof ConstStatementImpl)) {
System.out.println("Element not recognizable" + clause.eContents().toString());
}
}
}
}
if (contractSpec != null) {
List<ComponentType> vdmComponentTypes = model.getComponentType();
for (ComponentType vdmComponentType : vdmComponentTypes) {
// populating agree contract details in the corresponding componentType instance in vdm
if (vdmComponentType.getName().equalsIgnoreCase(sysType.getName())) {
vdmComponentType.setContract(contractSpec);
}
}
// populating agree contract details in the componentType instance in vdm
// packComponent.setContract(contractSpec);
}
}
}
// End of unpacking sysType
}
for (SystemImplementation sysImpl : systemImpls) {
// unpacking sysType
for (AnnexSubclause annex : sysImpl.getOwnedAnnexSubclauses()) {
if (annex.getName().equalsIgnoreCase("agree")) {
// annex is of type DefaultAnnexSubclause
DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
// AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
// populating agree contracts in the vdm node body for component implementation type
verdict.vdm.vdm_lustre.NodeBody nodeBody = new verdict.vdm.vdm_lustre.NodeBody();
;
EList<EObject> annexContents = agreeAnnex.eContents();
if (annexContents.isEmpty()) {
System.out.println("Empty Agree Annex.");
}
for (EObject clause : annexContents) {
// mapping to AgreeContractclause
AgreeContract agreeContract = (AgreeContract) clause;
// getting specStatements
EList<SpecStatement> specStatements = agreeContract.getSpecs();
for (SpecStatement specStatement : specStatements) {
if (specStatement instanceof ConstStatementImpl) {
ConstStatementImpl constStmtImpl = (ConstStatementImpl) specStatement;
ConstantDeclaration constDecl = translateConstStatementImpl(constStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getConstantDeclaration().add(constDecl);
} else if (specStatement instanceof EqStatementImpl) {
EqStatementImpl eqStmtImpl = (EqStatementImpl) specStatement;
nodeBody = translateEqStatementImpl(eqStmtImpl, dataTypeDecl, nodeDecl, model, nodeBody);
} else if (specStatement instanceof AssignStatementImpl) {
AssignStatementImpl assignStmtImpl = (AssignStatementImpl) specStatement;
NodeEquation nodeEquation = translateAssignStatementImpl(assignStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getEquation().add(nodeEquation);
} else if (specStatement instanceof AssertStatementImpl) {
AssertStatementImpl assertStmtImpl = (AssertStatementImpl) specStatement;
Expression assertion = translateAssertStatementImpl(assertStmtImpl, dataTypeDecl, nodeDecl, model);
nodeBody.getAssertion().add(assertion);
} else {
System.out.println("Element not recognizable" + clause.eContents().toString());
}
}
}
List<ComponentImpl> vdmComponentImpls = model.getComponentImpl();
for (ComponentImpl vdmComponentImpl : vdmComponentImpls) {
// populating agree contract details in the corresponding componentImplType instance in vdm
if (vdmComponentImpl.getName().equalsIgnoreCase(sysImpl.getName())) {
vdmComponentImpl.setDataflowImpl(nodeBody);
}
}
}
}
}
return model;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AGREE by loonwerks.
the class AGREESimulationState method buildPackageToConstantsMap.
private static Map<String, Map<String, ConstStatement>> buildPackageToConstantsMap(final IProject[] projects) {
// Build a mapping between lower case package names and a map between constant names to constant statements
final Map<String, Map<String, ConstStatement>> packageToConstantsMap = new HashMap<>();
try {
final Set<IFile> aadlFiles = new HashSet<>();
getAadlFiles(projects, aadlFiles);
for (final IFile aadlFile : aadlFiles) {
// final Resource aadlRes = OsateResourceUtil.getResource(aadlFile);
final Resource aadlRes = getResource(URI.createPlatformResourceURI(aadlFile.getFullPath().toString(), false));
if (aadlRes != null && !aadlRes.getContents().isEmpty()) {
final EObject content = aadlRes.getContents().get(0);
if (content instanceof AadlPackage) {
// Find all AGREE Libraries
final AadlPackage pkg = (AadlPackage) content;
if (pkg.getPublicSection() != null && pkg.getName() != null) {
final Map<String, ConstStatement> constants = new HashMap<>();
packageToConstantsMap.put(pkg.getQualifiedName().toLowerCase(), constants);
for (final AnnexLibrary lib : pkg.getPublicSection().getOwnedAnnexLibraries()) {
// Look for AGREE annex libraries
if (lib instanceof DefaultAnnexLibrary && "agree".equalsIgnoreCase(lib.getName())) {
final AnnexLibrary parsedLib = ((DefaultAnnexLibrary) lib).getParsedAnnexLibrary();
if (parsedLib instanceof AgreeContractLibrary) {
final AgreeContractLibrary agreeContractLib = (AgreeContractLibrary) parsedLib;
if (agreeContractLib.getContract() instanceof AgreeContract) {
final AgreeContract agreeContract = (AgreeContract) agreeContractLib.getContract();
for (final SpecStatement spec : agreeContract.getSpecs()) {
if (spec instanceof ConstStatement) {
final ConstStatement constStatement = (ConstStatement) spec;
// Check that the statement is of a supported type
if (getType(constStatement) != null) {
constants.put(constStatement.getName().toLowerCase(), constStatement);
}
}
}
}
}
}
}
}
}
}
}
} catch (CoreException e) {
throw new AGREESimulatorException(null, e, "Unable to build constants map");
}
return packageToConstantsMap;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AGREE by loonwerks.
the class AgreeValidator method checkLatchedExpr.
@Check(CheckType.FAST)
public void checkLatchedExpr(LatchedExpr latched) {
// get container
EObject container = latched.eContainer();
AgreeContract contract = null;
while (!(container instanceof ComponentClassifier)) {
if (container instanceof AgreeContract) {
contract = (AgreeContract) container;
}
container = container.eContainer();
}
if (container instanceof ComponentImplementation) {
boolean foundLatchedStatement = false;
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof LatchedStatement) {
foundLatchedStatement = true;
break;
}
}
if (!foundLatchedStatement) {
error(latched, "Latched expressions can appear only in component implementations " + "that contain a latched synchrony statement");
}
} else {
error(latched, "Latched expressions can appear only in component implementations");
}
Expr expr = latched.getExpr();
Expr nestId = null;
if (expr instanceof NamedElmExpr) {
nestId = expr;
} else if (expr instanceof EventExpr) {
EventExpr eventExpr = (EventExpr) expr;
nestId = eventExpr.getPort();
}
if (nestId != null) {
NamedElement namedEl = null;
if (nestId instanceof NamedElmExpr) {
namedEl = ((NamedElmExpr) nestId).getElm();
} else if (nestId instanceof SelectionExpr) {
namedEl = ((SelectionExpr) nestId).getField();
}
if ((namedEl instanceof DataPort) && ((DataPort) namedEl).isIn()) {
return;
} else if ((namedEl instanceof EventDataPort) && ((EventDataPort) namedEl).isIn()) {
return;
} else {
// check to see if it is an "agree_input"
EObject namedElContainer = namedEl.eContainer();
if (namedElContainer instanceof InputStatement) {
return;
}
}
}
error(latched, "Latched expressions are valid only for input data ports or event expressions over input event data ports");
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AGREE by loonwerks.
the class AgreeLinkingService method getElm.
private Element getElm(EObject context, EReference reference, String name) {
String[] segments = name.split("::");
if (segments.length >= 2) {
String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
String statementName = segments[segments.length - 1];
Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
if (propSet != null) {
Element elm = propSet.findNamedElement(statementName);
return elm;
}
AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
if (aadlPackage == null) {
for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
if (rename.getName() != null && pkgName.equals(rename.getName())) {
aadlPackage = rename.getRenamedPackage();
}
}
}
if (aadlPackage != null) {
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof RecordDef) {
if (((RecordDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof FnDef) {
if (((FnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LibraryFnDef) {
if (((LibraryFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof UninterpretedFnDef) {
if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof NodeDef) {
if (((NodeDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof LinearizationDef) {
if (((LinearizationDef) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof ConstStatement) {
if (((ConstStatement) spec).getName().equals(statementName)) {
return (spec);
}
} else if (spec instanceof EnumStatement) {
if (((EnumStatement) spec).getName().equals(statementName)) {
return (spec);
}
EList<NamedID> enums = ((EnumStatement) spec).getEnums();
for (NamedID nid : enums) {
if (nid.getName().contentEquals(statementName)) {
return nid;
}
}
}
}
}
}
}
return null;
}
use of com.rockwellcollins.atc.agree.agree.AgreeContract in project AGREE by loonwerks.
the class AgreeScopeProvider method getNamedElements.
private Map<String, NamedElement> getNamedElements(EObject ctx) {
Map<String, NamedElement> components = new HashMap<>();
if (ctx instanceof AadlPackage) {
components.put(((AadlPackage) ctx).getName(), (AadlPackage) ctx);
PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
for (Element el : pubSec.getOwnedElements()) {
if (el instanceof DataImplementation || el instanceof DataType) {
components.put(((NamedElement) el).getName(), (NamedElement) el);
}
}
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
} else {
components.putAll(getNamedElementsFromClassifier((Classifier) ctx, false));
}
return components;
}
Aggregations