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;
}
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;
}
Aggregations