Search in sources :

Example 76 with Node

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);
    }
}
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 77 with Node

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));
        }
    }
}
Also used : Type(de.be4.classicalb.core.parser.IDefinitions.Type) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 78 with 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);
}
Also used : NodeCloner.cloneNode(de.be4.classicalb.core.parser.util.NodeCloner.cloneNode) ArrayList(java.util.ArrayList)

Example 79 with Node

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

Example 80 with Node

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

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3