Search in sources :

Example 1 with SpoofaxAnalyzeResult

use of org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResult in project spoofax by metaborg.

the class StrategoAnalyzer method analyze.

@Override
public ISpoofaxAnalyzeResult analyze(ISpoofaxParseUnit input, IContext context, IProgress progress, ICancel cancel) throws AnalysisException, InterruptedException {
    cancel.throwIfCancelled();
    if (!input.valid()) {
        final String message = logger.format("Parse input for {} is invalid, cannot analyze", input.source());
        throw new AnalysisException(context, message);
    }
    final ILanguageImpl language = context.language();
    final ITermFactory termFactory = termFactoryService.getGeneric();
    final FacetContribution<AnalysisFacet> facetContribution = language.facetContribution(AnalysisFacet.class);
    if (facetContribution == null) {
        logger.debug("No analysis required for {}", language);
        final ISpoofaxAnalyzeUnit emptyUnit = unitService.emptyAnalyzeUnit(input, context);
        return new SpoofaxAnalyzeResult(emptyUnit, context);
    }
    final AnalysisFacet facet = facetContribution.facet;
    cancel.throwIfCancelled();
    final HybridInterpreter runtime;
    try {
        runtime = runtimeService.runtime(facetContribution.contributor, context, true);
    } catch (MetaborgException e) {
        throw new AnalysisException(context, "Failed to get Stratego runtime", e);
    }
    cancel.throwIfCancelled();
    final ISpoofaxAnalyzeUnit result = analyze(input, context, runtime, facet.strategyName, termFactory);
    return new SpoofaxAnalyzeResult(result, context);
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl) MetaborgException(org.metaborg.core.MetaborgException) AnalysisException(org.metaborg.core.analysis.AnalysisException) HybridInterpreter(org.strategoxt.HybridInterpreter) SpoofaxAnalyzeResult(org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResult) ISpoofaxAnalyzeResult(org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResult) IStrategoString(org.spoofax.interpreter.terms.IStrategoString) AnalysisFacet(org.metaborg.spoofax.core.analysis.AnalysisFacet) ITermFactory(org.spoofax.interpreter.terms.ITermFactory) ISpoofaxAnalyzeUnit(org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit)

Aggregations

MetaborgException (org.metaborg.core.MetaborgException)1 AnalysisException (org.metaborg.core.analysis.AnalysisException)1 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)1 AnalysisFacet (org.metaborg.spoofax.core.analysis.AnalysisFacet)1 ISpoofaxAnalyzeResult (org.metaborg.spoofax.core.analysis.ISpoofaxAnalyzeResult)1 SpoofaxAnalyzeResult (org.metaborg.spoofax.core.analysis.SpoofaxAnalyzeResult)1 ISpoofaxAnalyzeUnit (org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit)1 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)1 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)1 HybridInterpreter (org.strategoxt.HybridInterpreter)1