Search in sources :

Example 41 with TIdentifierLiteral

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

the class RulesProject method findTransitiveDependencies.

private Set<AbstractOperation> findTransitiveDependencies(final AbstractOperation operation, final List<AbstractOperation> ancestors) {
    ancestors.add(operation);
    List<TIdentifierLiteral> directDependencies = new ArrayList<>();
    directDependencies.addAll(convertAIdentifierListToTIdentifierLiteralList(operation.getDependsOnComputationList()));
    directDependencies.addAll(convertAIdentifierListToTIdentifierLiteralList(operation.getDependsOnRulesList()));
    directDependencies.addAll(operation.getImplicitDependenciesToComputations());
    directDependencies.addAll(operation.getFunctionCalls());
    // check for cycle
    Set<AbstractOperation> transitiveDependenciesFound = new HashSet<>();
    boolean cycleDetected = checkForCycles(operation, directDependencies, ancestors);
    if (cycleDetected) {
        operation.setTransitiveDependencies(transitiveDependenciesFound);
        return transitiveDependenciesFound;
    }
    for (TIdentifierLiteral tIdentifierLiteral : directDependencies) {
        String opName = tIdentifierLiteral.getText();
        AbstractOperation nextOperation = allOperations.get(opName);
        transitiveDependenciesFound.add(nextOperation);
        if (nextOperation.getTransitiveDependencies() != null) {
            transitiveDependenciesFound.addAll(nextOperation.getTransitiveDependencies());
        } else {
            transitiveDependenciesFound.addAll(findTransitiveDependencies(nextOperation, new ArrayList<>(ancestors)));
        }
    }
    operation.setTransitiveDependencies(transitiveDependenciesFound);
    return new HashSet<>(transitiveDependenciesFound);
}
Also used : ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) HashSet(java.util.HashSet)

Example 42 with TIdentifierLiteral

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

the class ASTPrologTest method testEvent.

@Test
public void testEvent() throws BCompoundException {
    final AEventBModelParseUnit model = new AEventBModelParseUnit();
    model.setName(new TIdentifierLiteral("mm"));
    final AEventsModelClause events = new AEventsModelClause();
    model.setModelClauses(Arrays.asList((PModelClause) events));
    AEvent event = new AEvent();
    events.setEvent(Arrays.asList((PEvent) event));
    event.setEventName(new TIdentifierLiteral("testevent"));
    event.setVariables(Arrays.asList(createId("param")));
    event.setGuards(Arrays.asList((PPredicate) new ATruthPredicate()));
    PSubstitution subst1 = new AAssignSubstitution(Arrays.asList(createId("x")), Arrays.asList(createId("param")));
    event.setAssignments(Arrays.asList(subst1));
    PWitness witness = new AWitness(new TIdentifierLiteral("ab"), new AEqualPredicate(createId("ab"), createId("y")));
    event.setWitness(Arrays.asList(witness));
    event.setRefines(Arrays.asList(new TIdentifierLiteral("abstract1"), new TIdentifierLiteral("abstract2")));
    checkAST(0, "event_b_model($,mm,[events($,[" + "event($,testevent,[abstract1,abstract2],[identifier($,param)],[truth($)],[]," + "[assign($,[identifier($,x)],[identifier($,param)])]," + "[witness($,identifier(%,ab),equal($,identifier($,ab),identifier($,y)))])])])", model);
}
Also used : AEqualPredicate(de.be4.classicalb.core.parser.node.AEqualPredicate) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PEvent(de.be4.classicalb.core.parser.node.PEvent) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) AWitness(de.be4.classicalb.core.parser.node.AWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) PWitness(de.be4.classicalb.core.parser.node.PWitness) AEvent(de.be4.classicalb.core.parser.node.AEvent) ATruthPredicate(de.be4.classicalb.core.parser.node.ATruthPredicate) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause) AAssignSubstitution(de.be4.classicalb.core.parser.node.AAssignSubstitution) Test(org.junit.Test)

Example 43 with TIdentifierLiteral

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

the class PreParser method determineDependencies.

private Map<String, Set<String>> determineDependencies(Set<String> definitionNames, Map<Token, Token> definitions) throws PreParseException {
    HashMap<String, Set<String>> dependencies = new HashMap<>();
    for (Entry<Token, Token> entry : definitions.entrySet()) {
        Token nameToken = entry.getKey();
        Token rhsToken = entry.getValue();
        // The FORMULA_PREFIX is needed to switch the lexer state from
        // section to normal. Note, that we do not parse the right hand side
        // of the definition here. Hence FORMULA_PREFIX has no further
        // meaning and substitutions can also be handled by the lexer.
        final Reader reader = new StringReader(BParser.FORMULA_PREFIX + "\n" + rhsToken.getText());
        final BLexer lexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), new DefinitionTypes());
        lexer.setParseOptions(parseOptions);
        Set<String> set = new HashSet<>();
        de.be4.classicalb.core.parser.node.Token next = null;
        try {
            next = lexer.next();
            while (!(next instanceof EOF)) {
                if (next instanceof TIdentifierLiteral) {
                    TIdentifierLiteral id = (TIdentifierLiteral) next;
                    String name = id.getText();
                    if (definitionNames.contains(name)) {
                        set.add(name);
                    }
                }
                next = lexer.next();
            }
        } catch (IOException e) {
        } catch (BLexerException e) {
            de.be4.classicalb.core.parser.node.Token errorToken = e.getLastToken();
            final String newMessage = determineNewErrorMessageWithCorrectedPositionInformations(nameToken, rhsToken, errorToken, e.getMessage());
            throw new PreParseException(newMessage);
        } catch (de.be4.classicalb.core.parser.lexer.LexerException e) {
            final String newMessage = determineNewErrorMessageWithCorrectedPositionInformationsWithoutToken(nameToken, rhsToken, e.getMessage());
            throw new PreParseException(newMessage);
        }
        dependencies.put(nameToken.getText(), set);
    }
    return dependencies;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Reader(java.io.Reader) StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader) Token(de.be4.classicalb.core.preparser.node.Token) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) StringReader(java.io.StringReader) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) EOF(de.be4.classicalb.core.parser.node.EOF) HashSet(java.util.HashSet) IOException(java.io.IOException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PushbackReader(java.io.PushbackReader)

Example 44 with TIdentifierLiteral

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

the class CTagsGenerator method createCTagsFromMachines.

private static Collection<? extends CTagsEntry> createCTagsFromMachines(RulesProject project) {
    List<CTagsEntry> list = new ArrayList<>();
    for (IModel model : project.bModels) {
        if (model instanceof RulesParseUnit) {
            RulesParseUnit parseUnit = (RulesParseUnit) model;
            if (null != parseUnit.getRulesMachineChecker()) {
                TIdentifierLiteral literal = parseUnit.getRulesMachineChecker().getNameLiteral();
                list.add(new CTagsEntry(literal.getText(), parseUnit.getPath(), literal.getStartPos(), TYPE_MACHINE));
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 45 with TIdentifierLiteral

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

the class EnumeratedSetElement method createASTNode.

public PExpression createASTNode(Typechecker typechecker) {
    TIdentifierLiteral literal = new TIdentifierLiteral(name);
    ArrayList<TIdentifierLiteral> idList = new ArrayList<TIdentifierLiteral>();
    idList.add(literal);
    AIdentifierExpression id = new AIdentifierExpression(idList);
    typechecker.setType(id, new SetType(this));
    return id;
}
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