Internals: Fix and enforce brace new constructors. No functional change intended.
This commit is contained in:
parent
1eccfa64b5
commit
3ca1c9b6dd
|
|
@ -310,7 +310,7 @@ public:
|
||||||
delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle
|
delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
VerilatedRange* const rangep = new VerilatedRange(*m_iter);
|
VerilatedRange* const rangep = new VerilatedRange{*m_iter};
|
||||||
++m_iter;
|
++m_iter;
|
||||||
return ((new VerilatedVpioRange{rangep})->castVpiHandle());
|
return ((new VerilatedVpioRange{rangep})->castVpiHandle());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2116,7 +2116,7 @@ class ConstVisitor final : public VNVisitor {
|
||||||
= new AstVarRef{rhsp->fileline(), tempPurep, VAccess::WRITE};
|
= new AstVarRef{rhsp->fileline(), tempPurep, VAccess::WRITE};
|
||||||
AstNodeAssign* const asnp
|
AstNodeAssign* const asnp
|
||||||
= VN_IS(nodep, AssignDly)
|
= VN_IS(nodep, AssignDly)
|
||||||
? new AstAssign(nodep->fileline(), tempPureRefp, rhsp)
|
? new AstAssign{nodep->fileline(), tempPureRefp, rhsp}
|
||||||
: nodep->cloneType(tempPureRefp, rhsp);
|
: nodep->cloneType(tempPureRefp, rhsp);
|
||||||
nodep->addHereThisAsNext(asnp);
|
nodep->addHereThisAsNext(asnp);
|
||||||
nodep->rhsp(new AstVarRef{rhsp->fileline(), tempPurep, VAccess::READ});
|
nodep->rhsp(new AstVarRef{rhsp->fileline(), tempPurep, VAccess::READ});
|
||||||
|
|
|
||||||
|
|
@ -190,11 +190,11 @@ class DescopeVisitor final : public VNVisitor {
|
||||||
}
|
}
|
||||||
// Not really any way the user could do this, and we'd need
|
// Not really any way the user could do this, and we'd need
|
||||||
// to come up with some return value
|
// to come up with some return value
|
||||||
// newfuncp->addStmtsp(new AstDisplay(newfuncp->fileline(),
|
// newfuncp->addStmtsp(new AstDisplay{newfuncp->fileline(),
|
||||||
// VDisplayType::DT_WARNING,
|
// VDisplayType::DT_WARNING,
|
||||||
// "%%Error: "s+name+"() called with bad
|
// "%%Error: "s+name+"() called with bad
|
||||||
// scope", nullptr));
|
// scope", nullptr});
|
||||||
// newfuncp->addStmtsp(new AstStop(newfuncp->fileline()));
|
// newfuncp->addStmtsp(new AstStop{newfuncp->fileline()});
|
||||||
UINFOTREE(9, newfuncp, "", "newfunc");
|
UINFOTREE(9, newfuncp, "", "newfunc");
|
||||||
} else {
|
} else {
|
||||||
// Only a single function under this name, we can rename it
|
// Only a single function under this name, we can rename it
|
||||||
|
|
|
||||||
|
|
@ -292,8 +292,8 @@ void V3HierBlock::writeParametersFile() const {
|
||||||
*of << "module " << moduleName << ";\n";
|
*of << "module " << moduleName << ";\n";
|
||||||
for (AstParamTypeDType* const gparam : m_params.gTypeParams()) {
|
for (AstParamTypeDType* const gparam : m_params.gTypeParams()) {
|
||||||
AstTypedef* tdefp
|
AstTypedef* tdefp
|
||||||
= new AstTypedef(new FileLine{FileLine::builtInFilename()}, gparam->name(), nullptr,
|
= new AstTypedef{new FileLine{FileLine::builtInFilename()}, gparam->name(), nullptr,
|
||||||
VFlagChildDType{}, gparam->skipRefp()->cloneTreePure(true));
|
VFlagChildDType{}, gparam->skipRefp()->cloneTreePure(true)};
|
||||||
V3EmitV::verilogForTree(tdefp, *of);
|
V3EmitV::verilogForTree(tdefp, *of);
|
||||||
VL_DO_DANGLING(tdefp->deleteTree(), tdefp);
|
VL_DO_DANGLING(tdefp->deleteTree(), tdefp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -550,7 +550,7 @@ private:
|
||||||
VAccess::READ};
|
VAccess::READ};
|
||||||
rhsp->dtypep(rhsarrp->subDTypep()->skipRefp());
|
rhsp->dtypep(rhsarrp->subDTypep()->skipRefp());
|
||||||
rhsp->classOrPackagep(rhsrefp->classOrPackagep());
|
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);
|
nodep->addNextHere(assignp);
|
||||||
}
|
}
|
||||||
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
|
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ public:
|
||||||
return strp;
|
return strp;
|
||||||
}
|
}
|
||||||
string* newString(const char* text, size_t length) {
|
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);
|
m_stringps.push_back(strp);
|
||||||
return strp;
|
return strp;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1205,7 +1205,7 @@ class CaptureVisitor final : public VNVisitor {
|
||||||
thisRefp->user1(true);
|
thisRefp->user1(true);
|
||||||
m_ignore.emplace(thisRefp);
|
m_ignore.emplace(thisRefp);
|
||||||
AstMemberSel* const memberSelp
|
AstMemberSel* const memberSelp
|
||||||
= new AstMemberSel(nodep->fileline(), thisRefp, nodep->varp());
|
= new AstMemberSel{nodep->fileline(), thisRefp, nodep->varp()};
|
||||||
memberSelp->user2p(m_targetp);
|
memberSelp->user2p(m_targetp);
|
||||||
nodep->replaceWith(memberSelp);
|
nodep->replaceWith(memberSelp);
|
||||||
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
||||||
|
|
@ -1259,7 +1259,7 @@ class CaptureVisitor final : public VNVisitor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AstVarRef* const varRefp
|
AstVarRef* const varRefp
|
||||||
= new AstVarRef(nodep->fileline(), nodep->varp(), nodep->access());
|
= new AstVarRef{nodep->fileline(), nodep->varp(), nodep->access()};
|
||||||
fixupClassOrPackage(nodep->varp(), varRefp);
|
fixupClassOrPackage(nodep->varp(), varRefp);
|
||||||
varRefp->user1(nodep->user1());
|
varRefp->user1(nodep->user1());
|
||||||
nodep->replaceWith(varRefp);
|
nodep->replaceWith(varRefp);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ def get_source_files(root):
|
||||||
|
|
||||||
|
|
||||||
def check_pattern(filename, contents, pattern, not_pattern, message):
|
def check_pattern(filename, contents, pattern, not_pattern, message):
|
||||||
|
# Pattern uses match, so must include skipping leading whitespace if necessary
|
||||||
lineno = 0
|
lineno = 0
|
||||||
buffer = "\n"
|
buffer = "\n"
|
||||||
for line in contents.splitlines():
|
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.
|
# Build a buffer until a newline so we check a block at a time.
|
||||||
buffer += line + "\n"
|
buffer += line + "\n"
|
||||||
continue
|
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):
|
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"
|
buffer = "\n"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -58,20 +60,28 @@ for filename in sorted(files.keys()):
|
||||||
|
|
||||||
contents = test.file_contents(filename) + "\n\n"
|
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")
|
"'virtual' keyword is redundant on 'override' method")
|
||||||
|
|
||||||
check_pattern(filename, contents,
|
check_pattern(filename, contents,
|
||||||
r' \s*(\w+ )*\s*(inline) [^;]+?\([^;]*?\)[^;]+?(?:{|:|=\s*default)', None,
|
r' \s*(\w+ )*\s*(inline) [^;]+?\([^;]*?\)[^;]+?(?:{|:|=\s*default[^\n]*)',
|
||||||
"'inline' keyword is redundant on method definitions inside classes")
|
None, "'inline' keyword is redundant on method definitions inside classes")
|
||||||
|
|
||||||
check_pattern(
|
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"
|
"Use 'inline' only on declaration inside classes"
|
||||||
" (except for template specializations)")
|
" (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):
|
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")
|
"'inline' keyword is on functions defined in .cpp files")
|
||||||
|
|
||||||
test.passes()
|
test.passes()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue