use of org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit 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);
}
use of org.metaborg.spoofax.core.unit.ISpoofaxAnalyzeUnit 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));
}
Aggregations