Search in sources :

Example 11 with AbstractOperation

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

the class RulesChecker method evalOperations.

public Map<AbstractOperation, OperationStatus> evalOperations(State state, Collection<AbstractOperation> operations) {
    ArrayList<IEvalElement> formulas = new ArrayList<>();
    for (AbstractOperation abstractOperation : operations) {
        if (abstractOperation instanceof ComputationOperation || abstractOperation instanceof RuleOperation) {
            formulas.add(rulesModel.getEvalElement(abstractOperation));
        }
    }
    state.getStateSpace().subscribe(this, formulas);
    Map<IEvalElement, AbstractEvalResult> values = state.getValues();
    final Map<AbstractOperation, OperationStatus> states = new HashMap<>();
    for (AbstractOperation op : operations) {
        if (op instanceof RuleOperation) {
            states.put(op, RuleStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
        } else if (op instanceof ComputationOperation) {
            states.put(op, ComputationStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
        }
    }
    return states;
}
Also used : RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) HashMap(java.util.HashMap) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) IEvalElement(de.prob.animator.domainobjects.IEvalElement) ArrayList(java.util.ArrayList) ComputationOperation(de.be4.classicalb.core.parser.rules.ComputationOperation)

Example 12 with AbstractOperation

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

the class RulesTestUtil method checkRulesMachineRunForConsistency.

public static void checkRulesMachineRunForConsistency(RulesMachineRun rulesMachineRun) {
    RulesProject rulesProject = rulesMachineRun.getRulesProject();
    RuleResults ruleResults = rulesMachineRun.getRuleResults();
    Map<String, RuleResult> ruleResultMap = ruleResults.getRuleResultMap();
    for (AbstractOperation abstractOperation : rulesProject.getOperationsMap().values()) {
        if (abstractOperation instanceof RuleOperation) {
            String ruleName = abstractOperation.getName();
            assertTrue(String.format("Rule operation '%s' is not contained in the result map.", ruleName), ruleResultMap.containsKey(ruleName));
            RuleResult ruleResult = ruleResultMap.get(ruleName);
            if (ruleResult.getRuleState() == RuleStatus.FAIL) {
                assertTrue(String.format("No violation found but rule failed: '%s'", ruleName), ruleResult.getNumberOfViolations() > 0);
            }
            if (ruleResult.getRuleState() == RuleStatus.NOT_CHECKED) {
                List<String> notCheckedCauses = ruleResult.getFailedDependencies();
                assertTrue(String.format("There is no cause why rule '%s' is not checked.", ruleName), !notCheckedCauses.isEmpty());
            }
        }
    }
}
Also used : RuleResults(de.prob.model.brules.RuleResults) RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) RulesProject(de.be4.classicalb.core.parser.rules.RulesProject) RuleResult(de.prob.model.brules.RuleResult)

Example 13 with AbstractOperation

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

the class RulesProject method collectAllOperations.

private void collectAllOperations() {
    for (IModel iModel : bModels) {
        final RulesParseUnit unit = (RulesParseUnit) iModel;
        final List<AbstractOperation> operations = unit.getOperations();
        for (AbstractOperation abstractOperation : operations) {
            final String name = abstractOperation.getName();
            if (allOperations.containsKey(name)) {
                this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Duplicate operation name: '" + name + "'.", abstractOperation.getNameLiteral())));
            }
            allOperations.put(name, abstractOperation);
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 14 with AbstractOperation

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

the class RulesProject method checkVisibilityOfTIdentifierList.

private void checkVisibilityOfTIdentifierList(AbstractOperation operation, List<TIdentifierLiteral> dependencyList) {
    List<String> machineReferences = operation.getMachineReferencesAsString();
    machineReferences.add(operation.getMachineName());
    for (TIdentifierLiteral tIdentifierLiteral : dependencyList) {
        String otherOpName = tIdentifierLiteral.getText();
        if (allOperations.containsKey(otherOpName)) {
            AbstractOperation abstractOperation = allOperations.get(otherOpName);
            String otherMachineName = abstractOperation.getMachineName();
            if (!machineReferences.contains(otherMachineName)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + otherOpName + "' is not visible in RULES_MACHINE '" + operation.getMachineName() + "'.", tIdentifierLiteral)));
            }
        }
    }
}
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 15 with AbstractOperation

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

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