Internals: Misc parser cleanups.

This commit is contained in:
Wilson Snyder 2020-06-07 22:15:19 -04:00
parent 25397e7612
commit 7b7a2e99e3
3 changed files with 49 additions and 31 deletions

View File

@ -347,11 +347,13 @@ const V3ParseBisonYYSType* V3ParseImp::tokenPeekp(size_t depth) {
return &m_tokensAhead.at(depth); return &m_tokensAhead.at(depth);
} }
bool V3ParseImp::tokenPipeScanParam() { size_t V3ParseImp::tokenPipeScanParam(size_t depth) {
// Search around IEEE parameter_value_assignment to see if :: follows // Search around IEEE parameter_value_assignment to see if :: follows
if (tokenPeekp(0)->token != '#') return false; // Return location of following token, or input if not found
if (tokenPeekp(1)->token != '(') return false; // yaID [ '#(' ... ')' ]
int depth = 2; // Past the ( if (tokenPeekp(depth)->token != '#') return depth;
if (tokenPeekp(depth + 1)->token != '(') return depth;
depth += 2; // Past the (
int parens = 1; // Count first ( int parens = 1; // Count first (
while (true) { while (true) {
int tok = tokenPeekp(depth)->token; int tok = tokenPeekp(depth)->token;
@ -369,7 +371,7 @@ bool V3ParseImp::tokenPipeScanParam() {
} }
++depth; ++depth;
} }
return tokenPeekp(depth)->token == yP_COLONCOLON; return depth;
} }
void V3ParseImp::tokenPipeline() { void V3ParseImp::tokenPipeline() {
@ -463,7 +465,8 @@ void V3ParseImp::tokenPipeline() {
} else if (nexttok == '#') { } else if (nexttok == '#') {
V3ParseBisonYYSType curValue = yylval; // Remember value, as about to read ahead V3ParseBisonYYSType curValue = yylval; // Remember value, as about to read ahead
{ {
if (tokenPipeScanParam()) { token = yaID__CC; } size_t depth = tokenPipeScanParam(0);
if (tokenPeekp(depth)->token == yP_COLONCOLON) { token = yaID__CC; }
} }
yylval = curValue; yylval = curValue;
} }
@ -499,29 +502,36 @@ void V3ParseImp::tokenPipelineSym() {
AstNode* scp = foundp->nodep(); AstNode* scp = foundp->nodep();
yylval.scp = scp; yylval.scp = scp;
UINFO(7, " tokenPipelineSym: Found " << scp << endl); UINFO(7, " tokenPipelineSym: Found " << scp << endl);
if (VN_IS(scp, Typedef)) { if (token == yaID__LEX) { // i.e. not yaID__CC
token = (token == yaID__CC) ? yaID__CC : yaID__aTYPE; if (VN_IS(scp, Typedef)) {
} else if (VN_IS(scp, TypedefFwd)) { token = yaID__aTYPE;
token = (token == yaID__CC) ? yaID__CC : yaID__aTYPE; } else if (VN_IS(scp, TypedefFwd)) {
} else if (VN_IS(scp, Class)) { token = yaID__aTYPE;
token = (token == yaID__CC) ? yaID__CC : yaID__aTYPE; } else if (VN_IS(scp, Class)) {
} else if (VN_IS(scp, Package)) { token = yaID__aTYPE;
token = (token == yaID__CC) ? yaID__CC : yaID__ETC; } else if (VN_IS(scp, Package)) {
} else { token = yaID__ETC;
token = (token == yaID__CC) ? yaID__CC : yaID__ETC; } else {
token = yaID__ETC;
}
} }
} else { // Not found } else { // Not found
yylval.scp = NULL; yylval.scp = NULL;
token = (token == yaID__CC) ? yaID__CC : yaID__ETC;
if (token == yaID__CC) { if (token == yaID__CC) {
// We'll get a parser error eventually but might not be obvious // IEEE does require this, but we may relax this as UVM breaks it, so allow bbox
// is missing package, and this confuses people // for today
static int warned = false; if (!v3Global.opt.bboxUnsup()) {
if (!warned++) { // We'll get a parser error eventually but might not be obvious
yylval.fl->v3error( // is missing package, and this confuses people
"Package/class '" + *yylval.strp static int warned = false;
+ "' not found, and needs to be predeclared (IEEE 1800-2017 26.3)"); if (!warned++) {
yylval.fl->v3error(
"Package/class '" + *yylval.strp
+ "' not found, and needs to be predeclared (IEEE 1800-2017 26.3)");
}
} }
} else if (token == yaID__LEX) {
token = yaID__ETC;
} }
} }
} }
@ -548,8 +558,8 @@ std::ostream& operator<<(std::ostream& os, const V3ParseBisonYYSType& rhs) {
os << "TOKEN {" << rhs.fl->filenameLetters() << rhs.fl->asciiLineCol() << "}"; os << "TOKEN {" << rhs.fl->filenameLetters() << rhs.fl->asciiLineCol() << "}";
os << "=" << rhs.token << " " << V3ParseImp::tokenName(rhs.token); os << "=" << rhs.token << " " << V3ParseImp::tokenName(rhs.token);
if (rhs.token == yaID__ETC // if (rhs.token == yaID__ETC //
|| rhs.token == yaID__LEX //
|| rhs.token == yaID__CC // || rhs.token == yaID__CC //
|| rhs.token == yaID__LEX //
|| rhs.token == yaID__aTYPE) { || rhs.token == yaID__aTYPE) {
os << " strp='" << *(rhs.strp) << "'"; os << " strp='" << *(rhs.strp) << "'";
} }

View File

@ -274,7 +274,7 @@ private:
void tokenPull(); void tokenPull();
void tokenPipeline(); // Internal; called from tokenToBison void tokenPipeline(); // Internal; called from tokenToBison
void tokenPipelineSym(); void tokenPipelineSym();
bool tokenPipeScanParam(); size_t tokenPipeScanParam(size_t depth);
const V3ParseBisonYYSType* tokenPeekp(size_t depth); const V3ParseBisonYYSType* tokenPeekp(size_t depth);
void preprocDumps(std::ostream& os); void preprocDumps(std::ostream& os);
}; };

View File

@ -1112,7 +1112,7 @@ package_import_itemList<nodep>:
; ;
package_import_item<nodep>: // ==IEEE: package_import_item package_import_item<nodep>: // ==IEEE: package_import_item
yaID__CC/*package_identifier*/ yP_COLONCOLON package_import_itemObj idCC/*package_identifier*/ yP_COLONCOLON package_import_itemObj
{ {
if (!VN_CAST($<scp>1, Package)) { if (!VN_CAST($<scp>1, Package)) {
$$ = NULL; $$ = NULL;
@ -1139,7 +1139,7 @@ package_export_itemList<nodep>:
; ;
package_export_item<nodep>: // ==IEEE: package_export_item package_export_item<nodep>: // ==IEEE: package_export_item
yaID__CC yP_COLONCOLON package_import_itemObj idCC yP_COLONCOLON package_import_itemObj
{ $$ = new AstPackageExport($<fl>3, VN_CAST($<scp>1, Package), *$3); { $$ = new AstPackageExport($<fl>3, VN_CAST($<scp>1, Package), *$3);
SYMP->exportItem($<scp>1,*$3); } SYMP->exportItem($<scp>1,*$3); }
; ;
@ -2679,6 +2679,9 @@ etcInst<nodep>: // IEEE: module_instantiation + gate_instantiation + udp_insta
; ;
instDecl<nodep>: instDecl<nodep>:
// // Currently disambiguated from data_declaration based on
// // VARs being type, and cells non-type.
// // IEEE requires a '(' to disambiguate, we need TODO force this
id parameter_value_assignmentE {INSTPREP($<fl>1,*$1,$2);} instnameList ';' id parameter_value_assignmentE {INSTPREP($<fl>1,*$1,$2);} instnameList ';'
{ $$ = $4; GRAMMARP->m_impliedDecl=false; { $$ = $4; GRAMMARP->m_impliedDecl=false;
if (GRAMMARP->m_instParamp) { if (GRAMMARP->m_instParamp) {
@ -4686,6 +4689,11 @@ idType<strp>: // IEEE: class_identifier or other type identifier
yaID__aTYPE { $$ = $1; $<fl>$=$<fl>1; } yaID__aTYPE { $$ = $1; $<fl>$=$<fl>1; }
; ;
idCC<strp>: // IEEE: class/package then ::
// lexer matches this: yaID_LEX [ '#' '(' ... ')' ] yP_COLONCOLON
yaID__CC { $$ = $1; $<fl>$=$<fl>1; }
;
idRandomize<strp>: // Keyword as an identifier idRandomize<strp>: // Keyword as an identifier
yRANDOMIZE { static string s = "randomize"; $$ = &s; $<fl>$ = $<fl>1; } yRANDOMIZE { static string s = "randomize"; $$ = &s; $<fl>$ = $<fl>1; }
; ;
@ -5906,13 +5914,13 @@ packageClassScopeItem<packagep>: // IEEE: package_scope or [package_scope]::[cla
// // if not needed must use packageClassScopeNoId // // if not needed must use packageClassScopeNoId
// // IEEE: class_type: "id [ parameter_value_assignment ]" but allow yaID__aTYPE // // IEEE: class_type: "id [ parameter_value_assignment ]" but allow yaID__aTYPE
// //vv mid rule action needed otherwise we might not have NextId in time to parse the id token // //vv mid rule action needed otherwise we might not have NextId in time to parse the id token
yaID__CC idCC
/*mid*/ { SYMP->nextId($<scp>1); } /*mid*/ { SYMP->nextId($<scp>1); }
/*cont*/ yP_COLONCOLON /*cont*/ yP_COLONCOLON
{ $$ = VN_CAST($<scp>1, Package); } // UNSUP classes { $$ = VN_CAST($<scp>1, Package); } // UNSUP classes
// //
| yaID__CC parameter_value_assignment | idCC parameter_value_assignment
/*mid*/ { SYMP->nextId($<scp>1); } // Change next *after* we handle parameters, not before /*mid*/ { SYMP->nextId($<scp>1); } // Change next *after* we handle parameters, not before
/*cont*/ yP_COLONCOLON /*cont*/ yP_COLONCOLON
{ $$ = VN_CAST($<scp>1, Package); // UNSUP classes { $$ = VN_CAST($<scp>1, Package); // UNSUP classes
if ($2) BBUNSUP($2->fileline(), "Unsupported: Parameterized classes"); } if ($2) BBUNSUP($2->fileline(), "Unsupported: Parameterized classes"); }