diff options
Diffstat (limited to 'project2/ice/sliceCompile.cpp')
-rw-r--r-- | project2/ice/sliceCompile.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/project2/ice/sliceCompile.cpp b/project2/ice/sliceCompile.cpp new file mode 100644 index 0000000..f98ecde --- /dev/null +++ b/project2/ice/sliceCompile.cpp @@ -0,0 +1,59 @@ +#include <pch.hpp> +#include "sliceCompile.h" +#include <scopeObject.h> + +SliceCompile::SliceCompile(const boost::filesystem::path & slice, const IceCompile::Deps & dep) : + IceCompile(slice, dep) +{ +} + +void +SliceCompile::Build(const boost::filesystem::path & in, const boost::filesystem::path & outpath) const +{ + std::vector<std::string> cppArgs; + 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"); + } + + FILE * out = fopen(outpath.string().c_str(), "w"); + if (!out) { + throw std::runtime_error("failed to open target"); + } + + fprintf(out, "#include <%s>\n", (in.filename().replace_extension(".h")).string().c_str()); + Headers(out); + fprintf(out, "\n"); + Body(out, u); + + if (fclose(out)) { + throw std::runtime_error("failed to close target"); + } +} + +void +SliceCompile::Headers(FILE *) const +{ +} + +boost::filesystem::path +SliceCompile::InputPath() const +{ + return slice; +} + |