netlist: add comment processing to preprocessor. [couriersud]

Comments are now processed in the preprocessor. Previously directives in
multiline comments were processed.
This commit is contained in:
couriersud 2019-01-20 22:17:58 +01:00
parent 46485eb727
commit 26420facff
4 changed files with 78 additions and 4 deletions

View File

@ -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

View File

@ -188,6 +188,8 @@ public:
, m_lineno(s.m_lineno)
, m_buf(s.m_buf)
, m_pos(s.m_pos)
, m_state(s.m_state)
, m_comment(s.m_comment)
{
}
@ -204,7 +206,13 @@ protected:
private:
pstring process_line(const pstring &line);
enum state_e
{
PROCESS,
LINE_CONTINUATION
};
pstring process_line(pstring line);
pstring process_comments(pstring line);
std::unordered_map<pstring, define_t> m_defines;
std::vector<pstring> m_expr_sep;
@ -214,6 +222,9 @@ private:
int m_lineno;
pstring_t<pu8_traits> m_buf;
pos_type m_pos;
state_e m_state;
pstring m_line;
bool m_comment;
};
}

View File

@ -288,7 +288,7 @@ void NETLIB_NAME(solver)::post_start()
switch (net_count)
{
#if 1
#if 0
case 1:
if (use_specific)
ms = plib::palloc<matrix_solver_direct1_t>(state(), sname, &m_params);

View File

@ -2,7 +2,7 @@
// copyright-holders:Andrew Gardner, Couriersud
#include "netlist/devices/net_lib.h"
#define USE_FRONTIERS 0
#define USE_FRONTIERS 1
#define USE_FIXED_STV 1
/* ----------------------------------------------------------------------------