use of de.be4.eventbalg.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class OpSubstitutions method setTypeSubstDef.
private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
final Node defRhs = oldDefinition.getRhs();
final PSubstitution rhsSubst;
if (defRhs instanceof AFunctionExpression) {
final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
rhsSubst.setStartPos(rhsFunction.getStartPos());
rhsSubst.setEndPos(rhsFunction.getEndPos());
} else if (defRhs instanceof AIdentifierExpression) {
final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
rhsSubst.setStartPos(rhsIdent.getStartPos());
rhsSubst.setEndPos(rhsIdent.getEndPos());
} else {
// some other expression was parsed (NOT allowed)
throw new VisitorException(new CheckException("Expecting operation", node));
}
final TIdentifierLiteral oldDefId = oldDefinition.getName();
final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
substDef.setStartPos(oldDefinition.getStartPos());
substDef.setEndPos(oldDefinition.getEndPos());
definitions.replaceDefinition(idString, Type.Substitution, substDef);
oldDefinition.replaceBy(substDef);
}
use of de.be4.eventbalg.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class OpSubstitutions method replaceWithDefExpression.
private ADefinitionExpression replaceWithDefExpression(final Node node, TIdentifierLiteral identifier, final List<PExpression> paramList) {
final ADefinitionExpression newNode = new ADefinitionExpression();
newNode.setDefLiteral(identifier);
if (paramList != null) {
newNode.setParameters(paramList);
}
final PositionedNode posNode = node;
final PositionedNode newPosNode = newNode;
newPosNode.setStartPos(posNode.getStartPos());
newPosNode.setEndPos(posNode.getEndPos());
node.replaceBy(newNode);
return newNode;
}
use of de.be4.eventbalg.core.parser.node.TIdentifierLiteral 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.eventbalg.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.
the class RulesProject method checkVisibilityOfTIdentifierList.
private void checkVisibilityOfTIdentifierList(AbstractOperation operation, List<TIdentifierLiteral> dependencyList) {
List<String> machineReferences = operation.getMachineReferencesAsString();
machineReferences.add(operation.getMachineName());
for (TIdentifierLiteral tIdentifierLiteral : dependencyList) {
String otherOpName = tIdentifierLiteral.getText();
if (allOperations.containsKey(otherOpName)) {
AbstractOperation abstractOperation = allOperations.get(otherOpName);
String otherMachineName = abstractOperation.getMachineName();
if (!machineReferences.contains(otherMachineName)) {
this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + otherOpName + "' is not visible in RULES_MACHINE '" + operation.getMachineName() + "'.", tIdentifierLiteral)));
}
}
}
}
use of de.be4.eventbalg.core.parser.node.TIdentifierLiteral 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());
}
}
Aggregations