changeset 81328f5e764a in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=81328f5e764a
description:
sim: allow SimObject subclasses to define classmethods
(without requiring a leading underscore)
Also a little cleanup on type names in SimObject.py.
diffstat:
src/python/m5/SimObject.py | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
diffs (57 lines):
diff -r acc1fbbef239 -r 81328f5e764a src/python/m5/SimObject.py
--- a/src/python/m5/SimObject.py Mon Jul 05 21:39:38 2010 -0700
+++ b/src/python/m5/SimObject.py Mon Jul 05 21:39:38 2010 -0700
@@ -29,7 +29,7 @@
import math
import sys
-import types
+from types import FunctionType
try:
import pydot
@@ -102,15 +102,15 @@
# class are instantiated, and provides inherited instance behavior).
class MetaSimObject(type):
# Attributes that can be set only at initialization time
- init_keywords = { 'abstract' : types.BooleanType,
- 'cxx_class' : types.StringType,
- 'cxx_type' : types.StringType,
- 'cxx_predecls' : types.ListType,
- 'swig_objdecls' : types.ListType,
- 'swig_predecls' : types.ListType,
- 'type' : types.StringType }
+ init_keywords = { 'abstract' : bool,
+ 'cxx_class' : str,
+ 'cxx_type' : str,
+ 'cxx_predecls' : list,
+ 'swig_objdecls' : list,
+ 'swig_predecls' : list,
+ 'type' : str }
# Attributes that can be set any time
- keywords = { 'check' : types.FunctionType }
+ keywords = { 'check' : FunctionType }
# __new__ is called before __init__, and is where the statements
# in the body of the class definition get loaded into the class's
@@ -126,8 +126,9 @@
cls_dict = {}
value_dict = {}
for key,val in dict.items():
- if key.startswith('_') or isinstance(val, (types.FunctionType,
- types.TypeType)):
+ if key.startswith('_') or isinstance(val, (FunctionType,
+ classmethod,
+ type)):
cls_dict[key] = val
else:
# must be a param/port setting
@@ -233,7 +234,7 @@
if not isinstance(val, kwtype):
raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
(keyword, type(val), kwtype)
- if isinstance(val, types.FunctionType):
+ if isinstance(val, FunctionType):
val = classmethod(val)
type.__setattr__(cls, keyword, val)
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev