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));
}
}
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);
}
}
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);
}
}
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;
}
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)));
}
}
}
}
}
Aggregations