1.1 --- a/micropython/common.py Sat Apr 20 00:59:58 2013 +0200
1.2 +++ b/micropython/common.py Thu Apr 25 18:08:32 2013 +0200
1.3 @@ -76,6 +76,42 @@
1.4
1.5 # Deduction-related methods.
1.6
1.7 + def get_attributes(self, targets, attrname):
1.8 +
1.9 + "Return a list of attributes for 'targets' supporting 'attrname'."
1.10 +
1.11 + attributes = set()
1.12 +
1.13 + for target in targets:
1.14 + try:
1.15 + attributes.add(self.objtable.access(target.full_name(), attrname))
1.16 + except TableError:
1.17 + return None
1.18 +
1.19 + return attributes
1.20 +
1.21 + def get_attribute_and_value(self, obj):
1.22 +
1.23 + """
1.24 + Return (attribute, value) details for the given 'obj', where an
1.25 + attribute of None can be returned for constant objects, and where None
1.26 + can be returned as the result where no concrete details can be provided.
1.27 + """
1.28 +
1.29 + if isinstance(obj, Constant):
1.30 + return None, obj
1.31 +
1.32 + if isinstance(obj, Attr):
1.33 + return obj, obj.get_value()
1.34 +
1.35 + return None
1.36 +
1.37 + def provides_constant_result(self, value):
1.38 +
1.39 + "Return whether 'value' provides a constant result."
1.40 +
1.41 + return isinstance(value, (Const, Constant))
1.42 +
1.43 def provides_self_access(self, node, unit):
1.44
1.45 """
1.46 @@ -134,22 +170,6 @@
1.47
1.48 return all_target_names and all_target_names[0]
1.49
1.50 - def get_attribute_and_value(self, obj):
1.51 -
1.52 - """
1.53 - Return (attribute, value) details for the given 'obj', where an
1.54 - attribute of None can be returned for constant objects, and where None
1.55 - can be returned as the result where no concrete details can be provided.
1.56 - """
1.57 -
1.58 - if isinstance(obj, Constant):
1.59 - return None, obj
1.60 -
1.61 - if isinstance(obj, Attr):
1.62 - return obj, obj.get_value()
1.63 -
1.64 - return None
1.65 -
1.66 def possible_attributes_from_annotation(self, node):
1.67
1.68 """
1.69 @@ -240,6 +260,17 @@
1.70
1.71 return targets
1.72
1.73 + def possible_accessors_for_attribute(self, attrname):
1.74 +
1.75 + "Return possible accessors given the single 'attrname'."
1.76 +
1.77 + targets = set()
1.78 +
1.79 + for target_name in self.objtable.any_possible_objects([attrname]):
1.80 + targets.add(self.objtable.get_object(target_name))
1.81 +
1.82 + return targets
1.83 +
1.84 def used_by_unit(node):
1.85
1.86 """