Search in sources :

Example 16 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class OpSubstitutions method caseAFuncOpSubstitution.

@Override
public void caseAFuncOpSubstitution(final AFuncOpSubstitution node) {
    final PExpression expression = node.getFunction();
    PExpression idExpr = null;
    LinkedList<PExpression> parameters = null;
    Type type = null;
    TIdentifierLiteral idToken = null;
    String idString = null;
    if (expression instanceof AFunctionExpression) {
        // the operation was parsed as a function expression
        final AFunctionExpression function = (AFunctionExpression) expression;
        final PExpression funcId = function.getIdentifier();
        if (funcId instanceof AIdentifierExpression) {
            final AIdentifierExpression identifier = (AIdentifierExpression) funcId;
            idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
            idToken = identifier.getIdentifier().get(0);
            type = definitions.getType(idString);
        } else {
            type = Type.NoDefinition;
        }
        idExpr = function.getIdentifier();
        parameters = new LinkedList<>(function.getParameters());
    } else if (expression instanceof AIdentifierExpression) {
        // the operation was parsed as an identifier expression
        final AIdentifierExpression identifier = (AIdentifierExpression) expression;
        idString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
        idToken = identifier.getIdentifier().get(0);
        type = definitions.getType(idString);
        idExpr = expression;
        parameters = new LinkedList<>();
    } else {
        // some other expression was parsed (NOT allowed)
        throw new BParseException(null, "Expecting operation");
    }
    if (type != Type.NoDefinition && idToken != null) {
        if (type == Type.Substitution || type == Type.ExprOrSubst) {
            // create DefinitionSubstitution
            final ADefinitionSubstitution defSubst = new ADefinitionSubstitution(new TDefLiteralSubstitution(idToken.getText(), idToken.getLine(), idToken.getPos()), parameters);
            if (type == Type.ExprOrSubst) {
                // type is determined now => set to Substitution
                setTypeSubstDef(node, idString);
            }
            // transfer position information
            final PositionedNode posNode = node;
            final PositionedNode newPosNode = defSubst;
            newPosNode.setStartPos(posNode.getStartPos());
            newPosNode.setEndPos(posNode.getEndPos());
            node.replaceBy(defSubst);
            defSubst.apply(this);
        } else {
            // finding some other type here is an error!
            throw new VisitorException(new CheckException("Expecting substitution here but found definition with type '" + type + "'", node));
        }
    } else {
        // no def, no problem ;-)
        final AOpSubstitution opSubst = new AOpSubstitution(idExpr, parameters);
        opSubst.setStartPos(idExpr.getStartPos());
        opSubst.setEndPos(idExpr.getEndPos());
        node.replaceBy(opSubst);
        opSubst.apply(this);
    }
}
Also used : TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BParseException(de.be4.classicalb.core.parser.exceptions.BParseException) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList) Type(de.be4.classicalb.core.parser.IDefinitions.Type) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression) ADefinitionSubstitution(de.be4.classicalb.core.parser.node.ADefinitionSubstitution) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException) AOpSubstitution(de.be4.classicalb.core.parser.node.AOpSubstitution)

Example 17 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class RulesMachineChecker method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    if (!node.getParameters().isEmpty()) {
        errorList.add(new CheckException("A RULES_MACHINE must not have any machine parameters", node));
    }
    LinkedList<TIdentifierLiteral> nameList = node.getName();
    if (nameList.size() > 1) {
        errorList.add(new CheckException("Renaming of a RULES_MACHINE name is not allowed.", node));
    }
    this.nameLiteral = nameList.get(0);
    this.machineName = nameLiteral.getText();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 18 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class RulesMachineChecker method inAOperationCallSubstitution.

@Override
public void inAOperationCallSubstitution(AOperationCallSubstitution node) {
    LinkedList<TIdentifierLiteral> opNameList = node.getOperation();
    if (opNameList.size() > 1) {
        errorList.add(new CheckException("Renaming of operation names is not allowed.", node));
    }
    List<PExpression> copy = new ArrayList<>(node.getResultIdentifiers());
    checkThatIdentifiersAreLocalVariables(copy);
    if (currentOperation != null) {
        currentOperation.addFunctionCall(opNameList.get(0));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 19 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class RulesProject method checkForCycles.

private boolean checkForCycles(AbstractOperation operation, List<TIdentifierLiteral> directDependencies, List<AbstractOperation> ancestors) {
    List<String> ancestorsNames = new ArrayList<>();
    for (AbstractOperation op : ancestors) {
        String opName = op.getName();
        ancestorsNames.add(opName);
    }
    for (TIdentifierLiteral id : directDependencies) {
        final String opName = id.getText();
        if (ancestorsNames.contains(opName)) {
            StringBuilder sb = new StringBuilder();
            for (int index = ancestorsNames.indexOf(opName); index < ancestors.size(); index++) {
                final String name = ancestors.get(index).getName();
                sb.append(name);
                sb.append(" -> ");
            }
            sb.append(opName);
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Cyclic dependencies between operations: " + sb.toString(), id)));
            return true;
        }
    }
    return false;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) BException(de.be4.classicalb.core.parser.exceptions.BException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 20 with TIdentifierLiteral

use of de.be4.classicalb.core.parser.node.TIdentifierLiteral in project probparsers by bendisposto.

the class RulesProject method checkVisibilityOfAIdentifierList.

private void checkVisibilityOfAIdentifierList(AbstractOperation operation, List<AIdentifierExpression> dependencyList) {
    List<TIdentifierLiteral> tidentifierList = new ArrayList<>();
    for (AIdentifierExpression aIdentifier : dependencyList) {
        tidentifierList.add(aIdentifier.getIdentifier().get(0));
    }
    checkVisibilityOfTIdentifierList(operation, tidentifierList);
}
Also used : AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) 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