Make more use of pformat. (nw)

This commit is contained in:
couriersud 2015-08-13 19:06:28 +02:00
parent 6e3fef765d
commit 98b1106ee9
7 changed files with 24 additions and 29 deletions

View File

@ -25,7 +25,7 @@ namespace netlist
// A netlist parser
// ----------------------------------------------------------------------------------------
ATTR_COLD void parser_t::verror(pstring msg, int line_num, pstring line)
ATTR_COLD void parser_t::verror(const pstring &msg, int line_num, const pstring &line)
{
m_setup.netlist().error("line %d: error: %s\n\t\t%s\n", line_num,
msg.cstr(), line.cstr());
@ -297,7 +297,7 @@ void parser_t::net_c()
if (n.is(m_tok_param_right))
break;
if (!n.is(m_tok_comma))
error("expected a comma, found <%s>", n.str().cstr());
error(pformat("expected a comma, found <%1>")(n.str()) );
}
}
@ -317,7 +317,7 @@ void parser_t::dippins()
if (n.is(m_tok_param_right))
break;
if (!n.is(m_tok_comma))
error("expected a comma, found <%s>", n.str().cstr());
error(pformat("expected a comma, found <%1>")(n.str()) );
}
if ((pins.size() % 2) == 1)
error("You must pass an equal number of pins to DIPPINS");

View File

@ -42,7 +42,7 @@ namespace netlist
/* for debugging messages */
netlist_t &netlist() { return m_setup.netlist(); }
virtual void verror(pstring msg, int line_num, pstring line);
virtual void verror(const pstring &msg, int line_num, const pstring &line);
private:
nl_double eval_param(const token_t tok);

View File

@ -75,7 +75,7 @@ void ptokenizer::require_token(const token_t tok, const token_id_t &token_num)
{
if (!tok.is(token_num))
{
error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr());
error(pformat("Expected token <%1> got <%2>")(m_tokens[token_num.id()])(tok.str()) );
}
}
@ -84,7 +84,7 @@ pstring ptokenizer::get_string()
token_t tok = get_token();
if (!tok.is_type(STRING))
{
error("Error: expected a string, got <%s>\n", tok.str().cstr());
error(pformat("Expected a string, got <%1>")(tok.str()) );
}
return tok.str();
}
@ -94,7 +94,7 @@ pstring ptokenizer::get_identifier()
token_t tok = get_token();
if (!tok.is_type(IDENTIFIER))
{
error("Error: expected an identifier, got <%s>\n", tok.str().cstr());
error(pformat("Expected an identifier, got <%1>")(tok.str()) );
}
return tok.str();
}
@ -104,7 +104,7 @@ pstring ptokenizer::get_identifier_or_number()
token_t tok = get_token();
if (!(tok.is_type(IDENTIFIER) || tok.is_type(NUMBER)))
{
error("Error: expected an identifier, got <%s>\n", tok.str().cstr());
error(pformat("Expected an identifier, got <%1>")(tok.str()) );
}
return tok.str();
}
@ -114,12 +114,12 @@ double ptokenizer::get_number_double()
token_t tok = get_token();
if (!tok.is_type(NUMBER))
{
error("Error: expected a number, got <%s>\n", tok.str().cstr());
error(pformat("Expected a number, got <%1>")(tok.str()) );
}
bool err = false;
double ret = tok.str().as_double(&err);
if (err)
error("Error: expected a number, got <%s>\n", tok.str().cstr());
error(pformat("Expected a number, got <%1>")(tok.str()) );
return ret;
}
@ -128,12 +128,12 @@ long ptokenizer::get_number_long()
token_t tok = get_token();
if (!tok.is_type(NUMBER))
{
error("Error: expected a long int, got <%s>\n", tok.str().cstr());
error(pformat("Expected a long int, got <%1>")(tok.str()) );
}
bool err = false;
long ret = tok.str().as_long(&err);
if (err)
error("Error: expected a long int, got <%s>\n", tok.str().cstr());
error(pformat("Expected a long int, got <%1>")(tok.str()) );
return ret;
}
@ -252,16 +252,9 @@ ptokenizer::token_t ptokenizer::get_token_internal()
}
ATTR_COLD void ptokenizer::error(const char *format, ...)
ATTR_COLD void ptokenizer::error(const pstring &errs)
{
va_list ap;
va_start(ap, format);
pstring errmsg1 = pstring(format).vprintf(ap);
va_end(ap);
verror(errmsg1, currentline_no(), currentline_str());
verror("Error: " + errs, currentline_no(), currentline_str());
//throw error;
}
@ -460,7 +453,7 @@ pstring ppreprocessor::process_line(const pstring &line)
}
}
else
error(pformat("unknown directive on line %1: %2\n")(m_lineno)(line));
error(pformat("unknown directive on line %1: %2")(m_lineno)(line));
}
else
{

View File

@ -112,10 +112,10 @@ public:
}
token_t get_token_internal();
void error(const char *format, ...) ATTR_PRINTF(2,3);
void error(const pstring &errs);
protected:
virtual void verror(pstring msg, int line_num, pstring line) = 0;
virtual void verror(const pstring &msg, int line_num, const pstring &line) = 0;
private:
void skipeol();

View File

@ -395,6 +395,10 @@ public:
pformat &x (const INT64 x, const char *f = "") { return update(f, I64FMT "x", x); }
pformat &x (const UINT64 x, const char *f = "") { return update(f, I64FMT "x", x); }
pformat &operator ()(const long x, const char *f = "") { return update(f, "ld", x); }
pformat &operator ()(const unsigned long x, const char *f = "") { return update(f, "lu", x); }
pformat &operator ()(const INT32 x, const char *f = "") { return update(f, "d", x); }
pformat &operator ()(const UINT32 x, const char *f = "") { return update(f, "u", x); }
@ -405,7 +409,7 @@ public:
pformat &operator ()(const UINT16 x, const char *f = "") { return update(f, "hu", x); }
#if !defined(__MINGW32__) && !defined(__MINGW64__) && !defined(EMSCRIPTEN)
pformat &operator ()(const std::size_t x, const char *f = "") { return update(f, SIZETFMT, x); }
//pformat &operator ()(const std::size_t x, const char *f = "") { return update(f, SIZETFMT, x); }
#endif
pformat &operator ()(const double x, const char *f = "") { return update(f, "g", x); }
pformat & e(const double x, const char *f = "") { return update(f, "e", x); }
@ -422,8 +426,6 @@ private:
char m_str[2048];
unsigned m_arg;
};
//const type_t vprintf(va_list args) const;
//static const type_t sprintf(const char *format, ...) ATTR_PRINTF(1,2);
#endif /* _PSTRING_H_ */

View File

@ -439,7 +439,7 @@ void nl_convert_eagle_t::convert(const pstring &contents)
break;
}
default:
tok.error("// IGNORED %s\n", name.cstr());
tok.error("// IGNORED " + name);
}
}

View File

@ -196,7 +196,7 @@ public:
protected:
void verror(pstring msg, int line_num, pstring line)
void verror(const pstring &msg, int line_num, const pstring &line)
{
m_convert.out("%s (line %d): %s\n", msg.cstr(), line_num, line.cstr());
}