Search in sources :

Example 26 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 27 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.

the class RulesProject method checkIdentifiers.

private void checkIdentifiers() {
    if (this.hasErrors()) {
        /*
			 * if there is already an error such as an parse error in one
			 * machine, it makes no sense to check for invalid identifiers
			 * because all declarations of this machine are missing.
			 */
        return;
    }
    final HashMap<String, RulesParseUnit> map = new HashMap<>();
    for (IModel model : bModels) {
        RulesParseUnit parseUnit = (RulesParseUnit) model;
        map.put(parseUnit.getMachineName(), parseUnit);
    }
    for (IModel model : bModels) {
        RulesParseUnit parseUnit = (RulesParseUnit) model;
        HashSet<String> knownIdentifiers = new HashSet<>();
        List<RulesMachineReference> machineReferences = parseUnit.getMachineReferences();
        for (RulesMachineReference rulesMachineReference : machineReferences) {
            String referenceName = rulesMachineReference.getName();
            RulesParseUnit rulesParseUnit = map.get(referenceName);
            RulesMachineChecker checker = rulesParseUnit.getRulesMachineChecker();
            knownIdentifiers.addAll(checker.getGlobalIdentifierNames());
        }
        RulesMachineChecker checker = parseUnit.getRulesMachineChecker();
        Map<String, HashSet<Node>> unknownIdentifierMap = checker.getUnknownIdentifier();
        HashSet<String> unknownIdentifiers = new HashSet<>(unknownIdentifierMap.keySet());
        unknownIdentifiers.removeAll(knownIdentifiers);
        for (String name : unknownIdentifiers) {
            HashSet<Node> hashSet = unknownIdentifierMap.get(name);
            Node node = hashSet.iterator().next();
            this.bExceptionList.add(new BException(parseUnit.getPath(), new CheckException("Unknown identifier '" + name + "'.", node)));
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Node(de.be4.classicalb.core.parser.node.Node) BException(de.be4.classicalb.core.parser.exceptions.BException) HashSet(java.util.HashSet)

Example 28 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 29 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 30 with CheckException

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

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)78 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)19 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)17 PExpression (de.be4.classicalb.core.parser.node.PExpression)16 Test (org.junit.Test)15 BException (de.be4.classicalb.core.parser.exceptions.BException)14 ArrayList (java.util.ArrayList)13 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)12 Ast2String (util.Ast2String)10 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)9 Node (de.be4.classicalb.core.parser.node.Node)8 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)8 File (java.io.File)8 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)4 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)4 Helpers.getTreeAsString (util.Helpers.getTreeAsString)4 Type (de.be4.classicalb.core.parser.IDefinitions.Type)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3