diff options
Diffstat (limited to 'src/lib/netlist/plib/pparser.h')
-rw-r--r-- | src/lib/netlist/plib/pparser.h | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 17f43284e2c..36ecd02e017 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -19,7 +19,11 @@ namespace plib { class ptokenizer : nocopyassignmove { public: - ptokenizer(plib::putf8_reader &&strm); + template <typename T> + ptokenizer(T &&strm) + : m_strm(std::move(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"') + { + } virtual ~ptokenizer(); @@ -98,15 +102,16 @@ public: return ret; } - void set_identifier_chars(pstring s) { m_identifier_chars = s; } - void set_number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; } - void set_string_char(pstring::value_type c) { m_string = c; } - void set_whitespace(pstring s) { m_whitespace = s; } - void set_comment(pstring start, pstring end, pstring line) + ptokenizer & identifier_chars(pstring s) { m_identifier_chars = s; return *this; } + ptokenizer & number_chars(pstring st, pstring rem) { m_number_chars_start = st; m_number_chars = rem; return *this; } + ptokenizer & string_char(pstring::value_type c) { m_string = c; return *this; } + ptokenizer & whitespace(pstring s) { m_whitespace = s; return *this; } + ptokenizer & comment(pstring start, pstring end, pstring line) { m_tok_comment_start = register_token(start); m_tok_comment_end = register_token(end); m_tok_line_comment = register_token(line); + return *this; } token_t get_token_internal(); @@ -145,7 +150,7 @@ private: }; -class ppreprocessor : plib::nocopyassignmove +class ppreprocessor : public pistream { public: @@ -159,11 +164,39 @@ public: }; explicit ppreprocessor(std::vector<define_t> *defines = nullptr); - virtual ~ppreprocessor() {} + virtual ~ppreprocessor() override {} - void process(putf8_reader &istrm, putf8_writer &ostrm); + template <typename T> + ppreprocessor & process(T &&istrm) + { + putf8_reader reader(std::move(istrm)); + pstring line; + while (reader.readline(line)) + { + m_lineno++; + line = process_line(line); + m_buf += decltype(m_buf)(line.c_str()) + static_cast<char>(10); + } + return *this; + } + + ppreprocessor(ppreprocessor &&s) + : m_defines(s.m_defines) + , m_expr_sep(s.m_expr_sep) + , m_ifflag(s.m_ifflag) + , m_level(s.m_level) + , m_lineno(s.m_lineno) + , m_buf(s.m_buf) + , m_pos(s.m_pos) + { + } protected: + + virtual size_type vread(value_type *buf, const size_type n) override; + virtual void vseek(const pos_type n) override { } + virtual pos_type vtell() const override { return m_pos; } + int expr(const std::vector<pstring> &sexpr, std::size_t &start, int prio); define_t *get_define(const pstring &name); pstring replace_macros(const pstring &line); @@ -179,6 +212,8 @@ private: std::uint_least64_t m_ifflag; // 31 if levels int m_level; int m_lineno; + pstring_t<pu8_traits> m_buf; + pos_type m_pos; }; } |