Search in sources :

Example 6 with AbstractOperation

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

the class RulesTransformation method outAOperatorPredicate.

@Override
public void outAOperatorPredicate(AOperatorPredicate node) {
    // currently all operator handle rule names
    final List<PExpression> arguments = new ArrayList<>(node.getIdentifiers());
    final String operatorName = node.getName().getText();
    final AIdentifierExpression ruleIdentifier = (AIdentifierExpression) arguments.get(0);
    final String ruleName = ruleIdentifier.getIdentifier().get(0).getText();
    AbstractOperation operation = allOperations.get(ruleName);
    if (operation == null || !(operation instanceof RuleOperation)) {
        errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
        return;
    }
    final RuleOperation rule = (RuleOperation) operation;
    switch(operatorName) {
        case RulesGrammar.SUCCEEDED_RULE:
            replacePredicateOperator(node, arguments, RULE_SUCCESS);
            return;
        case RulesGrammar.SUCCEEDED_RULE_ERROR_TYPE:
            replaceSucceededRuleErrorTypeOperator(node, ruleName, rule);
            return;
        case RulesGrammar.FAILED_RULE:
            replacePredicateOperator(node, arguments, RULE_FAIL);
            return;
        case RulesGrammar.FAILED_RULE_ALL_ERROR_TYPES:
            replaceFailedRuleAllErrorTypesOperator(node, rule);
            return;
        case RulesGrammar.FAILED_RULE_ERROR_TYPE:
            replaceFailedRuleErrorTypeOperator(node, rule);
            return;
        case RulesGrammar.NOT_CHECKED_RULE:
            replacePredicateOperator(node, arguments, RULE_NOT_CHECKED);
            return;
        case RulesGrammar.DISABLED_RULE:
            replacePredicateOperator(node, arguments, RULE_DISABLED);
            return;
        default:
            throw new AssertionError("should not happen: " + operatorName);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList)

Example 7 with AbstractOperation

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

the class RulesTransformation method translateGetRuleCounterExamplesOperator.

private void translateGetRuleCounterExamplesOperator(AOperatorExpression node) {
    final PExpression pExpression = node.getIdentifiers().get(0);
    final AIdentifierExpression id = (AIdentifierExpression) pExpression;
    final String ruleName = id.getIdentifier().get(0).getText();
    final AbstractOperation operation = allOperations.get(ruleName);
    if (operation == null || !(operation instanceof RuleOperation)) {
        errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
        return;
    }
    final RuleOperation rule = (RuleOperation) operation;
    final String name = id.getIdentifier().get(0).getText() + RULE_COUNTER_EXAMPLE_VARIABLE_SUFFIX;
    if (node.getIdentifiers().size() == 1) {
        final AIdentifierExpression ctVariable = createIdentifier(name, pExpression);
        final ARangeExpression range = createPositinedNode(new ARangeExpression(ctVariable), node);
        node.replaceBy(range);
    } else {
        PExpression funcCall = getSetOfErrorMessagesByErrorType(name, node.getIdentifiers().get(1), rule.getNumberOfErrorTypes());
        node.replaceBy(funcCall);
    }
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Example 8 with AbstractOperation

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

the class RulesChecker method getOperationState.

public OperationStatus getOperationState(String opName) {
    checkThatOperationExists(opName);
    checkThatOperationIsNotAFunctionOperation(opName);
    init();
    AbstractOperation abstractOperation = rulesProject.getOperationsMap().get(opName);
    return this.operationStatuses.get(abstractOperation);
}
Also used : AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation)

Example 9 with AbstractOperation

use of de.be4.classicalb.core.parser.rules.AbstractOperation 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 10 with AbstractOperation

use of de.be4.classicalb.core.parser.rules.AbstractOperation 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)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)9 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)8 ArrayList (java.util.ArrayList)8 BException (de.be4.classicalb.core.parser.exceptions.BException)7 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)5 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)5 HashSet (java.util.HashSet)5 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)3 HashMap (java.util.HashMap)3 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)2 FunctionOperation (de.be4.classicalb.core.parser.rules.FunctionOperation)2 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)2 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)2 IEvalElement (de.prob.animator.domainobjects.IEvalElement)2 Trace (de.prob.statespace.Trace)2 OperationStatus (de.prob.model.brules.OperationStatus)1 RuleResult (de.prob.model.brules.RuleResult)1 RuleResults (de.prob.model.brules.RuleResults)1 RulesChecker (de.prob.model.brules.RulesChecker)1 State (de.prob.statespace.State)1