Search in sources :

Example 1 with AOperation

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

the class MachineContext method caseAOperationsMachineClause.

@Override
public void caseAOperationsMachineClause(AOperationsMachineClause node) {
    this.operationMachineClause = node;
    this.contextTable = new ArrayList<LinkedHashMap<String, Node>>();
    ArrayList<MachineContext> list = lookupReferencedMachines();
    for (int i = 0; i < list.size(); i++) {
        MachineContext s = list.get(i);
        this.contextTable.add(s.getSetParamter());
        this.contextTable.add(s.getScalarParameter());
        this.contextTable.add(s.getDeferredSets());
        this.contextTable.add(s.getEnumeratedSets());
        this.contextTable.add(s.getEnumValues());
        this.contextTable.add(s.getConstants());
        this.contextTable.add(s.getDefinitions());
        this.contextTable.add(s.getVariables());
    }
    List<POperation> copy = new ArrayList<POperation>(node.getOperations());
    // first collect all operations
    for (POperation e : copy) {
        AOperation op = (AOperation) e;
        String name = Utils.getTIdentifierListAsString(op.getOpName());
        // existString(name);
        if (operations.keySet().contains(name)) {
            throw new ScopeException(String.format("Duplicate operation: '%s'", name));
        }
        operations.put(name, op);
    }
    // visit all operations
    for (POperation e : copy) {
        e.apply(this);
    }
}
Also used : AOperation(de.be4.classicalb.core.parser.node.AOperation) POperation(de.be4.classicalb.core.parser.node.POperation) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ScopeException(de.prob.typechecker.exceptions.ScopeException)

Example 2 with AOperation

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

the class CreateFreetypeTest method createSimpleAdd.

private AOperation createSimpleAdd(String name) {
    final ASetExtensionExpression newVal = new ASetExtensionExpression(createIdentifiers(CONS_EMPTY));
    final PSubstitution subst = createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal));
    return new AOperation(EMPTY_EXPRS, createIdLits(name), EMPTY_EXPRS, subst);
}
Also used : AUnionExpression(de.be4.classicalb.core.parser.node.AUnionExpression) ASetExtensionExpression(de.be4.classicalb.core.parser.node.ASetExtensionExpression) AOperation(de.be4.classicalb.core.parser.node.AOperation) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution)

Example 3 with AOperation

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

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

the class CreateFreetypeTest method createOperations.

private AOperationsMachineClause createOperations() {
    final AOperation op1 = createAdd("addBool", "b", new ABoolSetExpression(), CONS_BOOL);
    final AOperation op2 = createAdd("addInt", "i", new AIntSetExpression(), CONS_INT);
    final AOperation op3 = createSimpleAdd("addEmpty");
    final AOperationsMachineClause operations = new AOperationsMachineClause(Arrays.<POperation>asList(op1, op2, op3));
    return operations;
}
Also used : AOperationsMachineClause(de.be4.classicalb.core.parser.node.AOperationsMachineClause) AOperation(de.be4.classicalb.core.parser.node.AOperation) ABoolSetExpression(de.be4.classicalb.core.parser.node.ABoolSetExpression) AIntSetExpression(de.be4.classicalb.core.parser.node.AIntSetExpression)

Example 5 with AOperation

use of de.be4.classicalb.core.parser.node.AOperation 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)5 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)3 APreconditionSubstitution (de.be4.classicalb.core.parser.node.APreconditionSubstitution)2 ASetExtensionExpression (de.be4.classicalb.core.parser.node.ASetExtensionExpression)2 AUnionExpression (de.be4.classicalb.core.parser.node.AUnionExpression)2 ArrayList (java.util.ArrayList)2 ABoolSetExpression (de.be4.classicalb.core.parser.node.ABoolSetExpression)1 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)1 AIntSetExpression (de.be4.classicalb.core.parser.node.AIntSetExpression)1 AMemberPredicate (de.be4.classicalb.core.parser.node.AMemberPredicate)1 AOperationsMachineClause (de.be4.classicalb.core.parser.node.AOperationsMachineClause)1 ASelectSubstitution (de.be4.classicalb.core.parser.node.ASelectSubstitution)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 POperation (de.be4.classicalb.core.parser.node.POperation)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 ScopeException (de.prob.typechecker.exceptions.ScopeException)1 LinkedHashMap (java.util.LinkedHashMap)1