Internals: Defer $unit package resolution until link

This commit is contained in:
Wilson Snyder 2024-11-10 18:27:14 -05:00
parent c3b2bfbc39
commit b71d49e55a
2 changed files with 8 additions and 1 deletions

View File

@ -1011,6 +1011,12 @@ class LinkDotFindVisitor final : public VNVisitor {
if (!m_explicitNew && m_statep->forPrimary()) makeImplicitNew(nodep);
}
}
void visit(AstClassOrPackageRef* nodep) override {
if (!nodep->classOrPackageNodep() && nodep->name() == "$unit") {
nodep->classOrPackageNodep(v3Global.rootp()->dollarUnitPkgAddp());
}
iterateChildren(nodep);
}
void visit(AstScope* nodep) override {
UASSERT_OBJ(m_statep->forScopeCreation(), nodep,
"Scopes should only exist right after V3Scope");
@ -3806,6 +3812,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
if (AstClassOrPackageRef* lookNodep = VN_CAST(dotp->lhsp(), ClassOrPackageRef)) {
iterate(lookNodep);
cprp = dotp->rhsp();
UASSERT_OBJ(lookNodep->classOrPackagep(), nodep, "Bad package link");
lookSymp = m_statep->getNodeSym(lookNodep->classOrPackagep());
} else {
dotp->lhsp()->v3error("Attempting to extend" // LCOV_EXCL_LINE

View File

@ -7307,7 +7307,7 @@ dollarUnitNextId<nodeExprp>: // $unit
// // if not needed must use packageClassScopeNoId
// // Must call nextId without any additional tokens following
yD_UNIT
{ $$ = new AstClassOrPackageRef{$1, "$unit", PARSEP->unitPackage($<fl>1), nullptr};
{ $$ = new AstClassOrPackageRef{$1, "$unit", nullptr, nullptr};
SYMP->nextId(PARSEP->rootp()); }
;