Fix 'this' in extern functions.

This commit is contained in:
Wilson Snyder 2020-11-26 08:28:53 -05:00
parent ffbae97a3d
commit ad21f2e850
2 changed files with 20 additions and 12 deletions

View File

@ -2024,7 +2024,7 @@ private:
if (VN_IS(nodep->lhsp(), ParseRef) && nodep->lhsp()->name() == "this") { if (VN_IS(nodep->lhsp(), ParseRef) && nodep->lhsp()->name() == "this") {
VSymEnt* classSymp = m_ds.m_dotSymp; VSymEnt* classSymp = m_ds.m_dotSymp;
do { do {
classSymp = classSymp->fallbackp(); classSymp = classSymp->parentp();
} while (classSymp && !VN_IS(classSymp->nodep(), Class)); } while (classSymp && !VN_IS(classSymp->nodep(), Class));
m_ds.m_dotSymp = classSymp; m_ds.m_dotSymp = classSymp;
if (!classSymp) { if (!classSymp) {

View File

@ -4,22 +4,27 @@
// any use, without warranty, 2020 Rafal Kapuscik // any use, without warranty, 2020 Rafal Kapuscik
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
// //
class foo; class Cls;
bit [3:0] addr; bit [3:0] addr;
function void set (bit [3:0] addr); function void set(bit [3:0] addr);
begin : body begin : body
this.addr = addr; this.addr = addr;
end : body end : body
endfunction endfunction
extern function void setext(bit [3:0] addr);
endclass endclass
function void Cls::setext(bit [3:0] addr);
this.addr = addr;
endfunction
module t(/*AUTOARG*/ module t(/*AUTOARG*/
// Inputs // Inputs
clk clk
); );
input clk; input clk;
foo bar; Cls bar;
foo baz; Cls baz;
initial begin initial begin
bar = new(); bar = new();
baz = new(); baz = new();
@ -28,6 +33,9 @@ module t(/*AUTOARG*/
$display(bar.addr); $display(bar.addr);
$display(baz.addr); $display(baz.addr);
`endif `endif
if (bar.addr != 4) $stop;
bar.setext(2);
if (bar.addr != 2) $stop;
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end