Search in sources :

Example 1 with APreconditionSubstitution

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

the class CreateFreetypeTest method createAdd.

private AOperation createAdd(String name, String param, PExpression type, String cons) {
    final AMemberPredicate pre = new AMemberPredicate(createIdentifier(param), type);
    final ASetExtensionExpression newVal = new ASetExtensionExpression(Arrays.<PExpression>asList(new AFunctionExpression(createIdentifier(cons), createIdentifiers(param))));
    final PSubstitution subst = new APreconditionSubstitution(pre, createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal)));
    return new AOperation(EMPTY_EXPRS, createIdLits(name), createIdentifiers(param), subst);
}
Also used : AUnionExpression(de.be4.classicalb.core.parser.node.AUnionExpression) ASetExtensionExpression(de.be4.classicalb.core.parser.node.ASetExtensionExpression) APreconditionSubstitution(de.be4.classicalb.core.parser.node.APreconditionSubstitution) AOperation(de.be4.classicalb.core.parser.node.AOperation) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AMemberPredicate(de.be4.classicalb.core.parser.node.AMemberPredicate) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression)

Example 2 with APreconditionSubstitution

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

the class DomBuilder method inAOperation.

@Override
public void inAOperation(final AOperation node) {
    String name = extractIdentifierName(node.getOpName());
    if (prefix != null && !prefix.equals(name)) {
        name = prefix + "." + name;
    }
    List<PExpression> paramIds = node.getParameters();
    final List<String> params = extractIdentifiers(paramIds);
    final List<String> output = extractIdentifiers(node.getReturnValues());
    Operation operation = new Operation(name, params, output);
    PSubstitution body = node.getOperationBody();
    List<ClassicalBGuard> guards = new ArrayList<>();
    if (body instanceof ASelectSubstitution) {
        PPredicate condition = ((ASelectSubstitution) body).getCondition();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    if (body instanceof APreconditionSubstitution) {
        PPredicate condition = ((APreconditionSubstitution) body).getPredicate();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    List<ClassicalBAction> actions = new ArrayList<>();
    actions.add(new ClassicalBAction(createSubstitutionAST(body)));
    operation = operation.set(Action.class, new ModelElementList<>(actions));
    operation = operation.set(Guard.class, new ModelElementList<>(guards));
    operations.add(operation);
}
Also used : ASelectSubstitution(de.be4.classicalb.core.parser.node.ASelectSubstitution) Action(de.prob.model.representation.Action) ArrayList(java.util.ArrayList) ModelElementList(de.prob.model.representation.ModelElementList) AOperation(de.be4.classicalb.core.parser.node.AOperation) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) PExpression(de.be4.classicalb.core.parser.node.PExpression) APreconditionSubstitution(de.be4.classicalb.core.parser.node.APreconditionSubstitution) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) Guard(de.prob.model.representation.Guard)

Aggregations

AOperation (de.be4.classicalb.core.parser.node.AOperation)2 APreconditionSubstitution (de.be4.classicalb.core.parser.node.APreconditionSubstitution)2 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)2 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)1 AMemberPredicate (de.be4.classicalb.core.parser.node.AMemberPredicate)1 ASelectSubstitution (de.be4.classicalb.core.parser.node.ASelectSubstitution)1 ASetExtensionExpression (de.be4.classicalb.core.parser.node.ASetExtensionExpression)1 AUnionExpression (de.be4.classicalb.core.parser.node.AUnionExpression)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1 Action (de.prob.model.representation.Action)1 Guard (de.prob.model.representation.Guard)1 ModelElementList (de.prob.model.representation.ModelElementList)1 ArrayList (java.util.ArrayList)1