diff options
Diffstat (limited to 'src/lib/netlist/plib/pparser.cpp')
-rw-r--r-- | src/lib/netlist/plib/pparser.cpp | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index cfa30669801..be52b27dc30 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -29,7 +29,7 @@ void ptokenizer::skipeol() { c = getc(); if (c != 13) - ungetc(); + ungetc(c); return; } c = getc(); @@ -39,24 +39,28 @@ void ptokenizer::skipeol() pstring::code_t ptokenizer::getc() { - if (m_px >= m_cur_line.len()) + if (m_unget != 0) + { + pstring::code_t c = m_unget; + m_unget = 0; + return c; + } + if (m_px == m_cur_line.end()) { m_lineno++; if (m_strm.readline(m_cur_line)) - { - if (m_cur_line.right(1) != "\n") - m_cur_line += "\n"; - m_px = 0; - } + m_px = m_cur_line.begin(); else return 0; + return '\n'; } - return m_cur_line.code_at(m_px++); + pstring::code_t c = *(m_px++); + return c; } -void ptokenizer::ungetc() +void ptokenizer::ungetc(pstring::code_t c) { - m_px--; + m_unget = c; } void ptokenizer::require_token(const token_id_t &token_num) @@ -68,7 +72,11 @@ void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) { if (!tok.is(token_num)) { - error(pfmt("Expected token <{1}> got <{2}>")(m_tokens[token_num.id()])(tok.str()) ); + pstring val(""); + for (auto &i : m_tokens) + if (i.second.id() == token_num.id()) + val = i.first; + error(pfmt("Expected token <{1}> got <{2}>")(val)(tok.str()) ); } } @@ -163,7 +171,7 @@ ptokenizer::token_t ptokenizer::get_token_internal() { /* skip ws */ pstring::code_t c = getc(); - while (m_whitespace.find(c)>=0) + while (m_whitespace.find(c) != m_whitespace.end()) { c = getc(); if (eof()) @@ -171,7 +179,7 @@ ptokenizer::token_t ptokenizer::get_token_internal() return token_t(ENDOFFILE); } } - if (m_number_chars_start.find(c)>=0) + if (m_number_chars_start.find(c) != m_number_chars_start.end()) { /* read number while we receive number or identifier chars * treat it as an identifier when there are identifier chars in it @@ -180,32 +188,30 @@ ptokenizer::token_t ptokenizer::get_token_internal() token_type ret = NUMBER; pstring tokstr = ""; while (true) { - if (m_identifier_chars.find(c)>=0 && m_number_chars.find(c)<0) + if (m_identifier_chars.find(c) != m_identifier_chars.end() && m_number_chars.find(c) == m_number_chars.end()) ret = IDENTIFIER; - else if (m_number_chars.find(c)<0) + else if (m_number_chars.find(c) == m_number_chars.end()) break; tokstr += c; c = getc(); } - ungetc(); + ungetc(c); return token_t(ret, tokstr); } - else if (m_identifier_chars.find(c)>=0) + else if (m_identifier_chars.find(c) != m_identifier_chars.end()) { /* read identifier till non identifier char */ pstring tokstr = ""; - while (m_identifier_chars.find(c)>=0) { + while (m_identifier_chars.find(c) != m_identifier_chars.end()) { tokstr += c; c = getc(); } - ungetc(); - token_id_t id(plib::container::indexof(m_tokens, tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); + ungetc(c); + auto id = m_tokens.find(tokstr); + if (id != m_tokens.end()) + return token_t(id->second, tokstr); else - { return token_t(IDENTIFIER, tokstr); - } } else if (c == m_string) { @@ -222,27 +228,24 @@ ptokenizer::token_t ptokenizer::get_token_internal() { /* read identifier till first identifier char or ws */ pstring tokstr = ""; - while ((m_identifier_chars.find(c)) < 0 && (m_whitespace.find(c) < 0)) { + while ((m_identifier_chars.find(c)) == m_identifier_chars.end() && (m_whitespace.find(c) == m_whitespace.end())) { tokstr += c; /* expensive, check for single char tokens */ if (tokstr.len() == 1) { - token_id_t id(plib::container::indexof(m_tokens, tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); + auto id = m_tokens.find(tokstr); + if (id != m_tokens.end()) + return token_t(id->second, tokstr); } c = getc(); } - ungetc(); - token_id_t id(plib::container::indexof(m_tokens, tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); + ungetc(c); + auto id = m_tokens.find(tokstr); + if (id != m_tokens.end()) + return token_t(id->second, tokstr); else - { return token_t(UNKNOWN, tokstr); - } } - } void ptokenizer::error(const pstring &errs) @@ -406,7 +409,7 @@ pstring ppreprocessor::process_line(const pstring &line) std::size_t start = 0; lt = replace_macros(lt); pstring_vector_t t(lt.substr(3).replace(" ",""), m_expr_sep); - int val = expr(t, start, 0); + int val = static_cast<int>(expr(t, start, 0)); if (val == 0) m_ifflag |= (1 << m_level); } |