Internals: UINFO now includes newline itself. No functional change.

This commit is contained in:
Wilson Snyder
2025-05-22 20:29:32 -04:00
parent 091be59f0d
commit 46c7b69c64
129 changed files with 1259 additions and 1287 deletions
+38 -39
View File
@@ -345,7 +345,7 @@ FileLine* V3PreProcImp::defFileline(const string& name) {
}
void V3PreProcImp::define(FileLine* fl, const string& name, const string& value,
const string& params, bool cmdline) {
UINFO(4, "DEFINE '" << name << "' as '" << value << "' params '" << params << "'" << endl);
UINFO(4, "DEFINE '" << name << "' as '" << value << "' params '" << params << "'");
if (!V3LanguageWords::isKeyword("`"s + name).empty()) {
fl->v3error("Attempting to define built-in directive: '`" << name
<< "' (IEEE 1800-2023 22.5.1)");
@@ -619,13 +619,13 @@ string V3PreProcImp::defineSubst(VDefineRef* refp) {
// Note we parse the definition parameters and value here. If a
// parameterized define is used many, many times, we could cache the
// parsed result.
UINFO(4, "defineSubstIn `" << refp->name() << " " << refp->params() << endl);
UINFO(4, "defineSubstIn `" << refp->name() << " " << refp->params());
for (unsigned i = 0; i < refp->args().size(); i++) {
UINFO(4, "defineArg[" << i << "] = '" << refp->args()[i] << "'" << endl);
UINFO(4, "defineArg[" << i << "] = '" << refp->args()[i] << "'");
}
// Grab value
const string value = defValue(refp->name());
UINFO(4, "defineValue '" << V3PreLex::cleanDbgStrg(value) << "'" << endl);
UINFO(4, "defineValue '" << V3PreLex::cleanDbgStrg(value) << "'");
std::map<const string, string> argValueByName;
{ // Parse argument list into map
@@ -640,8 +640,8 @@ string V3PreProcImp::defineSubst(VDefineRef* refp) {
const char* cp = params.c_str();
if (*cp == '(') cp++;
for (; *cp; cp++) {
// UINFO(4," Parse Paren="<<paren<<" Arg="<<numArgs<<" token='"<<token<<"'
// Parse="<<cp<<endl);
// UINFO(4, " Parse Paren=" << paren << " Arg=" << numArgs << " token='" << token
// << "' Parse=" << cp);
if (!quote && paren == 1) {
if (*cp == ')' || *cp == ',') {
string valueDef;
@@ -652,7 +652,7 @@ string V3PreProcImp::defineSubst(VDefineRef* refp) {
}
argName = trimWhitespace(argName, true);
UINFO(4, " Got Arg=" << numArgs << " argName='" << argName
<< "' default='" << valueDef << "'" << endl);
<< "' default='" << valueDef << "'");
// Parse it
if (argName != "") {
if (refp->args().size() > numArgs) {
@@ -714,7 +714,7 @@ string V3PreProcImp::defineSubst(VDefineRef* refp) {
bool backslashesc = false; // In \.....{space} block
// Note we go through the loop once more at the nullptr end-of-string
for (const char* cp = value.c_str(); (*cp) || argName != ""; cp = (*cp ? cp + 1 : cp)) {
// UINFO(4, "CH "<<*cp<<" an "<<argName<<endl);
// UINFO(4, "CH " << *cp << " an " << argName);
if (!quote && !triquote && *cp == '\\') {
backslashesc = true;
} else if (std::isspace(*cp)) {
@@ -805,7 +805,7 @@ string V3PreProcImp::defineSubst(VDefineRef* refp) {
}
}
UINFO(4, "defineSubstOut '" << V3PreLex::cleanDbgStrg(out) << "'" << endl);
UINFO(4, "defineSubstOut '" << V3PreLex::cleanDbgStrg(out) << "'");
return out;
}
@@ -1015,7 +1015,7 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) {
UINFO(0, flcol << ": " << cmtp << " " << (m_off ? "of" : "on") << " "
<< procStateName(state()) << "(" << static_cast<int>(m_states.size())
<< ") dr" << m_defRefs.size() << ": <" << m_lexp->currentStartState()
<< ">" << tokenName(tok) << ": " << buf << endl);
<< ">" << tokenName(tok) << ": " << buf);
if (s_debugFileline >= 9) {
std::cout << m_lexp->m_tokFilelinep->warnContextSecondary() << endl;
}
@@ -1078,13 +1078,13 @@ int V3PreProcImp::getStateToken() {
string name(yyourtext() + 1, yyourleng() - 1);
if (defExists(name)) { // JOIN(DEFREF)
// Put back the `` and process the defref
UINFO(5, "```: define " << name << " exists, expand first\n");
UINFO(5, "```: define " << name << " exists, expand first");
// After define, unputString("``"). Not now as would lose yyourtext()
m_defPutJoin = true;
UINFO(5, "TOKEN now DEFREF\n");
UINFO(5, "TOKEN now DEFREF");
tok = VP_DEFREF;
} else { // DEFREF(JOIN)
UINFO(5, "```: define " << name << " doesn't exist, join first\n");
UINFO(5, "```: define " << name << " doesn't exist, join first");
// FALLTHRU, handle as with VP_SYMBOL_JOIN
}
}
@@ -1097,7 +1097,7 @@ int V3PreProcImp::getStateToken() {
|| tok == VP_DEFREF_JOIN || tok == VP_JOIN) {
// a`` -> string doesn't include the ``, so can just grab next and continue
string out(yyourtext(), yyourleng());
UINFO(5, "`` LHS:" << out << endl);
UINFO(5, "`` LHS:" << out);
// a``b``c can have multiple joins, so we need a stack
m_joinStack.push(out);
statePush(ps_JOIN);
@@ -1118,7 +1118,7 @@ int V3PreProcImp::getStateToken() {
m_lastSym.assign(yyourtext(), yyourleng());
if (state() == ps_DEFNAME_IFDEF || state() == ps_DEFNAME_IFNDEF) {
bool enable = defExists(m_lastSym);
UINFO(4, "Ifdef " << m_lastSym << (enable ? " ON" : " OFF") << endl);
UINFO(4, "Ifdef " << m_lastSym << (enable ? " ON" : " OFF"));
if (state() == ps_DEFNAME_IFNDEF) enable = !enable;
m_ifdefStack.push(VPreIfEntry{enable, false});
if (!enable) parsingOff();
@@ -1134,7 +1134,7 @@ int V3PreProcImp::getStateToken() {
if (!lastIf.on()) parsingOn();
// Handle `if portion
const bool enable = !lastIf.everOn() && defExists(m_lastSym);
UINFO(4, "Elsif " << m_lastSym << (enable ? " ON" : " OFF") << endl);
UINFO(4, "Elsif " << m_lastSym << (enable ? " ON" : " OFF"));
m_ifdefStack.push(VPreIfEntry{enable, lastIf.everOn()});
if (!enable) parsingOff();
}
@@ -1142,7 +1142,7 @@ int V3PreProcImp::getStateToken() {
goto next_tok;
} else if (state() == ps_DEFNAME_UNDEF) {
if (!m_off) {
UINFO(4, "Undef " << m_lastSym << endl);
UINFO(4, "Undef " << m_lastSym);
undef(m_lastSym);
}
statePop();
@@ -1161,7 +1161,7 @@ int V3PreProcImp::getStateToken() {
if (yyourleng() == 1 && yyourtext()[0] == '('
&& (state() == ps_DEFNAME_IFDEF || state() == ps_DEFNAME_IFNDEF
|| state() == ps_DEFNAME_ELSIF)) {
UINFO(4, "ifdef() start (\n");
UINFO(4, "ifdef() start (");
m_lexp->pushStateExpr();
m_exprParser.reset(fileline());
m_exprParenLevel = 1;
@@ -1222,7 +1222,7 @@ int V3PreProcImp::getStateToken() {
} else {
// Done with parsing expression
bool enable = m_exprParser.result();
UINFO(4, "ifdef() result=" << enable << endl);
UINFO(4, "ifdef() result=" << enable);
if (state() == ps_EXPR_IFDEF || state() == ps_EXPR_IFNDEF) {
if (state() == ps_EXPR_IFNDEF) enable = !enable;
m_ifdefStack.push(VPreIfEntry{enable, false});
@@ -1239,7 +1239,7 @@ int V3PreProcImp::getStateToken() {
if (!lastIf.on()) parsingOn();
// Handle `if portion
enable = !lastIf.everOn() && enable;
UINFO(4, "Elsif " << m_lastSym << (enable ? " ON" : " OFF") << endl);
UINFO(4, "Elsif " << m_lastSym << (enable ? " ON" : " OFF"));
m_ifdefStack.push(VPreIfEntry{enable, lastIf.everOn()});
if (!enable) parsingOff();
}
@@ -1322,7 +1322,7 @@ int V3PreProcImp::getStateToken() {
value = trimWhitespace(value, true);
// Define it
UINFO(4, "Define " << m_lastSym << " " << formals << " = '"
<< V3PreLex::cleanDbgStrg(value) << "'" << endl);
<< V3PreLex::cleanDbgStrg(value) << "'");
define(fileline(), m_lastSym, value, formals, false);
}
} else {
@@ -1353,7 +1353,7 @@ int V3PreProcImp::getStateToken() {
VDefineRef* refp = &(m_defRefs.top());
refp->nextarg(refp->nextarg() + m_lexp->m_defValue);
m_lexp->m_defValue = "";
UINFO(4, "defarg++ " << refp->nextarg() << endl);
UINFO(4, "defarg++ " << refp->nextarg());
if (tok == VP_DEFARG && yyourleng() == 1 && yyourtext()[0] == ',') {
refp->args().push_back(refp->nextarg());
stateChange(ps_DEFARG);
@@ -1378,7 +1378,7 @@ int V3PreProcImp::getStateToken() {
const string lhs = m_joinStack.top();
m_joinStack.pop();
out.insert(0, lhs);
UINFO(5, "``-end-defarg Out:" << out << endl);
UINFO(5, "``-end-defarg Out:" << out);
statePop();
}
if (!m_off) {
@@ -1427,7 +1427,7 @@ int V3PreProcImp::getStateToken() {
if (tok == VP_STRING) {
statePop();
m_lastSym.assign(yyourtext(), yyourleng());
UINFO(4, "Include " << m_lastSym << endl);
UINFO(4, "Include " << m_lastSym);
// Drop leading and trailing quotes.
m_lastSym.erase(0, 1);
m_lastSym.erase(m_lastSym.length() - 1, 1);
@@ -1466,11 +1466,11 @@ int V3PreProcImp::getStateToken() {
UASSERT(!m_joinStack.empty(), "`` join stack empty, but in a ``");
const string lhs = m_joinStack.top();
m_joinStack.pop();
UINFO(5, "`` LHS:" << lhs << endl);
UINFO(5, "`` LHS:" << lhs);
string rhs(yyourtext(), yyourleng());
UINFO(5, "`` RHS:" << rhs << endl);
UINFO(5, "`` RHS:" << rhs);
const string out = lhs + rhs;
UINFO(5, "`` Out:" << out << endl);
UINFO(5, "`` Out:" << out);
unputString(out);
statePop();
goto next_tok;
@@ -1542,14 +1542,14 @@ int V3PreProcImp::getStateToken() {
const VPreIfEntry lastIf = m_ifdefStack.top();
m_ifdefStack.pop();
const bool enable = !lastIf.everOn();
UINFO(4, "Else " << (enable ? " ON" : " OFF") << endl);
UINFO(4, "Else " << (enable ? " ON" : " OFF"));
m_ifdefStack.push(VPreIfEntry{enable, lastIf.everOn()});
if (!lastIf.on()) parsingOn();
if (!enable) parsingOff();
}
goto next_tok;
case VP_ENDIF:
UINFO(4, "Endif " << endl);
UINFO(4, "Endif ");
if (m_ifdefStack.empty()) {
fileline()->v3error("`endif with no matching `if");
} else {
@@ -1565,7 +1565,7 @@ int V3PreProcImp::getStateToken() {
// m_off not right here, but inside substitution, to make this work:
// `ifdef NEVER `DEFUN(`endif)
string name(yyourtext() + 1, yyourleng() - 1);
UINFO(4, "DefRef " << name << endl);
UINFO(4, "DefRef " << name);
if (m_defPutJoin) {
m_defPutJoin = false;
unputString("``");
@@ -1577,7 +1577,7 @@ int V3PreProcImp::getStateToken() {
// Substitute
if (!defExists(name)) { // Not found, return original string as-is
m_defDepth = 0;
UINFO(4, "Defref `" << name << " => not_defined" << endl);
UINFO(4, "Defref `" << name << " => not_defined");
if (m_off) {
goto next_tok;
} else {
@@ -1603,7 +1603,7 @@ int V3PreProcImp::getStateToken() {
const string lhs = m_joinStack.top();
m_joinStack.pop();
out.insert(0, lhs);
UINFO(5, "``-end-defref Out:" << out << endl);
UINFO(5, "``-end-defref Out:" << out);
statePop();
}
if (!m_off) {
@@ -1624,7 +1624,7 @@ int V3PreProcImp::getStateToken() {
}
goto next_tok;
} else { // Found, with parameters
UINFO(4, "Defref `" << name << " => parameterized" << endl);
UINFO(4, "Defref `" << name << " => parameterized");
// The CURRENT macro needs the paren saved, it's not a
// property of the child macro
if (!m_defRefs.empty()) m_defRefs.top().parenLevel(m_lexp->m_parenLevel);
@@ -1646,7 +1646,7 @@ int V3PreProcImp::getStateToken() {
return tok;
case VP_UNDEFINEALL:
if (!m_off) {
UINFO(4, "Undefineall " << endl);
UINFO(4, "Undefineall ");
undefineall();
}
goto next_tok;
@@ -1691,7 +1691,7 @@ int V3PreProcImp::getFinalToken(string& buf) {
if (false && debug() >= 5) {
const string bufcln = V3PreLex::cleanDbgStrg(buf);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
UINFO(0, flcol << ": FIN: " << tokenName(tok) << ": " << bufcln << endl);
UINFO(0, flcol << ": FIN: " << tokenName(tok) << ": " << bufcln);
}
// Track `line
const char* bufp = buf.c_str();
@@ -1706,8 +1706,7 @@ int V3PreProcImp::getFinalToken(string& buf) {
if (debug() >= 5) {
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
UINFO(0, flcol << ": FIN: readjust, fin at " << m_finFilelinep->lastLineno()
<< " request at " << m_lexp->m_tokFilelinep->lastLineno()
<< endl);
<< " request at " << m_lexp->m_tokFilelinep->lastLineno());
}
m_finFilelinep->filename(m_lexp->m_tokFilelinep->filename());
m_finFilelinep->lineno(m_lexp->m_tokFilelinep->lastLineno());
@@ -1751,7 +1750,7 @@ string V3PreProcImp::getline() {
if (debug() >= 5) {
const string bufcln = V3PreLex::cleanDbgStrg(buf);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
UINFO(0, flcol << ": GETFETC: " << tokenName(tok) << ": " << bufcln << endl);
UINFO(0, flcol << ": GETFETC: " << tokenName(tok) << ": " << bufcln);
}
if (tok == VP_EOF) {
// Add a final newline, if the user forgot the final \n.
@@ -1771,7 +1770,7 @@ string V3PreProcImp::getline() {
if (debug() >= 4) {
const string lncln = V3PreLex::cleanDbgStrg(theLine);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
UINFO(0, flcol << ": GETLINE: " << lncln << endl);
UINFO(0, flcol << ": GETLINE: " << lncln);
}
return theLine;
}