Search in sources :

Example 21 with CheckException

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

the class RulesMachineChecker method inAOperationCallSubstitution.

@Override
public void inAOperationCallSubstitution(AOperationCallSubstitution node) {
    LinkedList<TIdentifierLiteral> opNameList = node.getOperation();
    if (opNameList.size() > 1) {
        errorList.add(new CheckException("Renaming of operation names is not allowed.", node));
    }
    List<PExpression> copy = new ArrayList<>(node.getResultIdentifiers());
    checkThatIdentifiersAreLocalVariables(copy);
    if (currentOperation != null) {
        currentOperation.addFunctionCall(opNameList.get(0));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 22 with CheckException

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

the class RulesReferencesFinder method registerMachineReference.

private void registerMachineReference(AMachineReference mchRef) {
    String name = mchRef.getMachineName().get(0).getText();
    try {
        final File file = lookupFile(mainFile.getParentFile(), name, mchRef);
        RulesMachineReference rulesMachineReference = new RulesMachineReference(file, name, mchRef);
        referncesTable.put(name, rulesMachineReference);
    } catch (CheckException e) {
        errorList.add(e);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) File(java.io.File)

Example 23 with CheckException

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

the class RulesReferencesFinder method findReferencedMachines.

public void findReferencedMachines() throws BCompoundException {
    this.start.apply(this);
    if (!errorList.isEmpty()) {
        final List<BException> bExceptionList = new ArrayList<>();
        for (CheckException checkException : errorList) {
            final BException bException = new BException(mainFile.getAbsolutePath(), checkException);
            bExceptionList.add(bException);
        }
        throw new BCompoundException(bExceptionList);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) BException(de.be4.classicalb.core.parser.exceptions.BException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 24 with CheckException

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

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

the class RulesProject method checkReferencedRuleOperations.

public void checkReferencedRuleOperations() {
    if (this.hasErrors()) {
        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) {
        if (model instanceof RulesParseUnit) {
            RulesParseUnit rulesParseUnit = (RulesParseUnit) model;
            Set<AIdentifierExpression> referencedRuleOperations = rulesParseUnit.getRulesMachineChecker().getReferencedRuleOperations();
            final HashSet<String> knownRules = new HashSet<>();
            for (RuleOperation ruleOperation : rulesParseUnit.getRulesMachineChecker().getRuleOperations()) {
                knownRules.add(ruleOperation.getName());
            }
            for (RulesMachineReference rulesMachineReference : rulesParseUnit.getMachineReferences()) {
                String referenceName = rulesMachineReference.getName();
                RulesParseUnit otherParseUnit = map.get(referenceName);
                for (RuleOperation ruleOperation : otherParseUnit.getRulesMachineChecker().getRuleOperations()) {
                    knownRules.add(ruleOperation.getName());
                }
            }
            for (AIdentifierExpression aIdentifierExpression : referencedRuleOperations) {
                String ruleName = Utils.getAIdentifierAsString(aIdentifierExpression);
                if (!knownRules.contains(ruleName)) {
                    this.bExceptionList.add(new BException(rulesParseUnit.getPath(), new CheckException("Unknown rule '" + ruleName + "'.", aIdentifierExpression)));
                }
            }
        }
    }
}
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) BException(de.be4.classicalb.core.parser.exceptions.BException) HashSet(java.util.HashSet)

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