1.1 --- a/deducer.py Fri Sep 09 22:42:31 2016 +0200
1.2 +++ b/deducer.py Tue Sep 20 23:14:43 2016 +0200
1.3 @@ -19,11 +19,12 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from common import first, get_attrname_from_location, get_attrnames, \
1.8 +from common import get_attrname_from_location, get_attrnames, \
1.9 init_item, make_key, sorted_output, \
1.10 CommonOutput
1.11 from encoders import encode_attrnames, encode_access_location, \
1.12 - encode_constrained, encode_location, encode_usage
1.13 + encode_constrained, encode_location, encode_usage, \
1.14 + get_kinds, test_for_kinds, test_for_types
1.15 from os.path import join
1.16 from referencing import Reference
1.17
1.18 @@ -246,14 +247,14 @@
1.19
1.20 if guard_test and guard_test.startswith("specific"):
1.21 print >>f_guards, encode_location(location), guard_test, \
1.22 - self.get_kinds(all_types)[0], \
1.23 + get_kinds(all_types)[0], \
1.24 sorted_output(all_types)
1.25
1.26 # Write common type guard details.
1.27
1.28 elif guard_test and guard_test.startswith("common"):
1.29 print >>f_guards, encode_location(location), guard_test, \
1.30 - self.get_kinds(all_general_types)[0], \
1.31 + get_kinds(all_general_types)[0], \
1.32 sorted_output(all_general_types)
1.33
1.34 print >>f_type_summary, encode_location(location), encode_constrained(constrained), \
1.35 @@ -417,14 +418,14 @@
1.36 # Record specific type guard details.
1.37
1.38 if len(all_types) == 1:
1.39 - self.accessor_guard_tests[location] = self.test_for_types("specific", all_types)
1.40 + self.accessor_guard_tests[location] = test_for_types("specific", all_types)
1.41 elif self.is_single_class_type(all_types):
1.42 self.accessor_guard_tests[location] = "specific-object"
1.43
1.44 # Record common type guard details.
1.45
1.46 elif len(all_general_types) == 1:
1.47 - self.accessor_guard_tests[location] = self.test_for_types("common", all_types)
1.48 + self.accessor_guard_tests[location] = test_for_types("common", all_types)
1.49 elif self.is_single_class_type(all_general_types):
1.50 self.accessor_guard_tests[location] = "common-object"
1.51
1.52 @@ -533,11 +534,11 @@
1.53
1.54 if guarded and all_accessed_attrs.issubset(guard_attrs):
1.55 if len(all_accessor_types) == 1:
1.56 - self.reference_test_types[location] = self.test_for_types("guarded-specific", all_accessor_types)
1.57 + self.reference_test_types[location] = test_for_types("guarded-specific", all_accessor_types)
1.58 elif self.is_single_class_type(all_accessor_types):
1.59 self.reference_test_types[location] = "guarded-specific-object"
1.60 elif len(all_accessor_general_types) == 1:
1.61 - self.reference_test_types[location] = self.test_for_types("guarded-common", all_accessor_general_types)
1.62 + self.reference_test_types[location] = test_for_types("guarded-common", all_accessor_general_types)
1.63 elif self.is_single_class_type(all_accessor_general_types):
1.64 self.reference_test_types[location] = "guarded-common-object"
1.65
1.66 @@ -550,9 +551,9 @@
1.67 if len(all_providers) == 1:
1.68 provider = list(all_providers)[0]
1.69 if provider != '__builtins__.object':
1.70 - all_accessor_kinds = set(self.get_kinds(all_accessor_types))
1.71 + all_accessor_kinds = set(get_kinds(all_accessor_types))
1.72 if len(all_accessor_kinds) == 1:
1.73 - test_type = self.test_for_kinds("specific", all_accessor_kinds)
1.74 + test_type = test_for_kinds("specific", all_accessor_kinds)
1.75 else:
1.76 test_type = "specific-object"
1.77 self.reference_test_types[location] = test_type
1.78 @@ -561,9 +562,9 @@
1.79 elif len(all_general_providers) == 1:
1.80 provider = list(all_general_providers)[0]
1.81 if provider != '__builtins__.object':
1.82 - all_accessor_kinds = set(self.get_kinds(all_accessor_general_types))
1.83 + all_accessor_kinds = set(get_kinds(all_accessor_general_types))
1.84 if len(all_accessor_kinds) == 1:
1.85 - test_type = self.test_for_kinds("common", all_accessor_kinds)
1.86 + test_type = test_for_kinds("common", all_accessor_kinds)
1.87 else:
1.88 test_type = "common-object"
1.89 self.reference_test_types[location] = test_type
1.90 @@ -591,42 +592,6 @@
1.91 l.append((attrtype, attrs))
1.92 return l
1.93
1.94 - # Test generation methods.
1.95 -
1.96 - def get_kinds(self, all_types):
1.97 -
1.98 - """
1.99 - Return object kind details for 'all_types', being a collection of
1.100 - references for program types.
1.101 - """
1.102 -
1.103 - return map(lambda ref: ref.get_kind(), all_types)
1.104 -
1.105 - def test_for_types(self, prefix, all_types):
1.106 -
1.107 - """
1.108 - Return identifiers describing test conditions incorporating the given
1.109 - 'prefix' and involving 'all_types', being a collection of references to
1.110 - program types.
1.111 - """
1.112 -
1.113 - return self.test_for_kind(prefix, first(all_types).get_kind())
1.114 -
1.115 - def test_for_kinds(self, prefix, all_kinds):
1.116 -
1.117 - """
1.118 - Return identifiers describing test conditions incorporating the given
1.119 - 'prefix' and involving 'all_kinds', being a collection of object kinds.
1.120 - """
1.121 -
1.122 - return self.test_for_kind(prefix, first(all_kinds))
1.123 -
1.124 - def test_for_kind(self, prefix, kind):
1.125 -
1.126 - "Return a test condition identifier featuring 'prefix' and 'kind'."
1.127 -
1.128 - return "%s-%s" % (prefix, kind == "<instance>" and "instance" or "type")
1.129 -
1.130 # Type handling methods.
1.131
1.132 def is_single_class_type(self, all_types):