Search in sources :

Example 26 with BException

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

the class LexerTest method testStringLabeledElements.

@Test
public void testStringLabeledElements() throws BException {
    final Start rootNode = parseInput("machine Test invariants \n\t@inv1 asdf \n fdsa \n\t@inv2 qwer: \t rewq \nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    AInvariant invariant = (AInvariant) invariants.get(0);
    // correct invariant label?
    assertEquals("inv1", invariant.getName().getText());
    // correct string representation for predicate?
    assertEquals("asdf \n fdsa", invariant.getPredicate().getText());
    invariant = (AInvariant) invariants.get(1);
    // correct invariant label?
    assertEquals("inv2", invariant.getName().getText());
    // correct string representation for predicate?
    assertEquals("qwer: \t rewq", invariant.getPredicate().getText());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) PInvariant(de.be4.eventbalg.core.parser.node.PInvariant) AInvariant(de.be4.eventbalg.core.parser.node.AInvariant) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 27 with BException

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

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

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

Example 30 with BException

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

the class RulesProject method findImplicitDependenciesToComputations.

private void findImplicitDependenciesToComputations() {
    HashMap<String, ComputationOperation> variableToComputation = new HashMap<>();
    for (AbstractOperation operation : allOperations.values()) {
        if (operation instanceof ComputationOperation && !operation.replacesOperation()) {
            ComputationOperation comp = (ComputationOperation) operation;
            for (String defName : comp.getDefineVariables()) {
                variableToComputation.put(defName, comp);
            }
        }
    }
    for (AbstractOperation operation : allOperations.values()) {
        final Set<String> readVariables = operation.getReadVariables();
        readVariables.retainAll(variableToComputation.keySet());
        final HashSet<String> variablesInScope = new HashSet<>();
        // defined before read.
        if (operation instanceof ComputationOperation) {
            variablesInScope.addAll(((ComputationOperation) operation).getDefineVariables());
        }
        for (AIdentifierExpression aIdentifier : operation.getDependsOnComputationList()) {
            String opName = aIdentifier.getIdentifier().get(0).getText();
            AbstractOperation abstractOperation = allOperations.get(opName);
            if (abstractOperation instanceof ComputationOperation) {
                variablesInScope.addAll(((ComputationOperation) abstractOperation).getDefineVariables());
            }
        }
        readVariables.removeAll(variablesInScope);
        if (!readVariables.isEmpty()) {
            List<ComputationOperation> inferredDependenciesToComputations = new ArrayList<>();
            for (String varName : readVariables) {
                ComputationOperation computationOperation = variableToComputation.get(varName);
                inferredDependenciesToComputations.add(computationOperation);
                List<String> machineReferences = operation.getMachineReferencesAsString();
                machineReferences.add(operation.getMachineName());
                if (!machineReferences.contains(computationOperation.getMachineName())) {
                    this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Missing reference to RULES_MACHINE '" + computationOperation.getMachineName() + "' in order to use variable '" + varName + "'.", operation.getVariableReadByName(varName))));
                }
                operation.setImplicitComputationDependencies(inferredDependenciesToComputations);
            }
        } else {
            operation.setImplicitComputationDependencies(Collections.<ComputationOperation>emptyList());
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) BException(de.be4.classicalb.core.parser.exceptions.BException) HashSet(java.util.HashSet)

Aggregations

BException (de.be4.classicalb.core.parser.exceptions.BException)22 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Start (de.be4.eventbalg.core.parser.node.Start)7 Test (org.junit.Test)7 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)6 Start (de.be4.eventb.core.parser.node.Start)6 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)4 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)4 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)3 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 PrettyPrinter (de.be4.classicalb.core.parser.util.PrettyPrinter)3 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)3 File (java.io.File)3 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)2 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)2 Token (de.be4.classicalb.core.preparser.node.Token)2 AInvariant (de.be4.eventb.core.parser.node.AInvariant)2