diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-06 20:34:12 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-06 20:34:12 +0200 |
commit | 1bb22babd9f978be24c203d919f3c9760df8f3d8 (patch) | |
tree | 9097dee4ab008219096dc90dc47be116001464fb /src | |
parent | fda24d9c220b8288c297922793f933897d8fa28c (diff) | |
download | solar-1bb22babd9f978be24c203d919f3c9760df8f3d8.tar solar-1bb22babd9f978be24c203d919f3c9760df8f3d8.zip |
output: emit include statement for header
Diffstat (limited to 'src')
-rw-r--r-- | src/output.cpp | 19 | ||||
-rw-r--r-- | src/output.hpp | 3 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/output.cpp b/src/output.cpp index 6d090d0..4d9efaf 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -27,6 +27,7 @@ #include "output.hpp" #include <cerrno> +#include <cstring> #include <system_error> @@ -36,7 +37,8 @@ output_t::output_t(const generator_t *generator0, const char *header, const char : prefix_str("parse_"), token_prefix_str("TOK_"), stack_size(100), - generator(generator0) { + generator(generator0), + header_filename(header) { header_file = std::fopen(header, "w"); if (!header_file) throw std::system_error(errno, std::generic_category(), "unable to open header output file for writing"); @@ -249,7 +251,22 @@ void output_t::emit_states() { emit_state(i); } +void output_t::emit_header_include() { +#ifdef _WIN32 + const char sep = '\\'; +#else + const char sep = '/'; +#endif + + const char *slash = std::strrchr(header_filename.c_str(), sep); + const char *basename = slash ? slash+1 : header_filename.c_str(); + + std::fprintf(source_file, "#include \"%s\"\n\n\n", basename); +} + void output_t::emit_source() { + emit_header_include(); + std::fprintf(source_file, "typedef union %ssymbol_value {\n", prefix()); std::fprintf(source_file, "\t%stoken_value_t token;\n", prefix()); diff --git a/src/output.hpp b/src/output.hpp index 439e754..913f123 100644 --- a/src/output.hpp +++ b/src/output.hpp @@ -41,6 +41,8 @@ private: const generator_t *generator; + std::string header_filename; + std::FILE *header_file; std::FILE *source_file; @@ -67,6 +69,7 @@ private: void emit_state_reduce(const item_t &item, int rule_id); void emit_state(unsigned i); void emit_states(); + void emit_header_include(); void emit_source(); public: |