1.1 --- a/micropython/common.py Mon Mar 10 23:14:26 2014 +0100
1.2 +++ b/micropython/common.py Thu Mar 13 23:10:25 2014 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Common classes.
1.6
1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -20,7 +20,7 @@
1.13 """
1.14
1.15 from micropython.stdcompiler import compiler
1.16 -from micropython.basicdata import Constant, TypedInstance
1.17 +from micropython.basicdata import Constant, TypedInstance, Instance
1.18 from micropython.data import BaseAttr, Class
1.19 from micropython.errors import *
1.20 from os.path import split
1.21 @@ -108,6 +108,30 @@
1.22
1.23 return None
1.24
1.25 + def get_type_for_attribute(self, attr, value):
1.26 +
1.27 + """
1.28 + For an attribute 'attr' and 'value', return the "parent" type of the
1.29 + attribute if possible. Otherwise, return None.
1.30 + """
1.31 +
1.32 + if attr:
1.33 + return attr.get_type()
1.34 + elif value and not isinstance(value, Instance) and value.parent:
1.35 + return value.parent
1.36 + else:
1.37 + return None
1.38 +
1.39 + def get_values_for_attribute(self, attr, value):
1.40 +
1.41 + """
1.42 + Return values defined for the given attribute 'attr' unless a specific
1.43 + 'value' is provided, in which case a list containing that value is
1.44 + returned. Where no values are defined, return None in a list.
1.45 + """
1.46 +
1.47 + return value and [value] or attr and attr.get_values() or [None]
1.48 +
1.49 def get_module_name(node, module):
1.50
1.51 """