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