Search in sources :

Example 21 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class InterpreterTerms method refEntries.

private static ITerm refEntries(IScopeGraph<Scope, Label, Occurrence> scopeGraph) {
    Map<ITerm, ITerm> entries = Maps.newHashMap();
    for (Occurrence ref : scopeGraph.getAllRefs()) {
        ITerm scope = scopeGraph.getRefs().get(ref).map(s -> B.newList(s)).orElse(B.newNil());
        ITerm entry = B.newAppl("RE", scope);
        entries.put(ref, entry);
    }
    return map(entries.entrySet());
}
Also used : B(mb.nabl2.terms.build.TermBuild.B) Iterables(com.google.common.collect.Iterables) IUnifier(mb.nabl2.terms.unification.IUnifier) DeclProperties(mb.nabl2.constraints.namebinding.DeclProperties) ITerm(mb.nabl2.terms.ITerm) Set(java.util.Set) Scope(mb.nabl2.scopegraph.terms.Scope) IResolutionPath(mb.nabl2.scopegraph.path.IResolutionPath) Multimap(com.google.common.collect.Multimap) Occurrence(mb.nabl2.scopegraph.terms.Occurrence) IProperties(mb.nabl2.util.collections.IProperties) Maps(com.google.common.collect.Maps) IEsopNameResolution(mb.nabl2.scopegraph.esop.IEsopNameResolution) List(java.util.List) IScopeGraph(mb.nabl2.scopegraph.IScopeGraph) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Paths(mb.nabl2.scopegraph.terms.path.Paths) Label(mb.nabl2.scopegraph.terms.Label) IListTerm(mb.nabl2.terms.IListTerm) Map(java.util.Map) LoggerUtils(org.metaborg.util.log.LoggerUtils) ISolution(mb.nabl2.solver.ISolution) ILogger(org.metaborg.util.log.ILogger) ITerm(mb.nabl2.terms.ITerm) Occurrence(mb.nabl2.scopegraph.terms.Occurrence)

Example 22 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class InterpreterTerms method nameresolution.

private static ITerm nameresolution(IEsopNameResolution<Scope, Label, Occurrence> nameResolution) {
    nameResolution.resolveAll();
    final Map<ITerm, ITerm> entries = Maps.newHashMap();
    for (Map.Entry<Occurrence, Set<IResolutionPath<Scope, Label, Occurrence>>> entry : nameResolution.resolutionEntries()) {
        final Occurrence ref = entry.getKey();
        final Set<IResolutionPath<Scope, Label, Occurrence>> paths = entry.getValue();
        if (paths.size() == 1) {
            IResolutionPath<Scope, Label, Occurrence> path = Iterables.getOnlyElement(paths);
            ITerm value = B.newTuple(path.getDeclaration(), Paths.toTerm(path));
            entries.put(ref, value);
        } else {
            logger.warn("Can only convert a single path, but {} has {}.", ref, paths.size());
        }
    }
    return map(entries.entrySet());
}
Also used : IResolutionPath(mb.nabl2.scopegraph.path.IResolutionPath) Set(java.util.Set) Scope(mb.nabl2.scopegraph.terms.Scope) Label(mb.nabl2.scopegraph.terms.Label) ITerm(mb.nabl2.terms.ITerm) Map(java.util.Map) Occurrence(mb.nabl2.scopegraph.terms.Occurrence)

Example 23 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class InterpreterTerms method declEntries.

private static ITerm declEntries(IScopeGraph<Scope, Label, Occurrence> scopeGraph) {
    Map<ITerm, ITerm> entries = Maps.newHashMap();
    for (Occurrence decl : scopeGraph.getAllDecls()) {
        ITerm scope = scopeGraph.getDecls().get(decl).map(s -> B.newList(s)).orElse(B.newNil());
        ITerm assocs = multimap(scopeGraph.getExportEdges().get(decl));
        ITerm entry = B.newAppl("DE", scope, assocs);
        entries.put(decl, entry);
    }
    return map(entries.entrySet());
}
Also used : B(mb.nabl2.terms.build.TermBuild.B) Iterables(com.google.common.collect.Iterables) IUnifier(mb.nabl2.terms.unification.IUnifier) DeclProperties(mb.nabl2.constraints.namebinding.DeclProperties) ITerm(mb.nabl2.terms.ITerm) Set(java.util.Set) Scope(mb.nabl2.scopegraph.terms.Scope) IResolutionPath(mb.nabl2.scopegraph.path.IResolutionPath) Multimap(com.google.common.collect.Multimap) Occurrence(mb.nabl2.scopegraph.terms.Occurrence) IProperties(mb.nabl2.util.collections.IProperties) Maps(com.google.common.collect.Maps) IEsopNameResolution(mb.nabl2.scopegraph.esop.IEsopNameResolution) List(java.util.List) IScopeGraph(mb.nabl2.scopegraph.IScopeGraph) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Paths(mb.nabl2.scopegraph.terms.path.Paths) Label(mb.nabl2.scopegraph.terms.Label) IListTerm(mb.nabl2.terms.IListTerm) Map(java.util.Map) LoggerUtils(org.metaborg.util.log.LoggerUtils) ISolution(mb.nabl2.solver.ISolution) ILogger(org.metaborg.util.log.ILogger) ITerm(mb.nabl2.terms.ITerm) Occurrence(mb.nabl2.scopegraph.terms.Occurrence)

Example 24 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class InterpreterTerms method multimap.

private static IListTerm multimap(Iterable<? extends Map.Entry<? extends ITerm, ? extends ITerm>> entries) {
    Multimap<ITerm, ITerm> grouped = HashMultimap.create();
    for (Map.Entry<? extends ITerm, ? extends ITerm> entry : entries) {
        grouped.put(entry.getKey(), entry.getValue());
    }
    List<ITerm> entryterms = Lists.newArrayList();
    for (ITerm key : grouped.keySet()) {
        entryterms.add(B.newTuple(key, B.newList(grouped.get(key))));
    }
    return B.newList(entryterms);
}
Also used : ITerm(mb.nabl2.terms.ITerm) Map(java.util.Map)

Example 25 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class Solution method findAndLock.

@Override
public ISolution findAndLock() {
    final IProperties.Transient<TermIndex, ITerm, ITerm> astProperties = astProperties().melt();
    astProperties.mapValues(unifier()::findRecursive);
    final IProperties.Transient<Occurrence, ITerm, ITerm> declProperties = declProperties().melt();
    declProperties.mapValues(unifier()::findRecursive);
    final ISymbolicConstraints symbolic = symbolic().map(unifier()::findRecursive);
    return ImmutableSolution.builder().from(this).astProperties(astProperties.freeze()).declProperties(declProperties.freeze()).symbolic(symbolic).build();
}
Also used : ISymbolicConstraints(mb.nabl2.symbolic.ISymbolicConstraints) ITerm(mb.nabl2.terms.ITerm) IProperties(mb.nabl2.util.collections.IProperties) Occurrence(mb.nabl2.scopegraph.terms.Occurrence) TermIndex(mb.nabl2.stratego.TermIndex)

Aggregations

ITerm (mb.nabl2.terms.ITerm)79 Test (org.junit.Test)24 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)19 Scope (mb.nabl2.scopegraph.terms.Scope)18 SolveResult (mb.nabl2.solver.ISolver.SolveResult)16 Optional (java.util.Optional)15 IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)15 ITermVar (mb.nabl2.terms.ITermVar)15 Label (mb.nabl2.scopegraph.terms.Label)14 Map (java.util.Map)12 Set (java.util.Set)10 MessageContent (mb.nabl2.constraints.messages.MessageContent)10 SolverCore (mb.nabl2.solver.SolverCore)9 IUnifier (mb.nabl2.terms.unification.IUnifier)9 Function1 (org.metaborg.util.functions.Function1)9 Lists (com.google.common.collect.Lists)8 ISolution (mb.nabl2.solver.ISolution)8 HashMultimap (com.google.common.collect.HashMultimap)7 Multimap (com.google.common.collect.Multimap)7 IConstraint (mb.nabl2.constraints.IConstraint)7