use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.
the class RulesMachineChecker method checkOperationPredicateAttribute.
private void checkOperationPredicateAttribute(OccurredAttributes occurredAttributes, POperationAttribute pOperationAttribute) throws AssertionError {
APredicateAttributeOperationAttribute attr = (APredicateAttributeOperationAttribute) pOperationAttribute;
PPredicate predicate = attr.getPredicate();
final String attrName = attr.getName().getText();
occurredAttributes.add(attrName, pOperationAttribute);
switch(attrName) {
case RulesGrammar.ACTIVATION:
if (currentOperation instanceof FunctionOperation) {
errorList.add(new CheckException("ACTIVATION is not a valid attribute of a FUNCTION operation.", pOperationAttribute));
} else {
currentOperation.setActivationPredicate(predicate);
}
break;
case RulesGrammar.PRECONDITION:
if (currentOperation instanceof FunctionOperation) {
FunctionOperation func = (FunctionOperation) currentOperation;
func.setPreconditionPredicate(predicate);
} else {
errorList.add(new CheckException("PRECONDITION clause is not allowed for a RULE or COMPUTATION operation", pOperationAttribute));
}
break;
case RulesGrammar.POSTCONDITION:
if (currentOperation instanceof RuleOperation) {
errorList.add(new CheckException("POSTCONDITION attribute is not allowed for a RULE operation", pOperationAttribute));
} else {
currentOperation.setPostcondition(predicate);
}
break;
default:
throw new AssertionError("Unexpected operation attribute: " + attrName);
}
predicate.apply(this);
}
use of de.be4.classicalb.core.parser.rules.FunctionOperation 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.FunctionOperation 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);
}
}
}
}
use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.
the class RulesProject method checkFunctionCalls.
private void checkFunctionCalls(AbstractOperation abstractOperation) {
boolean errorOccured = false;
for (TIdentifierLiteral tIdentifierLiteral : abstractOperation.getFunctionCalls()) {
final String functionName = tIdentifierLiteral.getText();
if (!allOperations.containsKey(functionName) || !(allOperations.get(functionName) instanceof FunctionOperation)) {
this.bExceptionList.add(new BException(abstractOperation.getFileName(), new CheckException("Unknown FUNCTION name '" + functionName + "'", tIdentifierLiteral)));
errorOccured = true;
}
}
if (!errorOccured) {
checkVisibilityOfTIdentifierList(abstractOperation, abstractOperation.getFunctionCalls());
}
}
use of de.be4.classicalb.core.parser.rules.FunctionOperation in project probparsers by bendisposto.
the class RulesMachineChecker method caseAFunctionOperation.
@Override
public void caseAFunctionOperation(AFunctionOperation node) {
currentOperation = new FunctionOperation(node.getName(), this.fileName, this.machineName, machineReferences);
functionMap.put(node, (FunctionOperation) currentOperation);
this.identifierScope.createNewScope(new ArrayList<>(node.getParameters()));
this.identifierScope.createNewScope(new ArrayList<>(node.getReturnValues()), true);
visitOperationAttributes(node.getAttributes());
node.getBody().apply(this);
currentOperation = null;
this.identifierScope.removeScope();
}
Aggregations