Search in sources :

Example 26 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.

the class EventBMachineTranslator method translateMachine.

public Node translateMachine() {
    AEventBModelParseUnit ast = new AEventBModelParseUnit();
    ast.setName(new TIdentifierLiteral(machine.getName()));
    List<PModelClause> clauses = new ArrayList<>();
    clauses.add(processContexts());
    ARefinesModelClause refines = processRefines();
    if (refines != null) {
        clauses.add(refines);
    }
    clauses.add(processVariables());
    clauses.addAll(processInvariantsAndTheorems());
    AVariantModelClause variant = processVariant();
    if (variant != null) {
        clauses.add(variant);
    }
    clauses.add(processEvents());
    ast.setModelClauses(clauses);
    return ast;
}
Also used : ARefinesModelClause(de.be4.classicalb.core.parser.node.ARefinesModelClause) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) AVariantModelClause(de.be4.classicalb.core.parser.node.AVariantModelClause) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 27 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.

the class ContextTranslator method processSets.

private ASetsContextClause processSets() {
    List<PSet> sets = new ArrayList<>();
    for (Set bSet : context.getSets()) {
        List<TIdentifierLiteral> names = new ArrayList<>();
        names.add(new TIdentifierLiteral(bSet.getName()));
        sets.add(new ADeferredSetSet(names));
    }
    return new ASetsContextClause(sets);
}
Also used : ADeferredSetSet(de.be4.classicalb.core.parser.node.ADeferredSetSet) Set(de.prob.model.representation.Set) PSet(de.be4.classicalb.core.parser.node.PSet) ASetsContextClause(de.be4.classicalb.core.parser.node.ASetsContextClause) PSet(de.be4.classicalb.core.parser.node.PSet) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ADeferredSetSet(de.be4.classicalb.core.parser.node.ADeferredSetSet)

Example 28 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral 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 29 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project prob2 by bendisposto.

the class ComponentExtractor method caseAProcedureParseUnit.

@Override
public void caseAProcedureParseUnit(final AProcedureParseUnit node) {
    String name = node.getName().getText();
    LinkedList<TIdentifierLiteral> seen = node.getSeen();
    Context ctx = null;
    if (node.getSeen().size() == 1) {
        String cName = seen.getFirst().getText();
        ctx = getContext(cName);
    } else if (node.getSeen().size() > 1) {
        throw new IllegalArgumentException("Error in " + name + " definition: " + node.getStartPos() + " only one context may be seen by a procedure");
    }
    Procedure procedure = new Procedure(name, ctx, typeEnv);
    ProcedureExtractor pE = new ProcedureExtractor(procedure, node, typeEnv);
    modelM = modelM.addProcedure(pE.getProcedure());
}
Also used : Context(de.prob.model.eventb.Context) Procedure(de.prob.model.eventb.algorithm.Procedure) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Example 30 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class ASTBuilder method addForceDefinition.

public static void addForceDefinition(IDefinitions iDefinitions) {
    if (iDefinitions.containsDefinition(FORCE)) {
        return;
    }
    /*-
		 * EXTERNAL_FUNCTION_FORCE(T) == T --> T; 
		 * FORCE(value) == value;
		 * forces evaluation of symbolic set representations 
		 * usage: FORCE({ x | x:1..100 & x mod 2 = 0 } )
		 */
    AExpressionDefinitionDefinition forceDef = new AExpressionDefinitionDefinition();
    forceDef.setName(new TIdentifierLiteral(FORCE));
    String value = "value";
    forceDef.setParameters(createIdentifierList(value));
    forceDef.setRhs(createIdentifier(value));
    iDefinitions.addDefinition(forceDef, IDefinitions.Type.Expression);
    AExpressionDefinitionDefinition forceDefType = new AExpressionDefinitionDefinition();
    forceDefType.setName(new TIdentifierLiteral("EXTERNAL_FUNCTION_" + FORCE));
    forceDefType.setParameters(createIdentifierList("T"));
    forceDefType.setRhs(new ATotalFunctionExpression(createIdentifier("T"), createIdentifier("T")));
    iDefinitions.addDefinition(forceDefType, IDefinitions.Type.Expression);
}
Also used : AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) ATotalFunctionExpression(de.be4.classicalb.core.parser.node.ATotalFunctionExpression)

Aggregations

TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)44 ArrayList (java.util.ArrayList)23 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)13 PExpression (de.be4.classicalb.core.parser.node.PExpression)9 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)8 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)8 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)5 LinkedList (java.util.LinkedList)4 BException (de.be4.classicalb.core.parser.exceptions.BException)3 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)3 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)3 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)2 AConstructorFreetypeConstructor (de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor)2 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)2