use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class OpSubstitutions method caseAFunctionExpression.
@Override
public void caseAFunctionExpression(final AFunctionExpression node) {
if (node.getIdentifier() != null) {
node.getIdentifier().apply(this);
}
if (node.getIdentifier() instanceof ADefinitionExpression && ((ADefinitionExpression) node.getIdentifier()).getParameters().isEmpty()) {
final LinkedList<PExpression> paramList = new LinkedList<>(node.getParameters());
final TIdentifierLiteral identifier = ((ADefinitionExpression) node.getIdentifier()).getDefLiteral();
if (paramList.size() <= definitions.getParameterCount(identifier.getText())) {
/*
* The parameters seem to belong to this definition, so we need
* to replace the FunctionExpression by a
* DefinitionFunctionExpression. If not enough parameters were
* given this will be found by a later check, i.e.
* DefinitionUsageCheck.
*/
final ADefinitionExpression newNode = replaceWithDefExpression(node, identifier, paramList);
final List<PExpression> copy = newNode.getParameters();
for (final PExpression e : copy) {
e.apply(this);
}
return;
}
}
/*
* Reached in case that: Identifier of this FunctionExpression is not a
* definition or there were more parameters than the definition needs
* (by declaration), so we asume the parameters belong to some other
* construct (for example a function a level higher in the AST).
*/
final List<PExpression> copy = node.getParameters();
for (final PExpression e : copy) {
e.apply(this);
}
}
use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class OpSubstitutions method caseAIdentifierExpression.
@Override
public void caseAIdentifierExpression(final AIdentifierExpression node) {
final String identifierString = Utils.getTIdentifierListAsString(node.getIdentifier());
final Integer number = scopedVariables.get(identifierString);
final Type type = definitions.getType(identifierString);
if (number == null && type != Type.NoDefinition) {
if (type == Type.Expression || type == Type.ExprOrSubst) {
/*
* getFirst() is enough cause definitions cannot have composed
* identifiers
*/
replaceWithDefExpression(node, node.getIdentifier().getFirst(), null);
if (type == Type.ExprOrSubst) {
// type is determined now => set to Expression
definitions.setDefinitionType(identifierString, Type.Expression);
}
} else {
// finding some other type here is an error!
throw new VisitorException(new CheckException("Expecting expression here but found definition with type '" + type + "'", node));
}
}
}
use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class RulesTransformation method outARuleFailSubSubstitution.
@Override
public void outARuleFailSubSubstitution(ARuleFailSubSubstitution node) {
addForceDefinition(iDefinitions);
Node newNode = null;
if (!node.getIdentifiers().isEmpty()) {
newNode = createPositinedNode(createCounterExampleSubstitutions(node.getIdentifiers(), node.getWhen(), null, node.getMessage(), node.getErrorType()), node);
} else {
// default value if no value is provided
int errorType = 1;
if (node.getErrorType() != null) {
errorType = Integer.parseInt(node.getErrorType().getText());
}
PSubstitution sub = createCounterExampleSubstitution(errorType, createSetOfPExpression(node.getMessage(), node.getMessage()), false);
if (node.getWhen() != null) {
// there is a when predicate but no parameters
newNode = new AIfSubstitution(node.getWhen(), sub, new ArrayList<PSubstitution>(), null);
} else {
// no parameters and no when predicate
newNode = sub;
}
}
node.replaceBy(newNode);
}
use of de.be4.classicalb.core.parser.node.Node 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();
}
use of de.be4.classicalb.core.parser.node.Node in project probparsers by bendisposto.
the class RulesMachineChecker method inAAssignSubstitution.
@Override
public void inAAssignSubstitution(AAssignSubstitution node) {
ArrayList<PExpression> righthand = new ArrayList<>(node.getRhsExpressions());
for (PExpression pExpression : righthand) {
pExpression.apply(this);
}
List<PExpression> copy = new ArrayList<>(node.getLhsExpression());
checkThatIdentifiersAreLocalVariables(copy);
}
Aggregations