From bb41c6b26b9b1231f619e65d9c5d588bc5647ea9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 2 Jul 2025 18:47:27 -0400 Subject: [PATCH] Internals: Fix wrong fileline on some parsing scan-aheads. --- src/V3ParseImp.cpp | 17 ++++++++++++++--- src/V3ParseImp.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 36d25f859..9f7ac78d6 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -380,6 +380,15 @@ void V3ParseImp::dumpInputsFile() { VL_DO_DANGLING(delete ofp, ofp); } +void V3ParseImp::dumpTokensAhead(int line) { // LCOV_EXCL_START + int i = 0; + UINFO(1, "dumpTokensAhead @ " << line << " [ ] " << yylval); + for (auto t : m_tokensAhead) { + UINFO(1, "dumpTokensAhead @ " << line << " [" << i << "] " << t); + ++i; + } +} // LCOV_EXCL_STOP + void V3ParseImp::lexFile(const string& modname) { // Prepare for lexing UINFO(3, "Lexing " << modname); @@ -396,8 +405,11 @@ void V3ParseImp::tokenPull() { // Pull token from lex into the pipeline // This corrupts yylval, must save/restore if required // Fetch next token from prefetch or real lexer + VL_RESTORER(yylval); yylexReadTok(); // sets yylval + UINFO(9, "tokenPulled " << yylval); m_tokensAhead.push_back(yylval); + if (debug() >= 10) dumpTokensAhead(__LINE__); } const V3ParseBisonYYSType* V3ParseImp::tokenPeekp(size_t depth) { @@ -583,9 +595,7 @@ void V3ParseImp::tokenPipeline() { || token == yWITH__LEX // || token == yaID__LEX // ) { - if (debugFlex() >= 6) { - cout << " tokenPipeline: reading ahead to find possible strength" << endl; - } + if (debugFlex() >= 6) UINFO(0, "tokenPipeline: reading ahead"); const V3ParseBisonYYSType curValue = yylval; // Remember value, as about to read ahead const V3ParseBisonYYSType* nexttokp = tokenPeekp(0); const int nexttok = nexttokp->token; @@ -711,6 +721,7 @@ int V3ParseImp::tokenToBison() { if (debug() >= 6 || debugFlex() >= 6 || debugBison() >= 6) { // --debugi-flex and --debugi-bison + if (debug() >= 10) dumpTokensAhead(__LINE__); cout << "tokenToBison " << yylval << endl; } return yylval.token; diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index c87e182a5..f4527f194 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -291,6 +291,7 @@ public: void parseFile(FileLine* fileline, const string& modfilename, bool inLibrary, const string& libname, const string& errmsg) VL_MT_DISABLED; void dumpInputsFile() VL_MT_DISABLED; + void dumpTokensAhead(int line) VL_MT_DISABLED; static void candidatePli(VSpellCheck* spellerp) VL_MT_DISABLED; private: