Search in sources :

Example 36 with TIdentifierLiteral

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);
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Node(de.be4.classicalb.core.parser.node.Node) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AOpSubstitution(de.be4.classicalb.core.parser.node.AOpSubstitution) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 37 with TIdentifierLiteral

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;
}
Also used : ADefinitionExpression(de.be4.classicalb.core.parser.node.ADefinitionExpression) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode)

Example 38 with TIdentifierLiteral

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);
    }
}
Also used : ADefinitionExpression(de.be4.classicalb.core.parser.node.ADefinitionExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList)

Example 39 with TIdentifierLiteral

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)));
            }
        }
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) BException(de.be4.classicalb.core.parser.exceptions.BException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 40 with 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());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) BException(de.be4.classicalb.core.parser.exceptions.BException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Aggregations

TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)44 ArrayList (java.util.ArrayList)23 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)13 PExpression (de.be4.classicalb.core.parser.node.PExpression)9 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)8 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)8 ATotalFunctionExpression (de.be4.classicalb.core.parser.node.ATotalFunctionExpression)5 LinkedList (java.util.LinkedList)4 BException (de.be4.classicalb.core.parser.exceptions.BException)3 APowSubsetExpression (de.be4.classicalb.core.parser.node.APowSubsetExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)3 TStringLiteral (de.be4.classicalb.core.parser.node.TStringLiteral)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)3 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)2 AConstructorFreetypeConstructor (de.be4.classicalb.core.parser.node.AConstructorFreetypeConstructor)2 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)2