Add elaboration dot-error message context, plus debug improvements

This commit is contained in:
Wilson Snyder 2024-10-04 05:38:05 -04:00
parent 8638e46cb7
commit d06f986b51
2 changed files with 31 additions and 11 deletions

View File

@ -2175,14 +2175,17 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
string ascii() const {
static const char* const names[]
= {"NONE", "PACKAGE", "FIRST", "SCOPE", "FINAL", "MEMBER"};
= {"DP_NONE", "DP_PACKAGE", "DP_FIRST", "DP_SCOPE", "DP_FINAL", "DP_MEMBER"};
std::ostringstream sstr;
sstr << "ds=" << names[m_dotPos];
sstr << " dse" << cvtToHex(m_dotSymp);
sstr << " sup=" << m_super;
sstr << "(" << m_dotSymp->nodep()->typeName() << ")";
if (m_dotErr) sstr << " [dotErr]";
if (m_super) sstr << " [super]";
if (m_unresolvedCell) sstr << " [unrCell]";
if (m_unresolvedClass) sstr << " [unrClass]";
sstr << " txt=" << m_dotText;
sstr << " unrCell=" << m_unresolvedCell;
sstr << " unrClass=" << m_unresolvedClass;
return sstr.str();
}
} m_ds; // State to preserve across recursions
@ -2265,9 +2268,12 @@ class LinkDotResolveVisitor final : public VNVisitor {
void checkNoDot(AstNode* nodep) {
if (VL_UNLIKELY(m_ds.m_dotPos != DP_NONE)) {
// UINFO(9, indent() << "ds=" << m_ds.ascii() << endl);
nodep->v3error("Syntax error: Not expecting " << nodep->type() << " under a "
<< nodep->backp()->type()
<< " in dotted expression");
nodep->v3error("Syntax error: Not expecting "
<< nodep->type() << " under a " << nodep->backp()->type()
<< " in dotted expression\n"
<< nodep->warnContextPrimary() << m_ds.m_dotp->warnOther()
<< "... Resolving this reference\n"
<< m_ds.m_dotp->warnContextSecondary());
m_ds.m_dotErr = true;
}
}
@ -2440,6 +2446,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
void visit(AstCell* nodep) override {
// Cell: Recurse inside or cleanup not founds
LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl);
checkNoDot(nodep);
VL_RESTORER(m_usedPins);
m_usedPins.clear();
@ -2459,7 +2466,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
// instantiator's symbols
else {
m_pinSymp = m_statep->getNodeSym(nodep->modp());
UINFO(4, indent() << "(Backto) Link Cell: " << nodep << endl);
UINFO(4, indent() << "(Backto) visit " << nodep << endl);
// if (debug()) nodep->dumpTree("- linkcell: ");
// if (debug()) nodep->modp()->dumpTree("- linkcemd: ");
iterateChildren(nodep);
@ -2471,6 +2478,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
void visit(AstClassRefDType* nodep) override {
// Cell: Recurse inside or cleanup not founds
LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl);
checkNoDot(nodep);
VL_RESTORER(m_usedPins);
m_usedPins.clear();
@ -2481,7 +2489,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
{
// ClassRef's have pins, so track
m_pinSymp = m_statep->getNodeSym(nodep->classp());
UINFO(4, indent() << "(Backto) Link ClassRefDType: " << nodep << endl);
UINFO(4, indent() << "(Backto) visit " << nodep << endl);
// if (debug()) nodep->dumpTree("- linkcell: ");
// if (debug()) nodep->modp()->dumpTree("- linkcemd: ");
iterateChildren(nodep);
@ -2692,7 +2700,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
if (start) {
m_ds.init(m_curSymp);
// Note m_ds.m_dot remains nullptr; this is a reference not under a dot
// Note m_ds.m_dotp remains nullptr; this is a reference not under a dot
}
if (nodep->name() == "super") {
nodep->v3warn(E_UNSUPPORTED, "Unsupported: super");
@ -2720,7 +2728,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
// m_ds.dotp->lhsp() was checked to know if `index` is directly after lambda arg ref.
// If not, treat it as normal member select
iterateChildren(nodep);
const auto newp = new AstLambdaArgRef{
AstLambdaArgRef* const newp = new AstLambdaArgRef{
nodep->fileline(), m_ds.m_dotp->lhsp()->name() + "__DOT__index", true};
nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
@ -3286,6 +3294,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
void visit(AstMethodCall* nodep) override {
// Created here so should already be resolved.
LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl);
VL_RESTORER(m_ds);
VL_RESTORER(m_fromSymp);
VL_RESTORER(m_randMethodCallp);
@ -3931,6 +3940,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
// Resolve its reference
if (nodep->user3SetOnce()) return;
LINKDOT_VISIT_START();
UINFO(5, indent() << "visit " << nodep << endl);
if (AstNode* const cpackagep = nodep->classOrPackageOpp()) {
if (AstClassOrPackageRef* const cpackagerefp = VN_CAST(cpackagep, ClassOrPackageRef)) {
const AstClass* const clsp = VN_CAST(cpackagerefp->classOrPackageNodep(), Class);
@ -4081,6 +4091,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
void visit(AstIfaceRefDType* nodep) override {
if (nodep->user3SetOnce()) return;
LINKDOT_VISIT_START();
if (nodep->paramsp()) {
// If there is no parameters, there is no need to visit this node.

View File

@ -1,12 +1,21 @@
%Error: t/t_concat_link_bad.v:13:20: Syntax error: Not expecting REPLICATE under a DOT in dotted expression
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
t/t_concat_link_bad.v:13:34: ... Resolving this reference
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
%Error: t/t_concat_link_bad.v:13:26: Syntax error: Not expecting CONCAT under a REPLICATE in dotted expression
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
t/t_concat_link_bad.v:13:34: ... Resolving this reference
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
%Error: t/t_concat_link_bad.v:13:20: Syntax error: Not expecting CONST under a REPLICATE in dotted expression
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
t/t_concat_link_bad.v:13:34: ... Resolving this reference
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^
%Warning-IMPLICIT: t/t_concat_link_bad.v:13:12: Signal definition not found, creating implicitly: 'bar_s'
13 | assign bar_s = {foo_s, foo_s}.f1;
| ^~~~~