diff options
Diffstat (limited to 'src/lib/netlist/plib/pparser.h')
-rw-r--r-- | src/lib/netlist/plib/pparser.h | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 5332ee2518c..ced7e500cad 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -12,9 +12,11 @@ #include "pstream.h" #include "pstring.h" +#include "putil.h" // psource_t + //#include <cstdint> #include <unordered_map> - +#include <stack> namespace plib { class ptokenizer @@ -28,6 +30,7 @@ public: , m_px(m_cur_line.begin()) , m_unget(0) , m_string('"') + , m_support_line_markers(true) // FIXME { } @@ -42,6 +45,7 @@ public: TOKEN, STRING, COMMENT, + LINEMARKER, UNKNOWN, ENDOFFILE }; @@ -156,6 +160,7 @@ private: token_id_t m_tok_comment_start; token_id_t m_tok_comment_end; token_id_t m_tok_line_comment; + bool m_support_line_markers; }; @@ -174,26 +179,7 @@ public: using defines_map_type = std::unordered_map<pstring, define_t>; - explicit ppreprocessor(defines_map_type *defines = nullptr); - - ~ppreprocessor() override - { - delete rdbuf(); - } - - template <typename T> - ppreprocessor & process(T &&istrm) - { - putf8_reader reader(std::forward<T>(istrm)); - pstring line; - while (reader.readline(line)) - { - m_lineno++; - line = process_line(line); - m_outbuf += decltype(m_outbuf)(line.c_str()) + static_cast<char>(10); - } - return *this; - } + explicit ppreprocessor(psource_collection_t<> &sources, defines_map_type *defines = nullptr); COPYASSIGN(ppreprocessor, delete) ppreprocessor &operator=(ppreprocessor &&src) = delete; @@ -201,10 +187,10 @@ public: ppreprocessor(ppreprocessor &&s) noexcept : std::istream(new readbuffer(this)) , m_defines(std::move(s.m_defines)) + , m_sources(s.m_sources) , m_expr_sep(std::move(s.m_expr_sep)) , m_if_flag(s.m_if_flag) , m_if_level(s.m_if_level) - , m_lineno(s.m_lineno) , m_outbuf(std::move(s.m_outbuf)) , m_pos(s.m_pos) , m_state(s.m_state) @@ -212,6 +198,19 @@ public: { } + ~ppreprocessor() override + { + delete rdbuf(); + } + + template <typename T> + ppreprocessor & process(T &&istrm) + { + m_stack.emplace(input_context(std::forward<T>(istrm),"","<stream>")); + process_stack(); + return *this; + } + protected: class readbuffer : public std::streambuf @@ -242,6 +241,7 @@ protected: ? std::char_traits<char>::eof() : std::char_traits<char>::to_int_type(*this->gptr()); } + private: ppreprocessor *m_strm; std::array<char_type, 1024> m_buf; @@ -261,20 +261,41 @@ private: LINE_CONTINUATION }; + void process_stack(); + pstring process_line(pstring line); pstring process_comments(pstring line); defines_map_type m_defines; + psource_collection_t<> &m_sources; std::vector<pstring> m_expr_sep; std::uint_least64_t m_if_flag; // 31 if levels int m_if_level; - int m_lineno; + + struct input_context + { + template <typename T> + input_context(T &&istrm, const pstring &local_path, const pstring &name) + : m_reader(std::forward<T>(istrm)) + , m_lineno(0) + , m_local_path(local_path) + , m_name(name) + {} + + putf8_reader m_reader; + int m_lineno; + pstring m_local_path; + pstring m_name; + }; + + std::stack<input_context> m_stack; pstring_t<pu8_traits> m_outbuf; std::istream::pos_type m_pos; state_e m_state; pstring m_line; bool m_comment; + }; } // namespace plib |