Search in sources :

Example 1 with ISpoofaxAnalyzeUnitUpdate

use of org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate in project spoofax by metaborg.

the class ConstraintMultiFileAnalyzer method analyzeSemiIncremental.

private ISpoofaxAnalyzeResults analyzeSemiIncremental(Map<String, ISpoofaxParseUnit> changed, java.util.Set<String> removed, IMultiFileScopeGraphContext context, HybridInterpreter runtime, String strategy, IProgress progress, ICancel cancel) throws AnalysisException {
    final NaBL2DebugConfig debugConfig = context.config().debug();
    final Timer totalTimer = new Timer(true);
    final AggregateTimer collectionTimer = new AggregateTimer();
    final AggregateTimer solverTimer = new AggregateTimer();
    final AggregateTimer finalizeTimer = new AggregateTimer();
    final String globalSource = "";
    final Function1<String, String> globalFresh = base -> context.unit(globalSource).fresh().fresh(base);
    for (String input : removed) {
        context.removeUnit(input);
    }
    final int n = changed.size();
    final int w = context.units().size() / 2;
    progress.setWorkRemaining(n + w + 1);
    if (debugConfig.analysis() || debugConfig.files()) {
        logger.info("Analyzing {} files in {}.", n, context.location());
    }
    final Collection<ISpoofaxAnalyzeUnit> results = Lists.newArrayList();
    final Collection<ISpoofaxAnalyzeUnitUpdate> updateResults = Lists.newArrayList();
    try {
        // initial
        InitialResult initialResult;
        final Optional<ITerm> customInitial;
        {
            if (debugConfig.collection()) {
                logger.info("Collecting initial constraints.");
            }
            if (context.initialResult().isPresent()) {
                initialResult = context.initialResult().get();
                customInitial = context.initialResult().flatMap(r -> r.getCustomResult());
            } else {
                collectionTimer.start();
                try {
                    final ITerm globalAST = Actions.sourceTerm(globalSource, B.EMPTY_TUPLE);
                    ITerm initialResultTerm = doAction(strategy, Actions.analyzeInitial(globalSource, globalAST), context, runtime).orElseThrow(() -> new AnalysisException(context, "No initial result."));
                    initialResult = InitialResult.matcher().match(initialResultTerm).orElseThrow(() -> new AnalysisException(context, "Invalid initial results."));
                    customInitial = doCustomAction(strategy, Actions.customInitial(globalSource, globalAST), context, runtime);
                    initialResult = initialResult.withCustomResult(customInitial);
                    context.setInitialResult(initialResult);
                } finally {
                    collectionTimer.stop();
                }
            }
            if (debugConfig.collection()) {
                logger.info("Initial constraints collected.");
            }
        }
        // global parameters, that form the interface for a single unit
        final java.util.Set<ITermVar> intfVars = Sets.newHashSet();
        {
            initialResult.getArgs().getParams().stream().forEach(param -> intfVars.addAll(param.getVars()));
            initialResult.getArgs().getType().ifPresent(type -> intfVars.addAll(type.getVars()));
        }
        final SemiIncrementalMultiFileSolver solver = new SemiIncrementalMultiFileSolver(context.config().debug(), callExternal(runtime));
        // global
        ISolution initialSolution;
        {
            if (context.initialSolution().isPresent()) {
                initialSolution = context.initialSolution().get();
            } else {
                try {
                    solverTimer.start();
                    final IProgress subprogress = progress.subProgress(1);
                    GraphSolution preSolution = solver.solveGraph(ImmutableBaseSolution.of(initialResult.getConfig(), initialResult.getConstraints(), PersistentUnifier.Immutable.of()), globalFresh, cancel, subprogress);
                    preSolution = solver.reportUnsolvedGraphConstraints(preSolution);
                    initialSolution = solver.solveIntra(preSolution, intfVars, null, globalFresh, cancel, subprogress);
                    if (debugConfig.resolution()) {
                        logger.info("Reduced file constraints to {}.", initialSolution.constraints().size());
                    }
                } catch (SolverException e) {
                    throw new AnalysisException(context, e);
                } finally {
                    solverTimer.stop();
                }
                context.setInitialSolution(initialSolution);
            }
        }
        final java.util.Set<Scope> intfScopes = Sets.newHashSet();
        {
            initialResult.getArgs().getParams().stream().forEach(param -> Scope.matcher().match(param, initialSolution.unifier()).ifPresent(intfScopes::add));
        }
        // units
        final Map<String, IStrategoTerm> astsByFile = Maps.newHashMap();
        final Map<String, IMessage> failures = Maps.newHashMap();
        final Multimap<String, IMessage> ambiguitiesByFile = HashMultimap.create();
        for (Map.Entry<String, ISpoofaxParseUnit> input : changed.entrySet()) {
            final String source = input.getKey();
            final ISpoofaxParseUnit parseUnit = input.getValue();
            final ITerm ast = strategoTerms.fromStratego(parseUnit.ast());
            if (debugConfig.files()) {
                logger.info("Analyzing {}.", source);
            }
            final IMultiFileScopeGraphUnit unit = context.unit(source);
            unit.clear();
            try {
                UnitResult unitResult;
                final Optional<ITerm> customUnit;
                {
                    if (debugConfig.collection()) {
                        logger.info("Collecting constraints of {}.", source);
                    }
                    try {
                        collectionTimer.start();
                        final ITerm unitResultTerm = doAction(strategy, Actions.analyzeUnit(source, ast, initialResult.getArgs()), context, runtime).orElseThrow(() -> new AnalysisException(context, "No unit result."));
                        unitResult = UnitResult.matcher().match(unitResultTerm).orElseThrow(() -> new MetaborgException("Invalid unit results."));
                        final ITerm desugaredAST = unitResult.getAST();
                        customUnit = doCustomAction(strategy, Actions.customUnit(source, desugaredAST, customInitial.orElse(B.EMPTY_TUPLE)), context, runtime);
                        unitResult = unitResult.withCustomResult(customUnit);
                        final IStrategoTerm analyzedAST = strategoTerms.toStratego(desugaredAST);
                        astsByFile.put(source, analyzedAST);
                        ambiguitiesByFile.putAll(source, analysisCommon.ambiguityMessages(parseUnit.source(), parseUnit.ast()));
                        unit.setUnitResult(unitResult);
                    } finally {
                        collectionTimer.stop();
                    }
                    if (debugConfig.collection()) {
                        logger.info("Collected {} constraints of {}.", unitResult.getConstraints().size(), source);
                    }
                }
                {
                    final ISolution unitSolution;
                    if (debugConfig.resolution()) {
                        logger.info("Reducing {} constraints of {}.", unitResult.getConstraints().size(), source);
                    }
                    try {
                        solverTimer.start();
                        final Function1<String, String> fresh = base -> context.unit(source).fresh().fresh(base);
                        final IProgress subprogress = progress.subProgress(1);
                        GraphSolution preSolution = solver.solveGraph(ImmutableBaseSolution.of(initialResult.getConfig(), unitResult.getConstraints(), initialSolution.unifier()), fresh, cancel, subprogress);
                        preSolution = solver.reportUnsolvedGraphConstraints(preSolution);
                        unitSolution = solver.solveIntra(preSolution, intfVars, intfScopes, fresh, cancel, subprogress);
                        if (debugConfig.resolution()) {
                            logger.info("Reduced file constraints to {}.", unitSolution.constraints().size());
                        }
                    } catch (SolverException e) {
                        throw new AnalysisException(context, e);
                    } finally {
                        solverTimer.stop();
                    }
                    unit.setPartialSolution(unitSolution);
                    if (debugConfig.files() || debugConfig.resolution()) {
                        logger.info("Analyzed {}: {} errors, {} warnings, {} notes, {} unsolved constraints.", source, unitSolution.messages().getErrors().size(), unitSolution.messages().getWarnings().size(), unitSolution.messages().getNotes().size(), unitSolution.constraints().size());
                    }
                }
            } catch (MetaborgException e) {
                logger.warn("Analysis of " + source + " failed.", e);
                failures.put(source, MessageFactory.newAnalysisErrorAtTop(parseUnit.source(), "File analysis failed.", e));
            }
        }
        // solve
        final ISolution solution;
        final List<Optional<ITerm>> customUnits = Lists.newArrayList();
        {
            final List<ISolution> partialSolutions = Lists.newArrayList();
            for (IMultiFileScopeGraphUnit unit : context.units()) {
                unit.partialSolution().ifPresent(partialSolutions::add);
                unit.unitResult().map(UnitResult::getCustomResult).ifPresent(customUnits::add);
            }
            if (debugConfig.resolution()) {
                logger.info("Solving {} partial solutions.", partialSolutions.size());
            }
            ISolution sol;
            try {
                solverTimer.start();
                Function1<String, String> fresh = base -> context.unit(globalSource).fresh().fresh(base);
                IMessageInfo message = ImmutableMessageInfo.of(MessageKind.ERROR, MessageContent.of(), Actions.sourceTerm(globalSource));
                sol = solver.solveInter(initialSolution, partialSolutions, message, fresh, cancel, progress.subProgress(w));
                sol = solver.reportUnsolvedConstraints(sol);
            } catch (SolverException e) {
                throw new AnalysisException(context, e);
            } finally {
                solverTimer.stop();
            }
            if (!sol.flowSpecSolution().controlFlowGraph().isEmpty()) {
                logger.debug("CFG is not empty: calling FlowSpec dataflow solver");
                sol = new FixedPoint().entryPoint(sol, getFlowSpecTransferFunctions(context.language()));
            }
            solution = sol;
            context.setSolution(solution);
            if (debugConfig.resolution()) {
                logger.info("Project constraints solved.");
            }
        }
        // final
        FinalResult finalResult;
        final Optional<ITerm> customFinal;
        final Optional<CustomSolution> customSolution;
        {
            if (debugConfig.analysis()) {
                logger.info("Finalizing project analysis.");
            }
            finalizeTimer.start();
            try {
                ITerm finalResultTerm = doAction(strategy, Actions.analyzeFinal(globalSource), context, runtime).orElseThrow(() -> new AnalysisException(context, "No final result."));
                finalResult = FinalResult.matcher().match(finalResultTerm, solution.unifier()).orElseThrow(() -> new AnalysisException(context, "Invalid final results."));
                customFinal = doCustomAction(strategy, Actions.customFinal(globalSource, customInitial.orElse(B.EMPTY_TUPLE), Optionals.filter(customUnits)), context, runtime);
                finalResult = finalResult.withCustomResult(customFinal);
                context.setFinalResult(finalResult);
                customSolution = customFinal.flatMap(cs -> CustomSolution.matcher().match(cs, solution.unifier()));
                customSolution.ifPresent(cs -> context.setCustomSolution(cs));
            } finally {
                finalizeTimer.stop();
            }
            if (debugConfig.analysis()) {
                logger.info("Project analysis finalized.");
            }
        }
        // errors
        {
            if (debugConfig.analysis()) {
                logger.info("Processing project messages.");
            }
            Messages.Transient messageBuilder = Messages.Transient.of();
            messageBuilder.addAll(Messages.unsolvedErrors(solution.constraints()));
            messageBuilder.addAll(solution.messages().getAll());
            customSolution.map(CustomSolution::getMessages).map(IMessages::getAll).ifPresent(messageBuilder::addAll);
            IMessages messages = messageBuilder.freeze();
            IRelation3.Transient<String, MessageSeverity, IMessage> messagesByFile = HashTrieRelation3.Transient.of();
            messagesByFile(failures.values(), messagesByFile, context);
            messagesByFile(messages(messages.getAll(), solution.unifier(), context, context.location()), messagesByFile, context);
            // precondition: the messagesByFile should not contain any files that do not have corresponding units
            for (IMultiFileScopeGraphUnit unit : context.units()) {
                final String source = unit.resource();
                final java.util.Set<IMessage> fileMessages = messagesByFile.get(source).stream().map(Map.Entry::getValue).collect(Collectors2.toHashSet());
                if (changed.containsKey(source)) {
                    fileMessages.addAll(ambiguitiesByFile.get(source));
                    final boolean valid = !failures.containsKey(source);
                    final boolean success = valid && messagesByFile.get(source, MessageSeverity.ERROR).isEmpty();
                    final IStrategoTerm analyzedAST = astsByFile.get(source);
                    results.add(unitService.analyzeUnit(changed.get(source), new AnalyzeContrib(valid, success, analyzedAST != null, analyzedAST, fileMessages, -1), context));
                } else {
                    try {
                        final FileObject file = context.location().resolveFile(source);
                        updateResults.add(unitService.analyzeUnitUpdate(file, new AnalyzeUpdateData(fileMessages), context));
                    } catch (IOException ex) {
                        logger.error("Could not resolve {} to update messages", source);
                    }
                }
                messagesByFile.remove(source);
            }
            if (!messagesByFile.keySet().isEmpty()) {
                logger.error("Found messages for unanalyzed files {}", messagesByFile.keySet());
            }
            if (debugConfig.analysis() || debugConfig.files() || debugConfig.resolution()) {
                logger.info("Analyzed {} files: {} errors, {} warnings, {} notes.", n, messages.getErrors().size(), messages.getWarnings().size(), messages.getNotes().size());
            }
        }
    } catch (InterruptedException e) {
        logger.debug("Analysis was interrupted.");
    } finally {
        totalTimer.stop();
    }
    final ConstraintDebugData debugData = new ConstraintDebugData(totalTimer.stop(), collectionTimer.total(), solverTimer.total(), finalizeTimer.total());
    if (debugConfig.analysis()) {
        logger.info("{}", debugData);
    }
    return new SpoofaxAnalyzeResults(results, updateResults, context, debugData);
}
Also used : UnitResult(mb.nabl2.spoofax.analysis.UnitResult) ITerm(mb.nabl2.terms.ITerm) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit) IProgress(org.metaborg.util.task.IProgress) Inject(com.google.inject.Inject) IRelation3(mb.nabl2.util.collections.IRelation3) MetaborgException(org.metaborg.core.MetaborgException) HashMultimap(com.google.common.collect.HashMultimap) ICancel(org.metaborg.util.task.ICancel) Map(java.util.Map) ITermVar(mb.nabl2.terms.ITermVar) SolverException(mb.nabl2.solver.SolverException) ISolution(mb.nabl2.solver.ISolution) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) B(mb.nabl2.terms.build.TermBuild.B) GraphSolution(mb.nabl2.solver.solvers.BaseSolver.GraphSolution) ISpoofaxAnalyzer(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzer) ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) Collection(java.util.Collection) ISpoofaxTracingService(org.metaborg.spoofax.core.tracing.ISpoofaxTracingService) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) SemiIncrementalMultiFileSolver(mb.nabl2.solver.solvers.SemiIncrementalMultiFileSolver) AnalyzeUpdateData(org.metaborg.spoofax.core.unit.AnalyzeUpdateData) Sets(com.google.common.collect.Sets) FinalResult(mb.nabl2.spoofax.analysis.FinalResult) List(java.util.List) Optionals(org.metaborg.util.optionals.Optionals) Optional(java.util.Optional) LoggerUtils(org.metaborg.util.log.LoggerUtils) Timer(org.metaborg.util.time.Timer) ImmutableBaseSolution(mb.nabl2.solver.solvers.ImmutableBaseSolution) IMultiFileScopeGraphContext(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphContext) ITermFactoryService(org.metaborg.spoofax.core.terms.ITermFactoryService) AggregateTimer(org.metaborg.util.time.AggregateTimer) Function1(org.metaborg.util.functions.Function1) AnalysisCommon(org.metaborg.spoofax.core.analysis.AnalysisCommon) ISpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults) Multimap(com.google.common.collect.Multimap) Actions(mb.nabl2.spoofax.analysis.Actions) Lists(com.google.common.collect.Lists) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) IMultiFileScopeGraphUnit(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphUnit) ISpoofaxUnitService(org.metaborg.spoofax.core.unit.ISpoofaxUnitService) HybridInterpreter(org.strategoxt.HybridInterpreter) PersistentUnifier(mb.nabl2.terms.unification.PersistentUnifier) ILogger(org.metaborg.util.log.ILogger) ImmutableMessageInfo(mb.nabl2.constraints.messages.ImmutableMessageInfo) HashTrieRelation3(mb.nabl2.util.collections.HashTrieRelation3) Messages(mb.nabl2.solver.messages.Messages) IOException(java.io.IOException) MessageKind(mb.nabl2.constraints.messages.MessageKind) Scope(mb.nabl2.scopegraph.terms.Scope) CustomSolution(mb.nabl2.spoofax.analysis.CustomSolution) IMessage(org.metaborg.core.messages.IMessage) FileObject(org.apache.commons.vfs2.FileObject) Maps(com.google.common.collect.Maps) NaBL2DebugConfig(mb.nabl2.config.NaBL2DebugConfig) MessageContent(mb.nabl2.constraints.messages.MessageContent) AnalyzeContrib(org.metaborg.spoofax.core.unit.AnalyzeContrib) IMessages(mb.nabl2.solver.messages.IMessages) SpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults) Collectors2(org.metaborg.util.stream.Collectors2) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) IResourceService(org.metaborg.core.resource.IResourceService) IStrategoCommon(org.metaborg.spoofax.core.stratego.IStrategoCommon) InitialResult(mb.nabl2.spoofax.analysis.InitialResult) MessageSeverity(org.metaborg.core.messages.MessageSeverity) AnalysisException(org.metaborg.core.analysis.AnalysisException) IStrategoRuntimeService(org.metaborg.spoofax.core.stratego.IStrategoRuntimeService) MessageFactory(org.metaborg.core.messages.MessageFactory) ISpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults) SpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults) ITermVar(mb.nabl2.terms.ITermVar) GraphSolution(mb.nabl2.solver.solvers.BaseSolver.GraphSolution) List(java.util.List) FileObject(org.apache.commons.vfs2.FileObject) InitialResult(mb.nabl2.spoofax.analysis.InitialResult) IProgress(org.metaborg.util.task.IProgress) Optional(java.util.Optional) AnalyzeUpdateData(org.metaborg.spoofax.core.unit.AnalyzeUpdateData) FinalResult(mb.nabl2.spoofax.analysis.FinalResult) IMessage(org.metaborg.core.messages.IMessage) Function1(org.metaborg.util.functions.Function1) ISolution(mb.nabl2.solver.ISolution) IMultiFileScopeGraphUnit(org.metaborg.spoofax.core.context.scopegraph.IMultiFileScopeGraphUnit) CustomSolution(mb.nabl2.spoofax.analysis.CustomSolution) NaBL2DebugConfig(mb.nabl2.config.NaBL2DebugConfig) Map(java.util.Map) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) SemiIncrementalMultiFileSolver(mb.nabl2.solver.solvers.SemiIncrementalMultiFileSolver) MetaborgException(org.metaborg.core.MetaborgException) UnitResult(mb.nabl2.spoofax.analysis.UnitResult) AggregateTimer(org.metaborg.util.time.AggregateTimer) IMessageInfo(mb.nabl2.constraints.messages.IMessageInfo) AnalyzeContrib(org.metaborg.spoofax.core.unit.AnalyzeContrib) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit) ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) IMessages(mb.nabl2.solver.messages.IMessages) IOException(java.io.IOException) FixedPoint(mb.flowspec.runtime.solver.FixedPoint) Timer(org.metaborg.util.time.Timer) AggregateTimer(org.metaborg.util.time.AggregateTimer) Scope(mb.nabl2.scopegraph.terms.Scope) AnalysisException(org.metaborg.core.analysis.AnalysisException) ITerm(mb.nabl2.terms.ITerm) SolverException(mb.nabl2.solver.SolverException)

Example 2 with ISpoofaxAnalyzeUnitUpdate

use of org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate in project spoofax by metaborg.

the class TaskEngineAnalyzer method analyzeAll.

private ISpoofaxAnalyzeResults analyzeAll(Iterable<ISpoofaxParseUnit> inputs, IContext context, HybridInterpreter runtime, String strategy, ITermFactory termFactory) throws AnalysisException {
    final Map<String, ISpoofaxParseUnit> inputsPerSource = Maps.newHashMap();
    int detachedCounter = 0;
    final Collection<IStrategoAppl> analysisInputs = Lists.newArrayList();
    for (ISpoofaxParseUnit input : inputs) {
        if (!input.valid()) {
            logger.warn("Parse result for {} is invalid, cannot analyze", input.source());
            continue;
        }
        final String pathString;
        if (input.detached()) {
            pathString = "detached-source-" + detachedCounter++;
            logger.debug("Parse input is detached, using '{}' as path", pathString);
        } else {
            pathString = input.source().getName().getURI();
        }
        inputsPerSource.put(pathString, input);
        final IStrategoString pathTerm = termFactory.makeString(pathString);
        final IStrategoReal durationTerm = termFactory.makeReal(input.duration());
        analysisInputs.add(termFactory.makeAppl(fileCons, pathTerm, input.ast(), durationTerm));
    }
    final IStrategoTerm inputTerm = termFactory.makeList(analysisInputs);
    logger.trace("Invoking {} strategy", strategy);
    final IStrategoTerm resultTerm;
    try {
        resultTerm = strategoCommon.invoke(runtime, inputTerm, strategy);
    } catch (MetaborgException e) {
        final String message = analysisCommon.analysisFailedMessage(runtime);
        throw new AnalysisException(context, message, e);
    }
    if (resultTerm == null) {
        final String message = analysisCommon.analysisFailedMessage(runtime);
        throw new AnalysisException(context, message);
    }
    if (!(resultTerm instanceof IStrategoAppl) || resultTerm.getSubtermCount() != 5) {
        final String message = logger.format("Unexpected results from analysis {}, expected 5-tuple", resultTerm);
        throw new AnalysisException(context, message);
    }
    final IStrategoTerm resultsTerm = resultTerm.getSubterm(0);
    final IStrategoTerm updateResultsTerm = resultTerm.getSubterm(1);
    final Collection<ISpoofaxAnalyzeUnit> fileResults = Lists.newArrayListWithCapacity(resultsTerm.getSubtermCount());
    for (IStrategoTerm result : resultsTerm) {
        // HACK: analysis duration per parse unit is unknown, pass -1 as duration.
        final ISpoofaxAnalyzeUnit fileResult = result(result, inputsPerSource, context, -1);
        if (fileResult == null) {
            continue;
        }
        fileResults.add(fileResult);
    }
    final Collection<ISpoofaxAnalyzeUnitUpdate> updateResults = Lists.newArrayListWithCapacity(updateResultsTerm.getSubtermCount());
    for (IStrategoTerm result : updateResultsTerm) {
        final ISpoofaxAnalyzeUnitUpdate updateResult = updateResult(result, context);
        if (updateResult == null) {
            continue;
        }
        updateResults.add(updateResult);
    }
    return new SpoofaxAnalyzeResults(fileResults, updateResults, context);
}
Also used : ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) ISpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResults) SpoofaxAnalyzeResults(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResults) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) MetaborgException(org.metaborg.core.MetaborgException) IStrategoAppl(org.spoofax.interpreter.terms.IStrategoAppl) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) IStrategoReal(org.spoofax.interpreter.terms.IStrategoReal) AnalysisException(org.metaborg.core.analysis.AnalysisException) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit)

Example 3 with ISpoofaxAnalyzeUnitUpdate

use of org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate in project spoofax by metaborg.

the class SpoofaxModule method bindAnalysis.

/**
 * Overrides {@link MetaborgModule#bindAnalysis()} to provide Spoofax-specific bindings with Spoofax interfaces, and
 * to provide analyzers.
 */
@Override
protected void bindAnalysis() {
    // Analysis service
    bind(SpoofaxAnalysisService.class).in(Singleton.class);
    bind(ISpoofaxAnalysisService.class).to(SpoofaxAnalysisService.class);
    bind(new TypeLiteral<IAnalysisService<ISpoofaxParseUnit, ISpoofaxAnalyzeUnit, ISpoofaxAnalyzeUnitUpdate>>() {
    }).to(SpoofaxAnalysisService.class);
    bind(new TypeLiteral<IAnalysisService<?, ?, ?>>() {
    }).to(SpoofaxAnalysisService.class);
    bind(IAnalysisService.class).to(SpoofaxAnalysisService.class);
    // Stratego runtime
    bind(StrategoRuntimeService.class).in(Singleton.class);
    bind(IStrategoRuntimeService.class).to(StrategoRuntimeService.class);
    languageCacheBinder.addBinding().to(StrategoRuntimeService.class);
    // Utilities
    bind(IStrategoCommon.class).to(StrategoCommon.class).in(Singleton.class);
    bind(AnalysisCommon.class).in(Singleton.class);
    // Stratego primitives
    bind(ParseFileStrategy.class).in(Singleton.class);
    bind(ParseStrategoFileStrategy.class).in(Singleton.class);
    final Multibinder<IOperatorRegistry> libraryBinder = Multibinder.newSetBinder(binder(), IOperatorRegistry.class);
    bindPrimitiveLibrary(libraryBinder, TaskLibrary.class);
    bindPrimitiveLibrary(libraryBinder, LegacyIndexLibrary.class);
    bindPrimitiveLibrary(libraryBinder, SpoofaxPrimitiveLibrary.class);
    bindPrimitiveLibrary(libraryBinder, ScopeGraphLibrary.class);
    bindPrimitiveLibrary(libraryBinder, FlowSpecLibrary.class);
    bindPrimitiveLibrary(libraryBinder, LegacySpoofaxPrimitiveLibrary.class);
    bindPrimitiveLibrary(libraryBinder, LegacySpoofaxJSGLRLibrary.class);
    final Multibinder<AbstractPrimitive> spoofaxPrimitiveLibrary = Multibinder.newSetBinder(binder(), AbstractPrimitive.class, Names.named(SpoofaxPrimitiveLibrary.name));
    bindPrimitive(spoofaxPrimitiveLibrary, DigestPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageComponentsPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageImplementationPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguagePrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, ProjectPathPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LocalPathPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LocalReplicatePrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, AbsolutePathPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageSourceDirectoriesPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageSourceFilesPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageIncludeDirectoriesPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, LanguageIncludeFilesPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, RelativeSourcePath.class);
    bindPrimitive(spoofaxPrimitiveLibrary, RelativeSourceOrIncludePath.class);
    bindPrimitive(spoofaxPrimitiveLibrary, ParsePrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, CallStrategyPrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, IsLanguageActivePrimitive.class);
    bindPrimitive(spoofaxPrimitiveLibrary, GetSortNamePrimitive.class);
    final Multibinder<AbstractPrimitive> spoofaxScopeGraphLibrary = Multibinder.newSetBinder(binder(), AbstractPrimitive.class, Names.named("ScopeGraphLibrary"));
    bindPrimitive(spoofaxScopeGraphLibrary, SG_analysis_has_errors.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_debug_constraints.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_debug_name_resolution.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_debug_scope_graph.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_debug_symbolic_constraints.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_debug_unifier.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_erase_ast_indices.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_fresh.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_focus_term.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_all_decls.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_all_refs.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_all_scopes.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_analysis.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_decls.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_index.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_property.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_refs.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ast_resolution.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_custom_analysis.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_decl_property.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_decl_scope.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_direct_edges_inv.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_direct_edges.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_export_edges_inv.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_export_edges.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_import_edges_inv.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_import_edges.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_reachable_decls.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ref_resolution.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_ref_scope.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_resource_analysis.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_scope_decls.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_scope_refs.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_symbolic_facts.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_symbolic_goals.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_get_visible_decls.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_index_ast.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_is_debug_collection_enabled.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_is_debug_custom_enabled.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_is_debug_resolution_enabled.class);
    bindPrimitive(spoofaxScopeGraphLibrary, SG_set_ast_index.class);
    final Multibinder<AbstractPrimitive> spoofaxFlowSpecLibrary = Multibinder.newSetBinder(binder(), AbstractPrimitive.class, Names.named(FlowSpecLibrary.name));
    bindPrimitive(spoofaxFlowSpecLibrary, FS_get_property_pre.class);
    bindPrimitive(spoofaxFlowSpecLibrary, FS_get_property_post.class);
    bindPrimitive(spoofaxFlowSpecLibrary, FS_show_control_flow_graph.class);
    final Multibinder<AbstractPrimitive> legacySpoofaxLibrary = Multibinder.newSetBinder(binder(), AbstractPrimitive.class, Names.named(LegacySpoofaxPrimitiveLibrary.name));
    bindPrimitive(legacySpoofaxLibrary, LegacyProjectPathPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageSourceLocationsPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageSourceLocationsPrimitive2.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageIncludeLocationsPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageIncludeLocationsPrimitive2.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageSourceFilesPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyLanguageIncludeFilesPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, LegacyForeignCallPrimitive.class);
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_set_total_work_units", 0, 0));
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_set_markers", 0, 1));
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_refreshresource", 0, 1));
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_queue_strategy", 0, 2));
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_complete_work_unit", 0, 0));
    bindPrimitive(legacySpoofaxLibrary, new DummyPrimitive("SSL_EXT_pluginpath", 0, 0));
    final Multibinder<AbstractPrimitive> legacySpoofaxJSGLRLibrary = Multibinder.newSetBinder(binder(), AbstractPrimitive.class, Names.named(LegacySpoofaxJSGLRLibrary.injectionName));
    bindPrimitive(legacySpoofaxJSGLRLibrary, LegacyParseFilePrimitive.class);
    bindPrimitive(legacySpoofaxJSGLRLibrary, LegacyParseFilePtPrimitive.class);
    bindPrimitive(legacySpoofaxJSGLRLibrary, new DummyPrimitive("STRSGLR_open_parse_table", 0, 1));
    bindPrimitive(legacySpoofaxJSGLRLibrary, new DummyPrimitive("STRSGLR_close_parse_table", 0, 1));
}
Also used : ISpoofaxParseUnit(org.metaborg.spoofax.core.unit.ISpoofaxParseUnit) ISpoofaxAnalyzeUnitUpdate(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate) DummyPrimitive(org.metaborg.spoofax.core.stratego.primitive.generic.DummyPrimitive) ParseStrategoFileStrategy(org.metaborg.spoofax.core.stratego.strategies.ParseStrategoFileStrategy) ParseFileStrategy(org.metaborg.spoofax.core.stratego.strategies.ParseFileStrategy) SpoofaxAnalysisService(org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService) ISpoofaxAnalysisService(org.metaborg.spoofax.core.analysis.ISpoofaxAnalysisService) IAnalysisService(org.metaborg.core.analysis.IAnalysisService) IOperatorRegistry(org.spoofax.interpreter.library.IOperatorRegistry) AnalysisCommon(org.metaborg.spoofax.core.analysis.AnalysisCommon) StrategoRuntimeService(org.metaborg.spoofax.core.stratego.StrategoRuntimeService) IStrategoRuntimeService(org.metaborg.spoofax.core.stratego.IStrategoRuntimeService) TypeLiteral(com.google.inject.TypeLiteral) IStrategoRuntimeService(org.metaborg.spoofax.core.stratego.IStrategoRuntimeService) StrategoCommon(org.metaborg.spoofax.core.stratego.StrategoCommon) IStrategoCommon(org.metaborg.spoofax.core.stratego.IStrategoCommon) ISpoofaxAnalysisService(org.metaborg.spoofax.core.analysis.ISpoofaxAnalysisService) AbstractPrimitive(org.spoofax.interpreter.library.AbstractPrimitive) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit)

Aggregations

MetaborgException (org.metaborg.core.MetaborgException)2 AnalysisException (org.metaborg.core.analysis.AnalysisException)2 ISpoofaxAnalyzeUnit (org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit)2 ISpoofaxAnalyzeUnitUpdate (org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnitUpdate)2 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)2 HashMultimap (com.google.common.collect.HashMultimap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 TypeLiteral (com.google.inject.TypeLiteral)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 FixedPoint (mb.flowspec.runtime.solver.FixedPoint)1 NaBL2DebugConfig (mb.nabl2.config.NaBL2DebugConfig)1 IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)1