> On May 1, 2014, 8:08 p.m., Steve Reinhardt wrote:
> > Thanks!  Interesting idea to generate a class and then derive from it.  
> > Looks reasonable to me.
> > 
> > The comment called out below got me to wondering though... why did it 
> > already talk about wrapping the enum in a class/struct when the code was 
> > using a namespace?  I tracked the change down to this massive changeset of 
> > Nate's:
> > http://repo.gem5.org/gem5/rev/c94e103c83ad
> > 
> > which---without explanation---changed the original code, which used a 
> > struct:
> > http://repo.gem5.org/gem5/annotate/9f5df8033a44/src/python/m5/params.py#l569
> > to this namespace-based code:
> > http://repo.gem5.org/gem5/annotate/c94e103c83ad/src/python/m5/params.py#l652
> > 
> > So why was the change made?  Nate?  What was wrong with using structs to 
> > begin with?  Should we just go back to always using structs?  If we did, it 
> > would simplify the changes you had to make.
> > 
> > I'd be happy to play around with this a little myself, though sadly that 
> > won't happen all that soon...
> 
> Nathan Binkert wrote:
>     I'm honestly not sure.  I converted a lot of stuff in that changeset to 
> use the new enum stuff and it could be that the structs didn't seem to buy 
> much.  They just meant that you have to have longer names.  You can't have a 
> using directive on a struct, so you always had to write Foo::Bar and you 
> could never say Bar.  Why not just say Foo_Bar if you need to disambiguate.  
> All that said, it may have been a mistake to do that.
>     
>     If you do want better scoping, don't use the struct stuff from before 
> (i.e. don't do "struct Foo { enum { BAR }};") since it really is just a 
> longer name.  C++11 has a better way: strongly typed enumerations (a.k.a 
> "enum struct"). Where you'd say "enum struct Foo { BAR };".  Then each enum 
> is a different type and only its enum values can be used.
>     
>     http://en.wikipedia.org/wiki/C++11#Strongly_typed_enumerations
>     http://en.cppreference.com/w/cpp/language/enum. (the stuff about scoped 
> enumerations)

Thanks, Nate... the strongly typed enum stuff is new to me.  While the stronger 
type checking is nice, I don't see how it helps the naming issue.  According to 
http://en.cppreference.com/w/cpp/language/using_declaration, "Only the name 
explicitly mentioned in the using-declaration is transferred into the 
declarative scope: in particular, enumerators are not transferred when the 
enumeration type name is using-declared."

In contrast, Andrew figured out how to import the struct-declared flags into a 
class scope by using the struct as a base, something that doesn't appear to 
work with the "enum struct" definition.


- Steve


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviews.gem5.org/r/2254/#review5071
-----------------------------------------------------------


On May 1, 2014, 4:12 a.m., Andreas Hansson wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviews.gem5.org/r/2254/
> -----------------------------------------------------------
> 
> (Updated May 1, 2014, 4:12 a.m.)
> 
> 
> Review request for Default.
> 
> 
> Repository: gem5
> 
> 
> Description
> -------
> 
> Changeset 10204:cf938d8310b3
> ---------------------------
> cpu: Add flag name printing to StaticInst
> 
> This patch adds a the member function StaticInst::printFlags to allow all
> of an instruction's flags to be printed without using the individual
> is... member functions or resorting to exposing the 'flags' vector
> 
> It also replaces the enum definition StaticInst::Flags with a
> Python-generated enumeration and adds to the enum generation mechanism
> in src/python/m5/params.py to allow Enums to be placed in namespaces
> other than Enums or, alternatively, in wrapper structs allowing them to
> be inherited by other classes (so populating that class's name-space
> with the enumeration element names).
> 
> 
> Diffs
> -----
> 
>   src/cpu/SConscript e40b35147270 
>   src/cpu/StaticInstFlags.py PRE-CREATION 
>   src/cpu/static_inst.hh e40b35147270 
>   src/cpu/static_inst.cc e40b35147270 
>   src/python/m5/params.py e40b35147270 
> 
> Diff: http://reviews.gem5.org/r/2254/diff/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Andreas Hansson
> 
>

_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to