use of de.be4.classicalb.core.parser.rules.AbstractOperation 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.rules.AbstractOperation 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;
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project prob2 by bendisposto.
the class RulesChecker method getOperationState.
public OperationStatus getOperationState(String opName) {
checkThatOperationExists(opName);
checkThatOperationIsNotAFunctionOperation(opName);
init();
AbstractOperation abstractOperation = rulesProject.getOperationsMap().get(opName);
return this.operationStatuses.get(abstractOperation);
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project prob2 by bendisposto.
the class RulesChecker method executeOperationAndDependencies.
public boolean executeOperationAndDependencies(String opName) {
checkThatOperationExists(opName);
checkThatOperationIsNotAFunctionOperation(opName);
AbstractOperation goalOperation = rulesProject.getOperationsMap().get(opName);
init();
List<AbstractOperation> executionOrder = goalOperation.getSortedListOfTransitiveDependencies();
executionOrder.add(goalOperation);
executionOrder = executionOrder.stream().filter(op -> !(op instanceof FunctionOperation)).collect(Collectors.toList());
List<AbstractOperation> operationsToBeExecuted = new ArrayList<>();
for (AbstractOperation dep : executionOrder) {
OperationStatus operationStatus = operationStatuses.get(dep);
if (operationStatus.isDisabled()) {
return false;
}
if (dep != goalOperation && operationStatus == RuleStatus.FAIL) {
return false;
}
if (operationStatus.isNotExecuted()) {
operationsToBeExecuted.add(dep);
}
}
for (AbstractOperation op : operationsToBeExecuted) {
OperationStatus opState = executeOperation(op);
if (op != goalOperation && opState == RuleStatus.FAIL) {
return false;
}
}
return true;
}
use of de.be4.classicalb.core.parser.rules.AbstractOperation in project prob2 by bendisposto.
the class RulesChecker method determineDepedencies.
private void determineDepedencies() {
for (AbstractOperation op : rulesProject.getOperationsMap().values()) {
if (!(op instanceof FunctionOperation)) {
Set<AbstractOperation> set = op.getTransitiveDependencies().stream().filter(p -> !(p instanceof FunctionOperation)).collect(Collectors.toSet());
predecessors.put(op, set);
for (AbstractOperation abstractOperation : set) {
if (!successors.containsKey(abstractOperation)) {
successors.put(abstractOperation, new HashSet<>());
}
successors.get(abstractOperation).add(op);
}
}
}
}
Aggregations