qinhailiang Posted January 23, 2014 Report Posted January 23, 2014 Hi, all //Case Oneclass BasePacket; int A;endclass : BasePacketclass My_Packet extends BasePacket; int C;endclass : My_Packetclass BaseTest;BasePacket PB[string];virtual function void Create_PKT(string s); PB = new();endfunction : Create_PKTvirtual function void Configure_PKT(string s); PB.A = 1;endfunction : Configure_PKTvirtual function void printP(string s); $display("BaseTest::PB[%s].A is %d", s, PB.A);endfunction : printPendclass : BaseTestclass My_Test extends BaseTest;virtual function void Create_PKT(string s); My_Packet MP = new(); PB = MP;endfunction : Create_PKTvirtual function void Configure_PKT(string s);// My_Packet mp; super.Configure_PKT(s); My_Packet mp; $cast(mp, PB); mp.C = 2; PB = mp;endfunction : Configure_PKTvirtual function void printP(string s);// My_Packet mp; super.printP(s); My_Packet mp; $cast(mp, PB); $display("My_test::PB[%s].C is %d", s, mp.C);endfunction : printPendclass : My_TestBaseTest T1 = new();My_Test T2 = new();initial begin T1.Create_PKT("StringBase"); T1.Configure_PKT("StringBase"); T1.printP("StringBase"); T2.Create_PKT("MY_String"); T2.Configure_PKT("MY_String"); T2.printP("MY_String");end//Output Information (Compiler Report Error)////near "mp": syntax error, unexpected IDENTIFIER, expecting #//Case Twoclass BasePacket; int A;endclass : BasePacketclass My_Packet extends BasePacket; int C;endclass : My_Packetclass BaseTest;BasePacket PB[string];virtual function void Create_PKT(string s); PB = new();endfunction : Create_PKTvirtual function void Configure_PKT(string s); PB.A = 1;endfunction : Configure_PKTvirtual function void printP(string s); $display("BaseTest::PB[%s].A is %d", s, PB.A);endfunction : printPendclass : BaseTestclass My_Test extends BaseTest;virtual function void Create_PKT(string s); My_Packet MP = new(); PB = MP;endfunction : Create_PKTvirtual function void Configure_PKT(string s); My_Packet mp; super.Configure_PKT(s); //My_Packet mp; $cast(mp, PB); mp.C = 2; PB = mp;endfunction : Configure_PKTvirtual function void printP(string s); My_Packet mp; super.printP(s); //My_Packet mp; $cast(mp, PB); $display("My_test::PB[%s].C is %d", s, mp.C);endfunction : printPendclass : My_TestBaseTest T1 = new();My_Test T2 = new();initial begin T1.Create_PKT("StringBase"); T1.Configure_PKT("StringBase"); T1.printP("StringBase"); T2.Create_PKT("MY_String"); T2.Configure_PKT("MY_String"); T2.printP("MY_String");end//Output Information////# BaseTest::PB[stringBase].A is 1//# BaseTest::PB[MY_String].A is 1//# My_test::PB[MY_String].C is 2 I designed two cases as above, ran case one, the simulator reported error as above. Would like to tell me the different of the declaration class handle before and after the super call? Thank you in advanced. BR QIN Quote
apfitch Posted January 23, 2014 Report Posted January 23, 2014 That's just because declarations need to be first in procedural code. Try this: virtual function void Configure_PKT(string s); // My_Packet mp; super.Configure_PKT(s); begin My_Packet mp; $cast(mp, PB[s]); mp.C = 2; PB[s] = mp; end endfunction : Configure_PKT virtual function void printP(string s); // My_Packet mp; super.printP(s); begin My_Packet mp; $cast(mp, PB[s]); $display("My_test::PB[%s].C is %d", s, mp.C); end endfunction : printP (note the extra begin/end to create a new scope) regards Alan Quote
qinhailiang Posted January 24, 2014 Author Report Posted January 24, 2014 Hi, Alan I modified the code as you said above, it worked well. Thank you for your value information. BR QIN Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.