Search in sources :

Example 1 with ScopeGraphComponent

use of mb.nabl2.solver.components.ScopeGraphComponent in project nabl by metaborg.

the class BaseSolver method solveGraph.

public GraphSolution solveGraph(BaseSolution initial, Function1<String, String> fresh, ICancel cancel, IProgress progress) throws SolverException, InterruptedException {
    // shared
    final Ref<IUnifier.Immutable> unifier = new Ref<>(initial.unifier());
    final IEsopScopeGraph.Transient<Scope, Label, Occurrence, ITerm> scopeGraph = EsopScopeGraph.Transient.of();
    // solver components
    final SolverCore core = new SolverCore(initial.config(), unifier, fresh, callExternal);
    final AstComponent astSolver = new AstComponent(core, Properties.Transient.of());
    final BaseComponent baseSolver = new BaseComponent(core);
    final EqualityComponent equalitySolver = new EqualityComponent(core, unifier);
    final ScopeGraphComponent scopeGraphSolver = new ScopeGraphComponent(core, scopeGraph);
    try {
        ISolver component = c -> c.matchOrThrow(IConstraint.CheckedCases.<Optional<SolveResult>, InterruptedException>builder().onAst(astSolver::solve).onBase(baseSolver::solve).onEquality(equalitySolver::solve).onScopeGraph(scopeGraphSolver::solve).otherwise(cc -> Optional.empty()));
        final FixedPointSolver solver = new FixedPointSolver(cancel, progress, component, Iterables2.empty());
        final SolveResult solveResult = solver.solve(initial.constraints());
        return ImmutableGraphSolution.of(initial.config(), astSolver.finish(), scopeGraphSolver.finish(), equalitySolver.finish(), solveResult.messages(), solveResult.constraints());
    } catch (RuntimeException ex) {
        throw new SolverException("Internal solver error.", ex);
    }
}
Also used : IUnifier(mb.nabl2.terms.unification.IUnifier) Function1(org.metaborg.util.functions.Function1) ITerm(mb.nabl2.terms.ITerm) IProgress(org.metaborg.util.task.IProgress) ImmutableSolution(mb.nabl2.solver.ImmutableSolution) Ref(org.metaborg.util.Ref) IConstraint(mb.nabl2.constraints.IConstraint) ScopeGraphComponent(mb.nabl2.solver.components.ScopeGraphComponent) Occurrence(mb.nabl2.scopegraph.terms.Occurrence) IProperties(mb.nabl2.util.collections.IProperties) SolveResult(mb.nabl2.solver.ISolver.SolveResult) SolverCore(mb.nabl2.solver.SolverCore) ICancel(org.metaborg.util.task.ICancel) Value(org.immutables.value.Value) Label(mb.nabl2.scopegraph.terms.Label) Properties(mb.nabl2.util.collections.Properties) IAstConstraint(mb.nabl2.constraints.ast.IAstConstraint) SolverException(mb.nabl2.solver.SolverException) ISolution(mb.nabl2.solver.ISolution) EqualityComponent(mb.nabl2.solver.components.EqualityComponent) EsopScopeGraph(mb.nabl2.scopegraph.esop.reference.EsopScopeGraph) ImmutableSet(com.google.common.collect.ImmutableSet) TermIndex(mb.nabl2.stratego.TermIndex) BaseComponent(mb.nabl2.solver.components.BaseComponent) IScopeGraphConstraint(mb.nabl2.constraints.scopegraph.IScopeGraphConstraint) IEsopScopeGraph(mb.nabl2.scopegraph.esop.IEsopScopeGraph) Set(java.util.Set) Messages(mb.nabl2.solver.messages.Messages) Scope(mb.nabl2.scopegraph.terms.Scope) Sets(com.google.common.collect.Sets) NaBL2DebugConfig(mb.nabl2.config.NaBL2DebugConfig) AstComponent(mb.nabl2.solver.components.AstComponent) Iterables2(org.metaborg.util.iterators.Iterables2) IMessages(mb.nabl2.solver.messages.IMessages) ISolver(mb.nabl2.solver.ISolver) Serial(org.immutables.serial.Serial) SeedResult(mb.nabl2.solver.ISolver.SeedResult) Optional(java.util.Optional) SolverConfig(mb.nabl2.solver.SolverConfig) Collections(java.util.Collections) ScopeGraphComponent(mb.nabl2.solver.components.ScopeGraphComponent) BaseComponent(mb.nabl2.solver.components.BaseComponent) AstComponent(mb.nabl2.solver.components.AstComponent) ISolver(mb.nabl2.solver.ISolver) Optional(java.util.Optional) Label(mb.nabl2.scopegraph.terms.Label) SolverCore(mb.nabl2.solver.SolverCore) IEsopScopeGraph(mb.nabl2.scopegraph.esop.IEsopScopeGraph) Ref(org.metaborg.util.Ref) SolveResult(mb.nabl2.solver.ISolver.SolveResult) Scope(mb.nabl2.scopegraph.terms.Scope) ITerm(mb.nabl2.terms.ITerm) EqualityComponent(mb.nabl2.solver.components.EqualityComponent) SolverException(mb.nabl2.solver.SolverException) Occurrence(mb.nabl2.scopegraph.terms.Occurrence)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 Set (java.util.Set)1 NaBL2DebugConfig (mb.nabl2.config.NaBL2DebugConfig)1 IConstraint (mb.nabl2.constraints.IConstraint)1 IAstConstraint (mb.nabl2.constraints.ast.IAstConstraint)1 IScopeGraphConstraint (mb.nabl2.constraints.scopegraph.IScopeGraphConstraint)1 IEsopScopeGraph (mb.nabl2.scopegraph.esop.IEsopScopeGraph)1 EsopScopeGraph (mb.nabl2.scopegraph.esop.reference.EsopScopeGraph)1 Label (mb.nabl2.scopegraph.terms.Label)1 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)1 Scope (mb.nabl2.scopegraph.terms.Scope)1 ISolution (mb.nabl2.solver.ISolution)1 ISolver (mb.nabl2.solver.ISolver)1 SeedResult (mb.nabl2.solver.ISolver.SeedResult)1 SolveResult (mb.nabl2.solver.ISolver.SolveResult)1 ImmutableSolution (mb.nabl2.solver.ImmutableSolution)1 SolverConfig (mb.nabl2.solver.SolverConfig)1