Search in sources :

Example 1 with FunctionOperation

use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.

the class RulesMachineChecker method checkOperationPredicateAttribute.

private void checkOperationPredicateAttribute(OccurredAttributes occurredAttributes, POperationAttribute pOperationAttribute) throws AssertionError {
    APredicateAttributeOperationAttribute attr = (APredicateAttributeOperationAttribute) pOperationAttribute;
    PPredicate predicate = attr.getPredicate();
    final String attrName = attr.getName().getText();
    occurredAttributes.add(attrName, pOperationAttribute);
    switch(attrName) {
        case RulesGrammar.ACTIVATION:
            if (currentOperation instanceof FunctionOperation) {
                errorList.add(new CheckException("ACTIVATION is not a valid attribute of a FUNCTION operation.", pOperationAttribute));
            } else {
                currentOperation.setActivationPredicate(predicate);
            }
            break;
        case RulesGrammar.PRECONDITION:
            if (currentOperation instanceof FunctionOperation) {
                FunctionOperation func = (FunctionOperation) currentOperation;
                func.setPreconditionPredicate(predicate);
            } else {
                errorList.add(new CheckException("PRECONDITION clause is not allowed for a RULE or COMPUTATION operation", pOperationAttribute));
            }
            break;
        case RulesGrammar.POSTCONDITION:
            if (currentOperation instanceof RuleOperation) {
                errorList.add(new CheckException("POSTCONDITION attribute is not allowed for a RULE operation", pOperationAttribute));
            } else {
                currentOperation.setPostcondition(predicate);
            }
            break;
        default:
            throw new AssertionError("Unexpected operation attribute: " + attrName);
    }
    predicate.apply(this);
}
Also used : APredicateAttributeOperationAttribute(de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute) ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) AFunctionOperation(de.be4.classicalb.core.parser.node.AFunctionOperation) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PPredicate(de.be4.classicalb.core.parser.node.PPredicate)

Example 2 with FunctionOperation

use of de.be4.classicalb.core.parser.rules.FunctionOperation in project prob2 by bendisposto.

the class RulesChecker method executeOperationAndDependencies.

public boolean executeOperationAndDependencies(String opName) {
    checkThatOperationExists(opName);
    checkThatOperationIsNotAFunctionOperation(opName);
    AbstractOperation goalOperation = rulesProject.getOperationsMap().get(opName);
    init();
    List<AbstractOperation> executionOrder = goalOperation.getSortedListOfTransitiveDependencies();
    executionOrder.add(goalOperation);
    executionOrder = executionOrder.stream().filter(op -> !(op instanceof FunctionOperation)).collect(Collectors.toList());
    List<AbstractOperation> operationsToBeExecuted = new ArrayList<>();
    for (AbstractOperation dep : executionOrder) {
        OperationStatus operationStatus = operationStatuses.get(dep);
        if (operationStatus.isDisabled()) {
            return false;
        }
        if (dep != goalOperation && operationStatus == RuleStatus.FAIL) {
            return false;
        }
        if (operationStatus.isNotExecuted()) {
            operationsToBeExecuted.add(dep);
        }
    }
    for (AbstractOperation op : operationsToBeExecuted) {
        OperationStatus opState = executeOperation(op);
        if (op != goalOperation && opState == RuleStatus.FAIL) {
            return false;
        }
    }
    return true;
}
Also used : AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) FunctionOperation(de.be4.classicalb.core.parser.rules.FunctionOperation) ArrayList(java.util.ArrayList)

Example 3 with FunctionOperation

use of de.be4.classicalb.core.parser.rules.FunctionOperation in project prob2 by bendisposto.

the class RulesChecker method determineDepedencies.

private void determineDepedencies() {
    for (AbstractOperation op : rulesProject.getOperationsMap().values()) {
        if (!(op instanceof FunctionOperation)) {
            Set<AbstractOperation> set = op.getTransitiveDependencies().stream().filter(p -> !(p instanceof FunctionOperation)).collect(Collectors.toSet());
            predecessors.put(op, set);
            for (AbstractOperation abstractOperation : set) {
                if (!successors.containsKey(abstractOperation)) {
                    successors.put(abstractOperation, new HashSet<>());
                }
                successors.get(abstractOperation).add(op);
            }
        }
    }
}
Also used : Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) RulesProject(de.be4.classicalb.core.parser.rules.RulesProject) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) IEvalElement(de.prob.animator.domainobjects.IEvalElement) Trace(de.prob.statespace.Trace) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) Map(java.util.Map) FunctionOperation(de.be4.classicalb.core.parser.rules.FunctionOperation) Transition(de.prob.statespace.Transition) Entry(java.util.Map.Entry) RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) State(de.prob.statespace.State) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) ComputationOperation(de.be4.classicalb.core.parser.rules.ComputationOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) FunctionOperation(de.be4.classicalb.core.parser.rules.FunctionOperation)

Example 4 with FunctionOperation

use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.

the class RulesProject method checkFunctionCalls.

private void checkFunctionCalls(AbstractOperation abstractOperation) {
    boolean errorOccured = false;
    for (TIdentifierLiteral tIdentifierLiteral : abstractOperation.getFunctionCalls()) {
        final String functionName = tIdentifierLiteral.getText();
        if (!allOperations.containsKey(functionName) || !(allOperations.get(functionName) instanceof FunctionOperation)) {
            this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Unknown FUNCTION name '" + functionName + "'", tIdentifierLiteral)));
            errorOccured = true;
        }
    }
    if (!errorOccured) {
        checkVisibilityOfTIdentifierList(abstractOperation, abstractOperation.getFunctionCalls());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) BException(de.be4.classicalb.core.parser.exceptions.BException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 5 with FunctionOperation

use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.

the class RulesMachineChecker method caseAFunctionOperation.

@Override
public void caseAFunctionOperation(AFunctionOperation node) {
    currentOperation = new FunctionOperation(node.getName(), this.fileName, this.machineName, machineReferences);
    functionMap.put(node, (FunctionOperation) currentOperation);
    this.identifierScope.createNewScope(new ArrayList<>(node.getParameters()));
    this.identifierScope.createNewScope(new ArrayList<>(node.getReturnValues()), true);
    visitOperationAttributes(node.getAttributes());
    node.getBody().apply(this);
    currentOperation = null;
    this.identifierScope.removeScope();
}
Also used : AFunctionOperation(de.be4.classicalb.core.parser.node.AFunctionOperation)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)2 AFunctionOperation (de.be4.classicalb.core.parser.node.AFunctionOperation)2 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)2 FunctionOperation (de.be4.classicalb.core.parser.rules.FunctionOperation)2 ArrayList (java.util.ArrayList)2 BException (de.be4.classicalb.core.parser.exceptions.BException)1 APredicateAttributeOperationAttribute (de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute)1 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 State (de.prob.statespace.State)1 Trace (de.prob.statespace.Trace)1 Transition (de.prob.statespace.Transition)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1