#include #include "sliceCompile.h" #include #include std::mutex slicePreprocessor; SliceCompile::SliceCompile(const boost::filesystem::path & slice, const IceCompile::Deps & dep) : IceCompile(slice, dep) { } unsigned int SliceCompile::build(const boost::filesystem::path & in, FILE * out) const { std::vector cppArgs; std::lock_guard lock(slicePreprocessor); Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slice2project2", in.string(), cppArgs); FILE * cppHandle = icecpp->preprocess(false); if (cppHandle == NULL) { throw std::runtime_error("preprocess failed"); } Slice::UnitPtr u = Slice::Unit::createUnit(false, false, false, false); ScopeObject uDestroy(boost::bind(&Slice::Unit::destroy, u.get())); int parseStatus = u->parse(in.string(), cppHandle, false); if (!icecpp->close()) { throw std::runtime_error("preprocess close failed"); } if (parseStatus == EXIT_FAILURE) { throw std::runtime_error("unit parse failed"); } if (out) { fprintf(out, "#include <%s>\n", (in.filename().replace_extension(".h")).string().c_str()); Headers(out); fprintf(out, "\n"); } return Body(out, u); } unsigned int SliceCompile::Build(const boost::filesystem::path & in, const boost::filesystem::path & outpath) const { FILE * out = fopen(outpath.string().c_str(), "w"); if (!out) { throw std::runtime_error("failed to open target"); } auto components = build(in, out); if (fclose(out)) { throw std::runtime_error("failed to close target"); } return components; } unsigned int SliceCompile::Count(const boost::filesystem::path & in) const { return build(in, NULL); } void SliceCompile::Headers(FILE *) const { } boost::filesystem::path SliceCompile::InputPath() const { return slice; }