use of de.be4.classicalb.core.parser.exceptions.CheckException 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.CheckException 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.CheckException 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());
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesTransformation method outAOperatorPredicate.
@Override
public void outAOperatorPredicate(AOperatorPredicate node) {
// currently all operator handle rule names
final List<PExpression> arguments = new ArrayList<>(node.getIdentifiers());
final String operatorName = node.getName().getText();
final AIdentifierExpression ruleIdentifier = (AIdentifierExpression) arguments.get(0);
final String ruleName = ruleIdentifier.getIdentifier().get(0).getText();
AbstractOperation operation = allOperations.get(ruleName);
if (operation == null || !(operation instanceof RuleOperation)) {
errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
return;
}
final RuleOperation rule = (RuleOperation) operation;
switch(operatorName) {
case RulesGrammar.SUCCEEDED_RULE:
replacePredicateOperator(node, arguments, RULE_SUCCESS);
return;
case RulesGrammar.SUCCEEDED_RULE_ERROR_TYPE:
replaceSucceededRuleErrorTypeOperator(node, ruleName, rule);
return;
case RulesGrammar.FAILED_RULE:
replacePredicateOperator(node, arguments, RULE_FAIL);
return;
case RulesGrammar.FAILED_RULE_ALL_ERROR_TYPES:
replaceFailedRuleAllErrorTypesOperator(node, rule);
return;
case RulesGrammar.FAILED_RULE_ERROR_TYPE:
replaceFailedRuleErrorTypeOperator(node, rule);
return;
case RulesGrammar.NOT_CHECKED_RULE:
replacePredicateOperator(node, arguments, RULE_NOT_CHECKED);
return;
case RulesGrammar.DISABLED_RULE:
replacePredicateOperator(node, arguments, RULE_DISABLED);
return;
default:
throw new AssertionError("should not happen: " + operatorName);
}
}
use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.
the class RulesTransformation method translateGetRuleCounterExamplesOperator.
private void translateGetRuleCounterExamplesOperator(AOperatorExpression node) {
final PExpression pExpression = node.getIdentifiers().get(0);
final AIdentifierExpression id = (AIdentifierExpression) pExpression;
final String ruleName = id.getIdentifier().get(0).getText();
final AbstractOperation operation = allOperations.get(ruleName);
if (operation == null || !(operation instanceof RuleOperation)) {
errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
return;
}
final RuleOperation rule = (RuleOperation) operation;
final String name = id.getIdentifier().get(0).getText() + RULE_COUNTER_EXAMPLE_VARIABLE_SUFFIX;
if (node.getIdentifiers().size() == 1) {
final AIdentifierExpression ctVariable = createIdentifier(name, pExpression);
final ARangeExpression range = createPositinedNode(new ARangeExpression(ctVariable), node);
node.replaceBy(range);
} else {
PExpression funcCall = getSetOfErrorMessagesByErrorType(name, node.getIdentifiers().get(1), rule.getNumberOfErrorTypes());
node.replaceBy(funcCall);
}
return;
}
Aggregations