Internal C++11 flex cleanups. No functional change intended.

This commit is contained in:
Wilson Snyder 2021-07-24 12:49:07 -04:00
parent 275885a797
commit 43ecaec9a0
2 changed files with 15 additions and 15 deletions

View File

@ -524,7 +524,7 @@ again:
}
}
if (debug() >= 10) {
cout << "- pp::inputToLex got=" << got << " '" << string(buf, got) << "'" << endl;
cout << "- pp::inputToLex got=" << got << " '" << std::string{buf, got} << "'" << endl;
}
return got;
}
@ -567,7 +567,7 @@ string V3PreLex::endOfStream(bool& againr) {
// Final shutdown phase for a stream, we can finally change the
// current fileline to the new stream
curStreamp()->m_termState = 0;
FileLine* filelinep = curFilelinep();
FileLine* const filelinep = curFilelinep();
delete curStreamp();
m_streampStack.pop(); // Must work as size>1; EOF is entry 0
if (curStreamp()->m_eof) {
@ -590,7 +590,7 @@ string V3PreLex::endOfStream(bool& againr) {
void V3PreLex::initFirstBuffer(FileLine* filelinep) {
// Called from constructor to make first buffer
// yy_create_buffer also sets yy_fill_buffer=1 so reads from YY_INPUT
VPreStream* streamp = new VPreStream(filelinep, this);
VPreStream* const streamp = new VPreStream{filelinep, this};
streamp->m_eof = true;
m_streampStack.push(streamp);
//
@ -606,7 +606,7 @@ void V3PreLex::scanNewFile(FileLine* filelinep) {
yyerrorf("Recursive `define or other nested inclusion");
curStreamp()->m_eof = true; // Fake it to stop recursion
} else {
VPreStream* streamp = new VPreStream(filelinep, this);
VPreStream* const streamp = new VPreStream{filelinep, this};
m_tokFilelinep = curFilelinep();
streamp->m_file = true;
scanSwitchStream(streamp);
@ -615,7 +615,7 @@ void V3PreLex::scanNewFile(FileLine* filelinep) {
void V3PreLex::scanBytes(const string& str) {
// Note buffers also appended in ::scanBytesBack
// Not "m_buffers.push_front(string(strp,len))" as we need a `define
// Not "m_buffers.push_front(string{strp,len})" as we need a `define
// to take effect immediately, in the middle of the current buffer
// Also we don't use scan_bytes that would set yy_fill_buffer
// which would force Flex to bypass our YY_INPUT routine.
@ -625,7 +625,7 @@ void V3PreLex::scanBytes(const string& str) {
yyerrorf("Recursive `define or other nested inclusion");
curStreamp()->m_eof = true; // Fake it to stop recursion
} else {
VPreStream* streamp = new VPreStream(curFilelinep(), this);
VPreStream* const streamp = new VPreStream{curFilelinep(), this};
streamp->m_buffers.push_front(str);
scanSwitchStream(streamp);
}
@ -649,7 +649,7 @@ string V3PreLex::currentUnreadChars() {
ssize_t left = (yy_n_chars - (yy_c_buf_p - currentBuffer()->yy_ch_buf));
if (left > 0) { // left may be -1 at EOS
*(yy_c_buf_p) = (yy_hold_char);
return string(yy_c_buf_p, left);
return std::string(yy_c_buf_p, left); // () narrowing conversion
} else {
return "";
}
@ -689,7 +689,7 @@ void V3PreLex::dumpStack() {
dumpSummary();
std::stack<VPreStream*> tmpstack = LEXP->m_streampStack;
while (!tmpstack.empty()) {
VPreStream* streamp = tmpstack.top();
const VPreStream* const streamp = tmpstack.top();
cout << "- bufferStack[" << cvtToHex(streamp) << "]: "
<< " at=" << streamp->m_curFilelinep << " nBuf=" << streamp->m_buffers.size()
<< " size0=" << (streamp->m_buffers.empty() ? 0 : streamp->m_buffers.front().length())

View File

@ -60,9 +60,9 @@
//======================================================================
static double lexParseDouble(FileLine* fl, const char* textp, size_t length) {
string text = std::string(textp, length);
const string text = std::string{textp, length};
bool success = false;
double d = VString::parseDouble(text, &success);
const double d = VString::parseDouble(text, &success);
if (!success) fl->v3error("Syntax error parsing real: '" << textp << "'");
return d;
}
@ -608,7 +608,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5}
/* Default PLI rule */
<V95,V01NC,V01C,V05,VA5,S05,S09,S12,S17,SAX>{
"$"[a-zA-Z_$][a-zA-Z0-9_$]* { string str (yytext, yyleng);
"$"[a-zA-Z_$][a-zA-Z0-9_$]* { const string str (yytext, yyleng);
yylval.strp = PARSEP->newString(AstNode::encodeName(str));
FL; return yaD_PLI;
}
@ -861,10 +861,10 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5}
/* Identifiers and numbers */
<V95,V01NC,V01C,V05,VA5,S05,S09,S12,S17,SAX,VLT>{
{escid} { FL; yylval.strp = PARSEP->newString
(AstNode::encodeName(string(yytext+1))); // +1 to skip the backslash
(AstNode::encodeName(std::string{yytext+1})); // +1 to skip the backslash
return yaID__LEX;
}
{id} { FL; yylval.strp = PARSEP->newString(AstNode::encodeName(string(yytext)));
{id} { FL; yylval.strp = PARSEP->newString(AstNode::encodeName(std::string{yytext}));
return yaID__LEX;
}
\"[^\"\\]*\" { FL; yylval.strp = PARSEP->newString(yytext+1, yyleng-2);
@ -875,10 +875,10 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5}
/* "# 1'b0" is a delay value so must lex as "#" "1" "'b0" */
if (PARSEP->lexPrevToken()=='#') {
int shortlen = 0;
while (isdigit(yytext[shortlen])) shortlen++;
while (isdigit(yytext[shortlen])) ++shortlen;
if (shortlen) {
// Push rest past numbers for later parse
PARSEP->lexUnputString(yytext+shortlen, yyleng-shortlen);
PARSEP->lexUnputString(yytext + shortlen, yyleng - shortlen);
// Return is stuff before the tick
yyleng = shortlen;
yytext[yyleng] = '\0';