Search in sources :

Example 81 with CheckException

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

the class ClausesCheck method checkConstantsClause.

private void checkConstantsClause() {
    /*
		 * CONCRETE_CONSTANTS || CONSTANTS || ABSTRACT_CONSTANTS => PROPERTIES
		 */
    if ((clauses.containsKey(NAME_CONSTANTS) || clauses.containsKey(NAME_ABSTRACT_CONSTANTS)) && !clauses.containsKey(NAME_PROPERTIES)) {
        final Set<Node> nodes = new HashSet<>();
        if (clauses.containsKey(NAME_CONSTANTS)) {
            nodes.addAll(clauses.get(NAME_CONSTANTS));
        }
        if (clauses.containsKey(NAME_ABSTRACT_CONSTANTS)) {
            nodes.addAll(clauses.get(NAME_ABSTRACT_CONSTANTS));
        }
        exceptions.add(new CheckException("Clause(s) missing: PROPERTIES", nodes.toArray(new Node[nodes.size()])));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) HashSet(java.util.HashSet)

Example 82 with CheckException

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

the class ClausesCheck method checkVariablesClauses.

private void checkVariablesClauses() {
    /*
		 * CONCRETE_VARIABLES || VARIABLES || ABSTRACT_VARIABLES => INVARIANT &&
		 * INITIALISATION
		 */
    if ((clauses.containsKey(NAME_VARIABLES) || clauses.containsKey(NAME_CONCRETE_VARIABLES)) && (!clauses.containsKey(NAME_INVARIANT) || !clauses.containsKey(NAME_INITIALISATION))) {
        final Set<Node> nodes = new HashSet<>();
        if (clauses.containsKey(NAME_VARIABLES)) {
            nodes.addAll(clauses.get(NAME_VARIABLES));
        }
        if (clauses.containsKey(NAME_CONCRETE_VARIABLES)) {
            nodes.addAll(clauses.get(NAME_CONCRETE_VARIABLES));
        }
        final StringBuilder message = new StringBuilder("Clause(s) missing: ");
        boolean first = true;
        if (!clauses.containsKey(NAME_INVARIANT)) {
            message.append("INVARIANT");
            first = false;
        }
        if (!clauses.containsKey(NAME_INITIALISATION)) {
            if (!first) {
                message.append(", ");
            }
            message.append("INITIALISATION");
        }
        exceptions.add(new CheckException(message.toString(), nodes.toArray(new Node[nodes.size()])));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) HashSet(java.util.HashSet)

Example 83 with CheckException

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

the class ClausesCheck method checkDoubleClauses.

/**
 * Checks if one clause is used more than once in the machine.
 *
 * @throws CheckException
 */
private void checkDoubleClauses() {
    for (final Iterator<Set<Node>> iterator = clauses.values().iterator(); iterator.hasNext(); ) {
        final Set<Node> nodesforClause = iterator.next();
        if (nodesforClause.size() > 1) {
            final Node clauseNode = nodesforClause.iterator().next();
            final String simpleClassName = clauseNode.getClass().getSimpleName();
            final int endIndex = simpleClassName.indexOf("MachineClause");
            final String clauseName = simpleClassName.substring(1, endIndex).toUpperCase();
            exceptions.add(new CheckException("Clause '" + clauseName + "' is used more than once", nodesforClause.toArray(new Node[nodesforClause.size()])));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Example 84 with CheckException

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

the class DefinitionCollector method caseAConversionDefinition.

@Override
public void caseAConversionDefinition(AConversionDefinition node) {
    PDefinition def = node.getDefinition();
    if (def instanceof AExpressionDefinitionDefinition) {
        AExpressionDefinitionDefinition exprDef = (AExpressionDefinitionDefinition) def;
        final String defName = exprDef.getName().getText();
        final Type type = defTypes.getType(defName);
        addDefinition(node, type, defName);
    } else {
        this.exceptions.add(new CheckException("Only an expression is allowed on the right hand side of a conversion definition.", node));
    }
}
Also used : PDefinition(de.be4.classicalb.core.parser.node.PDefinition) Type(de.be4.classicalb.core.parser.IDefinitions.Type) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)

Example 85 with CheckException

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

the class DefinitionUsageCheck method runChecks.

public void runChecks(final Start rootNode) {
    // only need to check complete machines
    if (!Utils.isCompleteMachine(rootNode)) {
        return;
    }
    erroneousNodes.clear();
    rootNode.apply(this);
    if (!erroneousNodes.isEmpty()) {
        exceptions.add(new CheckException("Number of parameters doesn't match declaration of definition", erroneousNodes.toArray(new Node[erroneousNodes.size()])));
    }
}
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