Fix constructor-parameter argument comma-separation in C++ (#3162)

This commit is contained in:
Matthew Ballance 2021-10-09 16:19:31 -07:00 committed by GitHub
parent 5f597dd9fc
commit a9646cf45c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -392,10 +392,15 @@ public:
emitCCallArgs(nodep, "");
}
virtual void visit(AstCNew* nodep) override {
bool comma = false;
puts("std::make_shared<" + prefixNameProtect(nodep->dtypep()) + ">(");
puts("vlSymsp"); // TODO make this part of argsp, and eliminate when unnecessary
if (nodep->argsp()) puts(", ");
iterateAndNextNull(nodep->argsp());
if (nodep->argsp()) comma = true;
for (AstNode* subnodep = nodep->argsp(); subnodep; subnodep = subnodep->nextp()) {
if (comma) puts(", ");
iterate(subnodep);
comma = true;
}
puts(")");
}
virtual void visit(AstCMethodHard* nodep) override {

View File

@ -26,10 +26,20 @@ class ClsArg;
endfunction
endclass
class Cls2Arg;
int imembera;
int imemberb;
function new(int i, int j);
imembera = i + 1;
imemberb = j + 2;
endfunction
endclass
module t (/*AUTOARG*/);
initial begin
ClsNoArg c1;
ClsArg c2;
ClsArg c2;
Cls2Arg c3;
c1 = new;
if (c1.imembera != 5) $stop;
@ -42,6 +52,10 @@ module t (/*AUTOARG*/);
if (c2.imembera != 6) $stop;
if (c2.geta() != 6) $stop;
c3 = new(4, 5);
if (c3.imembera != 5) $stop;
if (c3.imemberb != 7) $stop;
$write("*-* All Finished *-*\n");
$finish;
end