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