summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pparser.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-01-20 22:17:58 +0100
committer couriersud <couriersud@gmx.org>2019-01-20 22:18:07 +0100
commit26420facff351d16d15a9ace7434aeaabccce9b5 (patch)
tree4ec07c0c9a831895bde1a24b631fbd99dbdb761f /src/lib/netlist/plib/pparser.cpp
parent46485eb727d2e7db32cda1fe44fdd252afc9cdfb (diff)
netlist: add comment processing to preprocessor. [couriersud]
Comments are now processed in the preprocessor. Previously directives in multiline comments were processed.
Diffstat (limited to 'src/lib/netlist/plib/pparser.cpp')
-rw-r--r--src/lib/netlist/plib/pparser.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp
index f7b7c7bae36..8cfc2b20cec 100644
--- a/src/lib/netlist/plib/pparser.cpp
+++ b/src/lib/netlist/plib/pparser.cpp
@@ -274,6 +274,8 @@ ppreprocessor::ppreprocessor(std::vector<define_t> *defines)
, m_level(0)
, m_lineno(0)
, m_pos(0)
+, m_state(PROCESS)
+, m_comment(false)
{
m_expr_sep.push_back("!");
m_expr_sep.push_back("(");
@@ -400,8 +402,69 @@ static pstring catremainder(const std::vector<pstring> &elems, std::size_t start
return ret;
}
-pstring ppreprocessor::process_line(const pstring &line)
+pstring ppreprocessor::process_comments(pstring line)
{
+ bool in_string = false;
+
+ std::size_t e = line.size();
+ pstring ret = "";
+ for (std::size_t i=0; i < e; )
+ {
+ pstring c = plib::left(line, 1);
+ line = line.substr(1);
+ if (!m_comment)
+ {
+ if (c=="\"")
+ {
+ in_string = !in_string;
+ ret += c;
+ }
+ else if (in_string && c=="\\")
+ {
+ i++;
+ ret += (c + plib::left(line, 1));
+ line = line.substr(1);
+ }
+ else if (!in_string && c=="/" && plib::left(line,1) == "*")
+ m_comment = true;
+ else if (!in_string && c=="/" && plib::left(line,1) == "/")
+ break;
+ else
+ ret += c;
+ }
+ else
+ if (c=="*" && plib::left(line,1) == "/")
+ {
+ i++;
+ line = line.substr(1);
+ m_comment = false;
+ }
+ i++;
+ }
+ return ret;
+}
+
+pstring ppreprocessor::process_line(pstring line)
+{
+ bool line_cont = plib::right(line, 1) == "\\";
+ if (line_cont)
+ line = plib::left(line, line.size() - 1);
+
+ if (m_state == LINE_CONTINUATION)
+ m_line += line;
+ else
+ m_line = line;
+
+ if (line_cont)
+ {
+ m_state = LINE_CONTINUATION;
+ return "";
+ }
+ else
+ m_state = PROCESS;
+
+ line = process_comments(m_line);
+
pstring lt = plib::trim(plib::replace_all(line, pstring("\t"), pstring(" ")));
pstring ret;
// FIXME ... revise and extend macro handling