Search in sources :

Example 1 with AGREESimulatorException

use of edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException in project AGREE by loonwerks.

the class AgreeProgramToSimulationProgram method transform.

public static SimulationProgram transform(final AgreeProgram agreeProgram, final SimulationProgramType type) {
    Objects.requireNonNull(agreeProgram, "agreeProgram must not be null");
    // Build a Component Instance to AgreeNode map
    final Program lustreProgram = LustreAstBuilder.getAssumeGuaranteeLustreProgram(agreeProgram);
    final AgreeRenaming agreeRenaming = new AgreeRenaming();
    final AgreeLayout layout = new AgreeLayout();
    RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, agreeProgram.topNode.compInst, layout);
    SimulationProgram program;
    try {
        final SimulationProgramBuilder builder = new SimulationProgramBuilder(type, agreeProgram.topNode.compInst, lustreProgram, agreeRenaming);
        populateMetadata(builder, agreeProgram, lustreProgram, agreeRenaming, agreeRenaming.getRefMap());
        program = builder.build();
    } catch (final Exception ex) {
        throw new AGREESimulatorException(lustreProgram, ex);
    }
    try {
        program = CreateLocalVariablesForPropertyExpressions.transform(program);
        program = RemovePropertySatisficationRequirements.transform(program);
        program = RemoveCondacts.transform(program);
        program = InlineNodeCalls.transform(program);
        program = ReplaceFollowedByOperator.transform(program);
        program = ReplacePreOperator.transform(program);
        program = CreateSimulationProperties.transform(program);
        program = RemoveProperties.transform(program);
        program = CreateSimulationGuarantee.transform(program);
    } catch (final Exception ex) {
        throw new AGREESimulatorException(program.getLustreProgram(), ex);
    }
    return program;
}
Also used : SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException)

Example 2 with AGREESimulatorException

use of edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException 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;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) HashMap(java.util.HashMap) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) CoreException(org.eclipse.core.runtime.CoreException) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) Map(java.util.Map) HashMap(java.util.HashMap) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) HashSet(java.util.HashSet) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Aggregations

AGREESimulatorException (edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException)2 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)1 AgreeContractLibrary (com.rockwellcollins.atc.agree.agree.AgreeContractLibrary)1 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)1 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)1 AgreeLayout (com.rockwellcollins.atc.agree.analysis.AgreeLayout)1 AgreeRenaming (com.rockwellcollins.atc.agree.analysis.AgreeRenaming)1 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)1 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)1 SimulationProgramBuilder (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Program (jkind.lustre.Program)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 AadlPackage (org.osate.aadl2.AadlPackage)1