Search in sources :

Example 1 with AbstractOperation

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

the class AbstractOperation method getRequiredDependencies.

public Set<AbstractOperation> getRequiredDependencies() {
    if (this.requiredDependencies == null) {
        this.requiredDependencies = new HashSet<>();
        HashSet<AIdentifierExpression> aIdentifierSet = new HashSet<>();
        aIdentifierSet.addAll(this.dependsOnComputationList);
        aIdentifierSet.addAll(this.dependsOnRuleList);
        HashSet<String> directDependencies = new HashSet<>();
        for (AIdentifierExpression aIdentifier : aIdentifierSet) {
            directDependencies.add(aIdentifier.getIdentifier().get(0).getText());
        }
        if (transitiveDependencies != null) {
            for (AbstractOperation abstractOperation : this.transitiveDependencies) {
                String opName = abstractOperation.getName();
                if (this.implicitDependenciesToComputations.contains(abstractOperation) || directDependencies.contains(opName)) {
                    requiredDependencies.add(abstractOperation);
                } else if (functionCallMap.containsKey(opName)) {
                    requiredDependencies.addAll(abstractOperation.getRequiredDependencies());
                }
            }
        }
    }
    return new HashSet<>(requiredDependencies);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) HashSet(java.util.HashSet)

Example 2 with AbstractOperation

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

the class RulesProject method checkForCycles.

private boolean checkForCycles(AbstractOperation operation, List<TIdentifierLiteral> directDependencies, List<AbstractOperation> ancestors) {
    List<String> ancestorsNames = new ArrayList<>();
    for (AbstractOperation op : ancestors) {
        String opName = op.getName();
        ancestorsNames.add(opName);
    }
    for (TIdentifierLiteral id : directDependencies) {
        final String opName = id.getText();
        if (ancestorsNames.contains(opName)) {
            StringBuilder sb = new StringBuilder();
            for (int index = ancestorsNames.indexOf(opName); index < ancestors.size(); index++) {
                final String name = ancestors.get(index).getName();
                sb.append(name);
                sb.append(" -> ");
            }
            sb.append(opName);
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Cyclic dependencies between operations: " + sb.toString(), id)));
            return true;
        }
    }
    return false;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) BException(de.be4.classicalb.core.parser.exceptions.BException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 3 with AbstractOperation

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

the class RulesProject method checkDependsOnComputations.

private void checkDependsOnComputations(AbstractOperation operation) {
    boolean errorOccured = false;
    for (AIdentifierExpression aIdentifierExpression : operation.getDependsOnComputationList()) {
        final String name = aIdentifierExpression.getIdentifier().get(0).getText();
        if (allOperations.containsKey(name)) {
            AbstractOperation abstractOperation = allOperations.get(name);
            if (!(abstractOperation instanceof ComputationOperation)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Identifier '" + name + "' is not a COMPUTATION.", aIdentifierExpression)));
                errorOccured = true;
            }
        } else {
            errorOccured = true;
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Unknown operation: '" + name + "'.", aIdentifierExpression)));
        }
    }
    if (!errorOccured) {
        checkVisibilityOfAIdentifierList(operation, operation.getDependsOnComputationList());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 4 with AbstractOperation

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

the class RulesProject method checkDependsOnRules.

private void checkDependsOnRules(AbstractOperation operation) {
    boolean errorOccured = false;
    for (AIdentifierExpression aIdentifierExpression : operation.getDependsOnRulesList()) {
        final String name = aIdentifierExpression.getIdentifier().get(0).getText();
        if (allOperations.containsKey(name)) {
            AbstractOperation abstractOperation = allOperations.get(name);
            if (!(abstractOperation instanceof RuleOperation)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + name + "' is not a RULE operation.", aIdentifierExpression)));
                errorOccured = true;
            }
        } else {
            errorOccured = true;
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Unknown operation: '" + name + "'.", aIdentifierExpression)));
        }
    }
    if (!errorOccured) {
        checkVisibilityOfAIdentifierList(operation, operation.getDependsOnRulesList());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 5 with AbstractOperation

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

the class RulesProject method checkVisibilityOfAIdentifierList.

private void checkVisibilityOfAIdentifierList(AbstractOperation operation, List<AIdentifierExpression> dependencyList) {
    List<TIdentifierLiteral> tidentifierList = new ArrayList<>();
    for (AIdentifierExpression aIdentifier : dependencyList) {
        tidentifierList.add(aIdentifier.getIdentifier().get(0));
    }
    checkVisibilityOfTIdentifierList(operation, tidentifierList);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) 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