/** * Finds and loads a logic into the given symbol table * * @param logicName name of the logic to load * @param symTable the symbol table into which to load it * @return null if read OK, an error if a problem happened */ public /* @Nullable */ IResponse loadLogic( String logicName, SymbolTable symTable, /* @Nullable */ IPos pos) { ILogic sx = null; // = findLogic(logicName, smtConfig.logicPath, pos); { String name = logicName; ISource source; InputStream input = null; try { SMT.Configuration config = smtConfig.clone(); config.interactive = false; input = SMT.logicFinder.find(smtConfig, name, pos); if (input == null) return smtConfig.responseFactory.error( "Unexpected null result: No logic loaded " + name, pos); // The above error should not happen, because an exception // ought to be thrown for any problems in find(). source = config.smtFactory.createSource(config, input, null); IParser p = config.smtFactory.createParser(config, source); sx = p.parseLogic(); symTable.logicInUse = sx; } catch (IParser.ParserException e) { return smtConfig.responseFactory.error( "Failed to parse the logic file " + name + ": " + e, e.pos()); } catch (Utils.SMTLIBException e) { return e.errorResponse; } catch (Exception e) { return smtConfig.responseFactory.error( "Failed to read the logic file for " + name + ": " + e, null); } finally { try { if (input != null) input.close(); } catch (java.io.IOException e) { return smtConfig.responseFactory.error( "Failed to close a stream while parsing " + name + " : " + e, null); } } } if (sx == null) { return smtConfig.responseFactory.error("Failed to load logic", pos); } // The second element should be the name of the logic, if specified if (!logicName.equals(sx.logicName().value())) { return smtConfig.responseFactory.error( "Definition of logic " + logicName + " is mal-formed (internal name does not match file name): " + sx.logicName().value(), sx.logicName().pos()); } return loadLogic(sx, symTable); }
// FIXME Fix the use of path here - it actually is used only for error messages and should not be // null public ITheory findTheory(String name, /* @Nullable */ String path) throws SMTLIBException { ISource source; InputStream input = null; try { SMT.Configuration config = smtConfig.clone(); config.interactive = false; input = SMT.logicFinder.find(smtConfig, name, null); // All errors should result in thrown exceptions, not all null response if (input == null) { throw new Utils.SMTLIBException( smtConfig.responseFactory.error( "Unexpected null returned from SMT.logicFinder when parsing the theory file for " + name + " in " + path)); } source = config.smtFactory.createSource(config, input, null); IParser p = config.smtFactory.createParser(config, source); return p.parseTheory(); } catch (IParser.ParserException e) { throw new SMTLIBException( smtConfig.log.logError( smtConfig.responseFactory.error( "Failed to parse the theory file " + name + " in " + path + ": " + e, e.pos()))); } catch (Exception e) { throw new SMTLIBException( smtConfig.log.logError( smtConfig.responseFactory.error( "Failed to read the theory file " + name + " in " + path + ": " + e, null))); } finally { try { if (input != null) input.close(); } catch (java.io.IOException e) { throw new SMTLIBException( smtConfig.log.logError( smtConfig.responseFactory.error( "Failed to close a stream while parsing " + name + " in " + path + " : " + e, null))); } } }