Search in sources :

Example 1 with AbstractElement

use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.

the class MachineXmlHandler method addRefinedMachine.

private void addRefinedMachine(final Attributes attributes) {
    String target = attributes.getValue("org.eventb.core.scTarget");
    String machineName = target.substring(target.lastIndexOf('/') + 1, target.lastIndexOf('.'));
    model = model.addRelationship(machine.getName(), machineName, ERefType.REFINES);
    AbstractElement component = model.getComponent(machineName);
    if (component != null) {
        EventBMachine mch = (EventBMachine) component;
        refines.add(mch);
    } else {
        try {
            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
            SAXParser saxParser = parserFactory.newSAXParser();
            String fileName = directoryPath + File.separatorChar + machineName + ".bcm";
            MachineXmlHandler handler = new MachineXmlHandler(model, fileName, typeEnv);
            saxParser.parse(new File(fileName), handler);
            axiomCache.putAll(handler.getAxiomCache());
            invariantCache.putAll(handler.getInvariantCache());
            eventCache.putAll(handler.getEventCache());
            refines.add(handler.getMachine());
            model = handler.getModel();
        } catch (IOException | ParserConfigurationException | SAXException e) {
            logger.error("Error parsing XML", e);
        }
    }
}
Also used : AbstractElement(de.prob.model.representation.AbstractElement) SAXParser(javax.xml.parsers.SAXParser) EventBMachine(de.prob.model.eventb.EventBMachine) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 2 with AbstractElement

use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.

the class MachineXmlHandler method addSeesContext.

private void addSeesContext(final Attributes attributes) {
    String target = attributes.getValue("org.eventb.core.scTarget");
    String contextName = target.substring(target.lastIndexOf('/') + 1, target.lastIndexOf('.'));
    model = model.addRelationship(machine.getName(), contextName, ERefType.SEES);
    seesNames.add(contextName);
    AbstractElement context = model.getComponent(contextName);
    if (context != null) {
        sees.add((Context) context);
    }
}
Also used : AbstractElement(de.prob.model.representation.AbstractElement)

Example 3 with AbstractElement

use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.

the class ComponentExtractor method caseAMachineParseUnit.

@Override
public void caseAMachineParseUnit(final AMachineParseUnit node) {
    String name = node.getName().getText();
    MachineModifier machineM = new MachineModifier(new EventBMachine(name), typeEnv);
    ModelElementList<Context> seen = new ModelElementList<>();
    for (TIdentifierLiteral contextName : node.getSeenNames()) {
        String cName = contextName.getText();
        AbstractElement context = getContext(cName);
        seen = seen.addElement((Context) context);
    }
    machineM = machineM.setSees(seen);
    if (node.getRefinesNames().size() == 1) {
        String mname = node.getRefinesNames().getFirst().getText();
        EventBMachine machine = getMachine(mname);
        machineM = machineM.setRefines(machine);
    } else if (node.getRefinesNames().size() > 1) {
        throw new IllegalArgumentException("Machines can only refine one abstract machine. Found " + node.getRefinesNames().size() + " refined machines");
    }
    machineM = machineM.addComment(getComment(node.getComments()));
    MachineExtractor mE = new MachineExtractor(machineM, typeEnv);
    node.apply(mE);
    modelM = modelM.addMachine(mE.getMachine());
}
Also used : Context(de.prob.model.eventb.Context) AbstractElement(de.prob.model.representation.AbstractElement) ModelElementList(de.prob.model.representation.ModelElementList) EventBMachine(de.prob.model.eventb.EventBMachine) MachineModifier(de.prob.model.eventb.MachineModifier) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Example 4 with AbstractElement

use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.

the class ContextXmlHandler method addExtendedContext.

private void addExtendedContext(final Attributes attributes) {
    String source = attributes.getValue("org.eventb.core.scTarget");
    String contextName = source.substring(source.lastIndexOf('#') + 1, source.length());
    model.addRelationship(context.getName(), contextName, ERefType.EXTENDS);
    if (!inInternalContext) {
        extendsNames.add(contextName);
    }
    AbstractElement component = model.getComponent(contextName);
    if (component != null) {
        if (inInternalContext) {
            internalExtends.add((Context) component);
        } else {
            extendedContexts.add((Context) component);
        }
    }
}
Also used : AbstractElement(de.prob.model.representation.AbstractElement)

Example 5 with AbstractElement

use of de.prob.model.representation.AbstractElement in project prob2 by bendisposto.

the class Transition method getParameterPredicates.

/**
 * @return a list of string predicates representing the value of the
 *         parameters for this transition
 */
public List<String> getParameterPredicates() {
    if (isArtificialTransition()) {
        return Collections.emptyList();
    }
    evaluate(FormulaExpand.EXPAND);
    List<String> predicates = new ArrayList<>();
    AbstractElement mainComponent = stateSpace.getMainComponent();
    List<String> paramNames = new ArrayList<>();
    if (mainComponent instanceof ClassicalBMachine) {
        Operation op = ((ClassicalBMachine) mainComponent).getOperation(getName());
        paramNames = op.getParameters();
    } else if (mainComponent instanceof EventBMachine) {
        Event event = ((EventBMachine) mainComponent).getEvent(getName());
        for (EventParameter eventParameter : event.getParameters()) {
            paramNames.add(eventParameter.getName());
        }
    }
    if (paramNames.size() == this.params.size()) {
        for (int i = 0; i < paramNames.size(); i++) {
            predicates.add(paramNames.get(i) + " = " + this.params.get(i));
        }
    }
    return predicates;
}
Also used : EventParameter(de.prob.model.eventb.EventParameter) AbstractElement(de.prob.model.representation.AbstractElement) ClassicalBMachine(de.prob.model.classicalb.ClassicalBMachine) ArrayList(java.util.ArrayList) Event(de.prob.model.eventb.Event) EventBMachine(de.prob.model.eventb.EventBMachine) Operation(de.prob.model.classicalb.Operation)

Aggregations

AbstractElement (de.prob.model.representation.AbstractElement)5 EventBMachine (de.prob.model.eventb.EventBMachine)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)1 ClassicalBMachine (de.prob.model.classicalb.ClassicalBMachine)1 Operation (de.prob.model.classicalb.Operation)1 Context (de.prob.model.eventb.Context)1 Event (de.prob.model.eventb.Event)1 EventParameter (de.prob.model.eventb.EventParameter)1 MachineModifier (de.prob.model.eventb.MachineModifier)1 ModelElementList (de.prob.model.representation.ModelElementList)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXException (org.xml.sax.SAXException)1