Search in sources :

Example 21 with ILanguageImpl

use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.

the class Builder method updateLanguageResources.

private Collection<FileObject> updateLanguageResources(BuildInput input, ILanguageImpl language, LanguageBuildDiff diff, IBuildOutputInternal<P, A, AU, T> output, boolean pardoned, IProgress progress, ICancel cancel) throws InterruptedException {
    cancel.throwIfCancelled();
    final boolean analyze = input.analyze && analysisService.available(language);
    final boolean transform = input.transform;
    progress.setWorkRemaining(10 + (analyze ? 45 : 0) + (transform ? 45 : 0));
    final Iterable<IdentifiedResourceChange> sourceChanges = diff.sourceChanges;
    final Iterable<IdentifiedResourceChange> includeChanges = diff.includeChanges;
    final Set<FileName> includes = Sets.newHashSet();
    for (IdentifiedResourceChange includeChange : includeChanges) {
        includes.add(includeChange.change.resource.getName());
    }
    final FileObject location = input.project.location();
    final Collection<FileObject> changedSources = Sets.newHashSet();
    final Set<FileName> removedResources = Sets.newHashSet();
    final Collection<IMessage> extraMessages = Lists.newLinkedList();
    final RefBool success = new RefBool(true);
    logger.info("Building {} sources, {} includes of {}", Iterables.size(sourceChanges), Iterables.size(includeChanges), language);
    // Parse
    cancel.throwIfCancelled();
    final Collection<P> sourceParseUnits = parse(input, language, sourceChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
    // GTODO: when a new context is created, all include files need to be parsed and analyzed in that context, this
    // approach does not do that!
    final Collection<P> includeParseUnits = parse(input, language, includeChanges, pardoned, changedSources, removedResources, extraMessages, success, progress.subProgress(5), cancel);
    final Iterable<P> allParseResults = Iterables.concat(sourceParseUnits, includeParseUnits);
    // Analyze
    cancel.throwIfCancelled();
    final Multimap<IContext, A> allAnalyzeUnits;
    final Collection<AU> allAnalyzeUpdates = Lists.newArrayList();
    if (analyze) {
        // Segregate by context
        final Multimap<IContext, P> parseUnitsPerContext = ArrayListMultimap.create();
        for (P parseResult : sourceParseUnits) {
            cancel.throwIfCancelled();
            final FileObject resource = parseResult.source();
            final ILanguageImpl langImpl = parseResult.input().langImpl();
            try {
                if (contextService.available(langImpl)) {
                    final IContext context = contextService.get(resource, input.project, langImpl);
                    parseUnitsPerContext.put(context, parseResult);
                }
            } catch (ContextException e) {
                final String message = String.format("Failed to retrieve context for parse result of %s", resource);
                printMessage(resource, message, e, input, pardoned);
                extraMessages.add(MessageFactory.newAnalysisErrorAtTop(resource, "Failed to retrieve context", e));
            }
        }
        // Run analysis
        cancel.throwIfCancelled();
        allAnalyzeUnits = analyze(input, language, location, parseUnitsPerContext, includeParseUnits, pardoned, allAnalyzeUpdates, removedResources, extraMessages, success, progress.subProgress(45), cancel);
    } else {
        allAnalyzeUnits = ArrayListMultimap.create();
    }
    // Transform
    cancel.throwIfCancelled();
    final Collection<T> allTransformUnits;
    if (transform) {
        allTransformUnits = transform(input, language, location, allAnalyzeUnits, includes, pardoned, removedResources, extraMessages, success, progress.subProgress(45), cancel);
    } else {
        allTransformUnits = Lists.newLinkedList();
    }
    printMessages(extraMessages, "Something", input, pardoned);
    output.add(success.get(), removedResources, includes, changedSources, allParseResults, allAnalyzeUnits.values(), allAnalyzeUpdates, allTransformUnits, extraMessages);
    final Collection<FileObject> newResources = Lists.newArrayList();
    for (T transformUnit : allTransformUnits) {
        for (ITransformOutput transformOutput : transformUnit.outputs()) {
            final FileObject outputFile = transformOutput.output();
            if (outputFile != null) {
                newResources.add(outputFile);
            }
        }
    }
    return newResources;
}
Also used : ITransformOutput(org.metaborg.core.transform.ITransformOutput) IContext(org.metaborg.core.context.IContext) FileName(org.apache.commons.vfs2.FileName) IdentifiedResourceChange(org.metaborg.core.resource.IdentifiedResourceChange) ContextException(org.metaborg.core.context.ContextException) FileObject(org.apache.commons.vfs2.FileObject) IMessage(org.metaborg.core.messages.IMessage) RefBool(org.metaborg.util.RefBool) ILanguageImpl(org.metaborg.core.language.ILanguageImpl)

Example 22 with ILanguageImpl

use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.

the class BuildInputBuilder method build.

/**
 * Builds a build input object from the current state.
 *
 * @throws MetaborgException
 *             When {@link IDependencyService#compileDeps} throws.
 */
public BuildInput build(IDependencyService dependencyService, ILanguagePathService languagePathService) throws MetaborgException {
    if (state == null) {
        state = new BuildState();
    }
    if (addDependencyLanguages) {
        final Iterable<ILanguageComponent> compileComponents = dependencyService.compileDeps(this.project);
        final Iterable<ILanguageImpl> compileImpls = LanguageUtils.toImpls(compileComponents);
        addLanguages(compileImpls);
    }
    if (addDefaultIncludePaths) {
        for (ILanguageImpl language : languages) {
            addIncludePaths(language, languagePathService.includePaths(this.project, language.belongsTo().name()));
        }
    }
    if (addSourcesFromDefaultSourceLocations) {
        for (ILanguageImpl language : languages) {
            final Iterable<IdentifiedResource> sources = languagePathService.sourceFiles(this.project, language);
            addIdentifiedSources(sources);
        }
    }
    for (ILanguageImpl language : languages) {
        if (pardonedLanguageStrings.contains(language.belongsTo().name())) {
            addPardonedLanguage(language);
        }
    }
    return new BuildInput(state, this.project, sourceChanges, includePaths, new BuildOrder(languages), selector, analyze, analyzeSelector, transform, transformSelector, transformGoals, messagePrinter, throwOnErrors, pardonedLanguages);
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) IdentifiedResource(org.metaborg.core.language.IdentifiedResource)

Example 23 with ILanguageImpl

use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.

the class AnalysisService method analyzeAll.

@Override
public IAnalyzeResults<A, AU> analyzeAll(Iterable<P> inputs, IContext context, IProgress progress, ICancel cancel) throws AnalysisException, InterruptedException {
    final ILanguageImpl langImpl = context.language();
    final AnalyzerFacet<P, A, AU> facet = facet(langImpl);
    if (facet == null) {
        final String message = logger.format("Cannot get an analyzer for {}", langImpl);
        throw new AnalysisException(context, message);
    }
    final IAnalyzer<P, A, AU> analyzer = facet.analyzer;
    return analyzer.analyzeAll(inputs, context, progress, cancel);
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl)

Example 24 with ILanguageImpl

use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.

the class LanguageChangeProcessor method removedImpl.

/**
 * Implementation was removed
 *
 * @param impl
 *            Removed implementation
 */
protected void removedImpl(ILanguageImpl impl) {
    for (ILanguageCache languageCache : languageCaches) {
        languageCache.invalidateCache(impl);
    }
    parseResultProcessor.invalidate(impl);
    analysisResultProcessor.invalidate(impl);
    final Iterable<IEditor> editors = editorRegistry.openEditors();
    for (IEditor editor : editors) {
        final ILanguageImpl language = editor.language();
        if (language != null && language.equals(impl)) {
            editor.reconfigure();
            editor.disable();
        }
    }
}
Also used : IEditor(org.metaborg.core.editor.IEditor) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ILanguageCache(org.metaborg.core.language.ILanguageCache)

Example 25 with ILanguageImpl

use of org.metaborg.core.language.ILanguageImpl in project spoofax by metaborg.

the class SyntaxService method parse.

@Override
public P parse(I input, IProgress progress, ICancel cancel) throws ParseException, InterruptedException {
    final ILanguageImpl langImpl = input.langImpl();
    final IParser<I, P> parser = parser(langImpl);
    if (parser == null) {
        final String message = logger.format("Cannot get a parser for {}", langImpl);
        throw new ParseException(input, message);
    }
    return parser.parse(input, progress, cancel);
}
Also used : ILanguageImpl(org.metaborg.core.language.ILanguageImpl)

Aggregations

ILanguageImpl (org.metaborg.core.language.ILanguageImpl)53 FileObject (org.apache.commons.vfs2.FileObject)32 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)24 MetaborgException (org.metaborg.core.MetaborgException)17 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)15 ILanguage (org.metaborg.core.language.ILanguage)14 HybridInterpreter (org.strategoxt.HybridInterpreter)13 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)11 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)11 Test (org.junit.Test)10 IContext (org.metaborg.core.context.IContext)10 LanguageVersion (org.metaborg.core.language.LanguageVersion)10 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)9 MetaborgTest (org.metaborg.core.test.MetaborgTest)9 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)9 IProject (org.metaborg.core.project.IProject)8 Nullable (javax.annotation.Nullable)6 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)6 IdentifiedResource (org.metaborg.core.language.IdentifiedResource)5 ISourceRegion (org.metaborg.core.source.ISourceRegion)5