sim: allow SimObject subclasses to define classmethods
(without requiring a leading underscore) Also a little cleanup on type names in SimObject.py.
This commit is contained in:
parent
30ce620d1d
commit
387cbffb7a
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
import types
|
from types import FunctionType
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pydot
|
import pydot
|
||||||
|
@ -102,15 +102,15 @@ instanceDict = {}
|
||||||
# class are instantiated, and provides inherited instance behavior).
|
# class are instantiated, and provides inherited instance behavior).
|
||||||
class MetaSimObject(type):
|
class MetaSimObject(type):
|
||||||
# Attributes that can be set only at initialization time
|
# Attributes that can be set only at initialization time
|
||||||
init_keywords = { 'abstract' : types.BooleanType,
|
init_keywords = { 'abstract' : bool,
|
||||||
'cxx_class' : types.StringType,
|
'cxx_class' : str,
|
||||||
'cxx_type' : types.StringType,
|
'cxx_type' : str,
|
||||||
'cxx_predecls' : types.ListType,
|
'cxx_predecls' : list,
|
||||||
'swig_objdecls' : types.ListType,
|
'swig_objdecls' : list,
|
||||||
'swig_predecls' : types.ListType,
|
'swig_predecls' : list,
|
||||||
'type' : types.StringType }
|
'type' : str }
|
||||||
# Attributes that can be set any time
|
# Attributes that can be set any time
|
||||||
keywords = { 'check' : types.FunctionType }
|
keywords = { 'check' : FunctionType }
|
||||||
|
|
||||||
# __new__ is called before __init__, and is where the statements
|
# __new__ is called before __init__, and is where the statements
|
||||||
# in the body of the class definition get loaded into the class's
|
# in the body of the class definition get loaded into the class's
|
||||||
|
@ -126,8 +126,9 @@ class MetaSimObject(type):
|
||||||
cls_dict = {}
|
cls_dict = {}
|
||||||
value_dict = {}
|
value_dict = {}
|
||||||
for key,val in dict.items():
|
for key,val in dict.items():
|
||||||
if key.startswith('_') or isinstance(val, (types.FunctionType,
|
if key.startswith('_') or isinstance(val, (FunctionType,
|
||||||
types.TypeType)):
|
classmethod,
|
||||||
|
type)):
|
||||||
cls_dict[key] = val
|
cls_dict[key] = val
|
||||||
else:
|
else:
|
||||||
# must be a param/port setting
|
# must be a param/port setting
|
||||||
|
@ -233,7 +234,7 @@ class MetaSimObject(type):
|
||||||
if not isinstance(val, kwtype):
|
if not isinstance(val, kwtype):
|
||||||
raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
|
raise TypeError, 'keyword %s has bad type %s (expecting %s)' % \
|
||||||
(keyword, type(val), kwtype)
|
(keyword, type(val), kwtype)
|
||||||
if isinstance(val, types.FunctionType):
|
if isinstance(val, FunctionType):
|
||||||
val = classmethod(val)
|
val = classmethod(val)
|
||||||
type.__setattr__(cls, keyword, val)
|
type.__setattr__(cls, keyword, val)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue