Re: [gem5-dev] Query on inheritance and virtual functions

2011-06-08 Thread Jack Harvard


On 8 Jun 2011, at 19:09, Nilay Vaish wrote:

 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 When you declare your function private, you can't use instance.function() to 
 access it. Is it generating a compile time error?
 
 On 8 Jun 2011, at 00:31, Nilay Vaish wrote:
 
 Consider the following class declarations --
 
 class A
 {
 public:
   virtual void function() = 0;
 };
 
 class B : public A
 {
 private:
   void function();
 }
 
 int main()
 {
 B b;
 b.function();
 }
 
 Will this code compile correctly?
 
 --
 Nilay
 
 I should say that my example program was not what I intended it to be. The 
 main function should look like --
 
 int main()
 {
  B* b = new B();
  A* a = b;
  a-function();
  return 0;
 }
 
 Now what would happen?

This compiles. However, if you do b-function(), you would get the same error 
as your last example, due to the same reason.





___
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev


Re: [gem5-dev] Query on inheritance and virtual functions

2011-06-08 Thread Jack Harvard

On 8 Jun 2011, at 23:28, Nilay Vaish wrote:

 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 
 
 On 8 Jun 2011, at 19:09, Nilay Vaish wrote:
 
 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 When you declare your function private, you can't use instance.function() 
 to access it. Is it generating a compile time error?
 
 On 8 Jun 2011, at 00:31, Nilay Vaish wrote:
 
 Consider the following class declarations --
 
 class A
 {
 public:
  virtual void function() = 0;
 };
 
 class B : public A
 {
 private:
  void function();
 }
 
 int main()
 {
 B b;
 b.function();
 }
 
 Will this code compile correctly?
 
 --
 Nilay
 
 I should say that my example program was not what I intended it to be. The 
 main function should look like --
 
 int main()
 {
 B* b = new B();
 A* a = b;
 a-function();
 return 0;
 }
 
 Now what would happen?
 
 This compiles. However, if you do b-function(), you would get the same 
 error as your last example, due to the same reason.
 
 
 It compiles and executes fine. What surprises me is that even though 
 function() is private for class B, still it gets invoked using the pointer 
 from class A. I was not aware of this before.

Overriding and access visibility is orthogonal, you use class A pointer to 
access its public function.   

___
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev


Re: [gem5-dev] Query on inheritance and virtual functions

2011-06-08 Thread Jack Harvard

On 9 Jun 2011, at 00:10, Nilay Vaish wrote:

 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 
 On 8 Jun 2011, at 23:28, Nilay Vaish wrote:
 
 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 
 
 On 8 Jun 2011, at 19:09, Nilay Vaish wrote:
 
 On Wed, 8 Jun 2011, Jack Harvard wrote:
 
 When you declare your function private, you can't use 
 instance.function() to access it. Is it generating a compile time error?
 
 On 8 Jun 2011, at 00:31, Nilay Vaish wrote:
 
 Consider the following class declarations --
 
 class A
 {
 public:
 virtual void function() = 0;
 };
 
 class B : public A
 {
 private:
 void function();
 }
 
 int main()
 {
 B b;
 b.function();
 }
 
 Will this code compile correctly?
 
 --
 Nilay
 
 I should say that my example program was not what I intended it to be. 
 The main function should look like --
 
 int main()
 {
 B* b = new B();
 A* a = b;
 a-function();
 return 0;
 }
 
 Now what would happen?
 
 This compiles. However, if you do b-function(), you would get the same 
 error as your last example, due to the same reason.
 
 
 It compiles and executes fine. What surprises me is that even though 
 function() is private for class B, still it gets invoked using the pointer 
 from class A. I was not aware of this before.
 
 Overriding and access visibility is orthogonal, you use class A pointer to 
 access its public function.
 
 I won't term this is a overriding, the function that will be called would be 
 the one defined in class B, as 'function()' is a virtual member of class A. 
 But then, 'function()' is private to class B, so I would expect some error to 
 occur. I think the reason is that visibility is tested only at compile time 
 and never at run time.

It's still overriding for the function() defined in B which is overriding the 
function defined in base class A (whether it's defined as virtual or pure 
virtual). In C++ it's allowed to override with a private member. That means you
can only call it via a pointer or reference to the base. This is occasionally 
useful (eg if the base is a private one), but it isn't very common in my 
experience.

(A long, long time ago there were rules in C++ like those in Java to
prevent derived classes reducing the visibility of members. They were
abandoned because they got in the way of reasonable code.)

___
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev


Re: [gem5-dev] Query on inheritance and virtual functions

2011-06-07 Thread Jack Harvard
When you declare your function private, you can't use instance.function() to 
access it. Is it generating a compile time error?

On 8 Jun 2011, at 00:31, Nilay Vaish wrote:

 Consider the following class declarations --
 
 class A
 {
  public:
virtual void function() = 0;
 };
 
 class B : public A
 {
  private:
void function();
 }
 
 int main()
 {
  B b;
  b.function();
 }
 
 Will this code compile correctly?
 
 --
 Nilay
 ___
 gem5-dev mailing list
 gem5-dev@m5sim.org
 http://m5sim.org/mailman/listinfo/gem5-dev

___
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev


Re: [gem5-dev] changeset in m5: scons: rename TraceFlags to DebugFlags

2011-06-07 Thread Jack Harvard
Why not just let TraceFlags be interpreted as DebugFlags, so TraceFlags still 
works for users.

On 3 Jun 2011, at 02:08, Nathan Binkert wrote:

 changeset 9228e00459d4 in /z/repo/m5
 details: http://repo.m5sim.org/m5?cmd=changeset;node=9228e00459d4
 description:
   scons: rename TraceFlags to DebugFlags
 
 diffstat:
 
 src/SConscript  |   2 -
 src/arch/SConscript |   6 +-
 src/arch/arm/SConscript |   8 ++--
 src/arch/mips/SConscript|   2 +-
 src/arch/power/SConscript   |   2 +-
 src/arch/sparc/SConscript   |   4 +-
 src/arch/x86/SConscript |  10 +++---
 src/base/SConscript |  24 +++---
 src/base/vnc/SConscript |   2 +-
 src/cpu/SConscript  |  54 
 src/cpu/inorder/SConscript  |  44 +-
 src/cpu/o3/SConscript   |  24 +++---
 src/cpu/ozone/SConscript|  10 +++---
 src/cpu/pred/SConscript |   2 +-
 src/cpu/simple/SConscript   |   2 +-
 src/cpu/testers/directedtest/SConscript |   2 +-
 src/cpu/testers/memtest/SConscript  |   2 +-
 src/cpu/testers/networktest/SConscript  |   2 +-
 src/cpu/testers/rubytest/SConscript |   2 +-
 src/dev/SConscript  |  50 +++---
 src/dev/alpha/SConscript|   4 +-
 src/dev/arm/SConscript  |   8 ++--
 src/dev/mips/SConscript |   2 +-
 src/dev/sparc/SConscript|   2 +-
 src/dev/x86/SConscript  |  16 
 src/kern/SConscript |   6 +-
 src/mem/SConscript  |  34 ++--
 src/mem/cache/SConscript|   8 ++--
 src/mem/cache/tags/SConscript   |   4 +-
 src/sim/SConscript  |  34 ++--
 30 files changed, 185 insertions(+), 187 deletions(-)
 
 diffs (truncated from 687 to 300 lines):
 
 diff -r 483e936f44f0 -r 9228e00459d4 src/SConscript
 --- a/src/SConscript  Thu Jun 02 17:36:18 2011 -0700
 +++ b/src/SConscript  Thu Jun 02 17:36:21 2011 -0700
 @@ -270,7 +270,6 @@
 if name in debug_flags:
 raise AttributeError, Flag %s already specified % name
 debug_flags[name] = (name, (), desc)
 -TraceFlag = DebugFlag
 
 def CompoundFlag(name, flags, desc=None):
 if name in debug_flags:
 @@ -280,7 +279,6 @@
 debug_flags[name] = (name, compound, desc)
 
 Export('DebugFlag')
 -Export('TraceFlag')
 Export('CompoundFlag')
 
 
 diff -r 483e936f44f0 -r 9228e00459d4 src/arch/SConscript
 --- a/src/arch/SConscript Thu Jun 02 17:36:18 2011 -0700
 +++ b/src/arch/SConscript Thu Jun 02 17:36:21 2011 -0700
 @@ -126,7 +126,7 @@
 
 env.Append(BUILDERS = { 'ISADesc' : isa_desc_builder })
 
 -TraceFlag('IntRegs')
 -TraceFlag('FloatRegs')
 -TraceFlag('MiscRegs')
 +DebugFlag('IntRegs')
 +DebugFlag('FloatRegs')
 +DebugFlag('MiscRegs')
 CompoundFlag('Registers', [ 'IntRegs', 'FloatRegs', 'MiscRegs' ])
 diff -r 483e936f44f0 -r 9228e00459d4 src/arch/arm/SConscript
 --- a/src/arch/arm/SConscript Thu Jun 02 17:36:18 2011 -0700
 +++ b/src/arch/arm/SConscript Thu Jun 02 17:36:21 2011 -0700
 @@ -65,10 +65,10 @@
 SimObject('ArmNativeTrace.py')
 SimObject('ArmTLB.py')
 
 -TraceFlag('Arm')
 -TraceFlag('TLBVerbose')
 -TraceFlag('Faults', Trace Exceptions, interrupts, svc/swi)
 -TraceFlag('Predecoder', Instructions returned by the predecoder)
 +DebugFlag('Arm')
 +DebugFlag('TLBVerbose')
 +DebugFlag('Faults', Trace Exceptions, interrupts, svc/swi)
 +DebugFlag('Predecoder', Instructions returned by the predecoder)
 if env['FULL_SYSTEM']:
 Source('interrupts.cc')
 Source('stacktrace.cc')
 diff -r 483e936f44f0 -r 9228e00459d4 src/arch/mips/SConscript
 --- a/src/arch/mips/SConscriptThu Jun 02 17:36:18 2011 -0700
 +++ b/src/arch/mips/SConscriptThu Jun 02 17:36:21 2011 -0700
 @@ -41,7 +41,7 @@
 Source('dsp.cc')
 
 SimObject('MipsTLB.py')
 -TraceFlag('MipsPRA')
 +DebugFlag('MipsPRA')
 
 if env['FULL_SYSTEM']:
 SimObject('MipsSystem.py')
 diff -r 483e936f44f0 -r 9228e00459d4 src/arch/power/SConscript
 --- a/src/arch/power/SConscript   Thu Jun 02 17:36:18 2011 -0700
 +++ b/src/arch/power/SConscript   Thu Jun 02 17:36:21 2011 -0700
 @@ -45,7 +45,7 @@
 Source('utility.cc')
 
 SimObject('PowerTLB.py')
 -TraceFlag('Power')
 +DebugFlag('Power')
 
 if not env['FULL_SYSTEM']:
 Source('process.cc')
 diff -r 483e936f44f0 -r 9228e00459d4 src/arch/sparc/SConscript
 --- a/src/arch/sparc/SConscript   Thu Jun 02 17:36:18 2011 -0700
 +++ b/src/arch/sparc/SConscript   Thu Jun 02 17:36:21 2011 -0700
 @@ -44,8 +44,8 @@
 SimObject('SparcNativeTrace.py')
 
 

Re: [gem5-dev] [m5-dev] Review Request: stats: move code that loops over all stats into python

2011-06-06 Thread Jack Harvard

On 12 May 2011, at 04:24, Nathan Binkert wrote:

 
 ---
 This is an automatically generated e-mail. To reply, visit:
 http://reviews.m5sim.org/r/690/#review1226
 ---
 
 
 I guess I should have said something, but there are several more diffs to 
 come down the road.  I just wanted to get some out of the way now.  By the 
 end, there will be no output code in C++ at all.
 
 
 src/python/m5/stats/__init__.py
 http://reviews.m5sim.org/r/690/#comment1691
 
  If you have a periodic dumping of stats because of an event and you get a 
 dumpstats from an m5op or from kill -USR1, you don't want to dump twice in 
 the same cycle because stuff just doesn't work well.
 

Where in the code is the signal from kill -USR1 handled to dump stats?

 - Nathan
 
 
 On 2011-05-10 06:08:36, Nathan Binkert wrote:
 
 ---
 This is an automatically generated e-mail. To reply, visit:
 http://reviews.m5sim.org/r/690/
 ---
 
 (Updated 2011-05-10 06:08:36)
 
 
 Review request for Default, Ali Saidi, Gabe Black, Steve Reinhardt, and 
 Nathan Binkert.
 
 
 Summary
 ---
 
 stats: move code that loops over all stats into python
 
 
 Diffs
 -
 
 src/base/SConscript 44f8c2507d85 
 src/base/statistics.hh 44f8c2507d85 
 src/base/statistics.cc 44f8c2507d85 
 src/base/stats/info.hh 44f8c2507d85 
 src/base/stats/mysql.hh 44f8c2507d85 
 src/base/stats/mysql.cc 44f8c2507d85 
 src/base/stats/output.hh 44f8c2507d85 
 src/base/stats/output.cc 44f8c2507d85 
 src/base/stats/text.hh 44f8c2507d85 
 src/base/stats/text.cc 44f8c2507d85 
 src/base/stats/visit.hh 44f8c2507d85 
 src/base/stats/visit.cc 44f8c2507d85 
 src/python/m5/simulate.py 44f8c2507d85 
 src/python/m5/stats/__init__.py PRE-CREATION 
 src/python/swig/stats.i 44f8c2507d85 
 
 Diff: http://reviews.m5sim.org/r/690/diff
 
 
 Testing
 ---
 
 quick regressions pass (though most recently run with review 689 and 691)
 
 
 Thanks,
 
 Nathan
 
 
 
 ___
 m5-dev mailing list
 m5-...@m5sim.org
 http://m5sim.org/mailman/listinfo/m5-dev

___
gem5-dev mailing list
gem5-dev@m5sim.org
http://m5sim.org/mailman/listinfo/gem5-dev