Search in sources :

Example 1 with TFFileInfo

use of mb.flowspec.runtime.solver.TFFileInfo in project spoofax by metaborg.

the class AbstractConstraintAnalyzer method getFlowSpecTransferFunctions.

protected Optional<TFFileInfo> getFlowSpecTransferFunctions(ILanguageComponent component) {
    TFFileInfo transferFunctions = flowSpecTransferFunctionCache.get(component);
    if (transferFunctions != null) {
        return Optional.of(transferFunctions);
    }
    FileObject tfs = resourceService.resolve(component.location(), TRANSFER_FUNCTIONS_FILE);
    try {
        IStrategoTerm sTerm = termFactory.parseFromString(IOUtils.toString(tfs.getContent().getInputStream(), StandardCharsets.UTF_8));
        ITerm term = strategoTerms.fromStratego(sTerm);
        transferFunctions = TFFileInfo.match().match(term, PersistentUnifier.Immutable.of()).orElseThrow(() -> new ParseException("Parse error on reading the transfer function file"));
    } catch (ParseError | ParseException | IOException e) {
        logger.error("Could not read transfer functions file for {}", component);
        return Optional.empty();
    }
    logger.debug("Caching flowspec transfer functions for language {}", component);
    flowSpecTransferFunctionCache.put(component, transferFunctions);
    return Optional.of(transferFunctions);
}
Also used : TFFileInfo(mb.flowspec.runtime.solver.TFFileInfo) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) ITerm(mb.nabl2.terms.ITerm) ParseError(org.spoofax.terms.ParseError) FileObject(org.apache.commons.vfs2.FileObject) ParseException(mb.flowspec.runtime.solver.ParseException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ParseException (mb.flowspec.runtime.solver.ParseException)1 TFFileInfo (mb.flowspec.runtime.solver.TFFileInfo)1 ITerm (mb.nabl2.terms.ITerm)1 FileObject (org.apache.commons.vfs2.FileObject)1 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)1 ParseError (org.spoofax.terms.ParseError)1