Internals: Fix and enforce brace new constructors. No functional change intended.

This commit is contained in:
Wilson Snyder 2025-08-08 18:21:12 -04:00
parent 1eccfa64b5
commit 3ca1c9b6dd
8 changed files with 28 additions and 18 deletions

View File

@ -310,7 +310,7 @@ public:
delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle
return nullptr;
}
VerilatedRange* const rangep = new VerilatedRange(*m_iter);
VerilatedRange* const rangep = new VerilatedRange{*m_iter};
++m_iter;
return ((new VerilatedVpioRange{rangep})->castVpiHandle());
}

View File

@ -2116,7 +2116,7 @@ class ConstVisitor final : public VNVisitor {
= new AstVarRef{rhsp->fileline(), tempPurep, VAccess::WRITE};
AstNodeAssign* const asnp
= VN_IS(nodep, AssignDly)
? new AstAssign(nodep->fileline(), tempPureRefp, rhsp)
? new AstAssign{nodep->fileline(), tempPureRefp, rhsp}
: nodep->cloneType(tempPureRefp, rhsp);
nodep->addHereThisAsNext(asnp);
nodep->rhsp(new AstVarRef{rhsp->fileline(), tempPurep, VAccess::READ});

View File

@ -190,11 +190,11 @@ class DescopeVisitor final : public VNVisitor {
}
// Not really any way the user could do this, and we'd need
// to come up with some return value
// newfuncp->addStmtsp(new AstDisplay(newfuncp->fileline(),
// newfuncp->addStmtsp(new AstDisplay{newfuncp->fileline(),
// VDisplayType::DT_WARNING,
// "%%Error: "s+name+"() called with bad
// scope", nullptr));
// newfuncp->addStmtsp(new AstStop(newfuncp->fileline()));
// scope", nullptr});
// newfuncp->addStmtsp(new AstStop{newfuncp->fileline()});
UINFOTREE(9, newfuncp, "", "newfunc");
} else {
// Only a single function under this name, we can rename it

View File

@ -292,8 +292,8 @@ void V3HierBlock::writeParametersFile() const {
*of << "module " << moduleName << ";\n";
for (AstParamTypeDType* const gparam : m_params.gTypeParams()) {
AstTypedef* tdefp
= new AstTypedef(new FileLine{FileLine::builtInFilename()}, gparam->name(), nullptr,
VFlagChildDType{}, gparam->skipRefp()->cloneTreePure(true));
= new AstTypedef{new FileLine{FileLine::builtInFilename()}, gparam->name(), nullptr,
VFlagChildDType{}, gparam->skipRefp()->cloneTreePure(true)};
V3EmitV::verilogForTree(tdefp, *of);
VL_DO_DANGLING(tdefp->deleteTree(), tdefp);
}

View File

@ -550,7 +550,7 @@ private:
VAccess::READ};
rhsp->dtypep(rhsarrp->subDTypep()->skipRefp());
rhsp->classOrPackagep(rhsrefp->classOrPackagep());
AstAssign* const assignp = new AstAssign(nodep->fileline(), lhsp, rhsp);
AstAssign* const assignp = new AstAssign{nodep->fileline(), lhsp, rhsp};
nodep->addNextHere(assignp);
}
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);

View File

@ -238,7 +238,7 @@ public:
return strp;
}
string* newString(const char* text, size_t length) {
string* const strp = new string(text, length);
string* const strp = new string(text, length); // Need () constructor
m_stringps.push_back(strp);
return strp;
}

View File

@ -1205,7 +1205,7 @@ class CaptureVisitor final : public VNVisitor {
thisRefp->user1(true);
m_ignore.emplace(thisRefp);
AstMemberSel* const memberSelp
= new AstMemberSel(nodep->fileline(), thisRefp, nodep->varp());
= new AstMemberSel{nodep->fileline(), thisRefp, nodep->varp()};
memberSelp->user2p(m_targetp);
nodep->replaceWith(memberSelp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
@ -1259,7 +1259,7 @@ class CaptureVisitor final : public VNVisitor {
return;
}
AstVarRef* const varRefp
= new AstVarRef(nodep->fileline(), nodep->varp(), nodep->access());
= new AstVarRef{nodep->fileline(), nodep->varp(), nodep->access()};
fixupClassOrPackage(nodep->varp(), varRefp);
varRefp->user1(nodep->user1());
nodep->replaceWith(varRefp);

View File

@ -27,6 +27,7 @@ def get_source_files(root):
def check_pattern(filename, contents, pattern, not_pattern, message):
# Pattern uses match, so must include skipping leading whitespace if necessary
lineno = 0
buffer = "\n"
for line in contents.splitlines():
@ -36,9 +37,10 @@ def check_pattern(filename, contents, pattern, not_pattern, message):
# Build a buffer until a newline so we check a block at a time.
buffer += line + "\n"
continue
if re.search(r"\n" + pattern, buffer):
m = re.search(r"\n" + pattern, buffer)
if m:
if not not_pattern or not re.search(not_pattern, buffer):
test.error(filename + ":" + str(lineno) + ": " + message)
test.error_keep_going(filename + ":" + str(lineno) + ": " + message + m.group(0))
buffer = "\n"
@ -58,20 +60,28 @@ for filename in sorted(files.keys()):
contents = test.file_contents(filename) + "\n\n"
check_pattern(filename, contents, r"[^\']*virtual[^{};\n]+override", None,
check_pattern(filename, contents, r"[^\']*virtual[^{};\n]+override[^\n]*", None,
"'virtual' keyword is redundant on 'override' method")
check_pattern(filename, contents,
r' \s*(\w+ )*\s*(inline) [^;]+?\([^;]*?\)[^;]+?(?:{|:|=\s*default)', None,
"'inline' keyword is redundant on method definitions inside classes")
r' \s*(\w+ )*\s*(inline) [^;]+?\([^;]*?\)[^;]+?(?:{|:|=\s*default[^\n]*)',
None, "'inline' keyword is redundant on method definitions inside classes")
check_pattern(
filename, contents, r'inline \S+ [^;:(]+::[^;:(]+\([^;]*\)[^;]+{', r'template',
filename, contents, r'\s*inline \S+ [^;:(]+::[^;:(]+\([^;]*\)[^;]+{[^\n]*', r'template',
"Use 'inline' only on declaration inside classes"
" (except for template specializations)")
check_pattern(
filename,
contents,
r'.*[( ]new [a-zA-Z0-9]+\([^\n]*',
# Ignore common ok narrowing conversions, on int vs uint32_t arguments
r'(Need \(\) constructor|new AstArraySel|new AstConst|new AstRange)',
"Use brace instead of parenthesis-style constructors e.g. 'new ...{...}'")
if re.search(r'\.(c|cpp)', filename):
check_pattern(filename, contents, r'(\w+\s+)*(inline)', None,
check_pattern(filename, contents, r'(\w+\s+)*(inline)[^\n]*', None,
"'inline' keyword is on functions defined in .cpp files")
test.passes()