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):
2.1 --- a/encoders.py Fri Sep 09 22:42:31 2016 +0200
2.2 +++ b/encoders.py Tue Sep 20 23:14:43 2016 +0200
2.3 @@ -19,6 +19,8 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 +from common import first
2.8 +
2.9 # Output encoding and decoding for the summary files.
2.10
2.11 def encode_attrnames(attrnames):
2.12 @@ -83,6 +85,46 @@
2.13
2.14 return s == "A"
2.15
2.16 +
2.17 +
2.18 +# Test generation functions.
2.19 +
2.20 +def get_kinds(all_types):
2.21 +
2.22 + """
2.23 + Return object kind details for 'all_types', being a collection of
2.24 + references for program types.
2.25 + """
2.26 +
2.27 + return map(lambda ref: ref.get_kind(), all_types)
2.28 +
2.29 +def test_for_kind(prefix, kind):
2.30 +
2.31 + "Return a test condition identifier featuring 'prefix' and 'kind'."
2.32 +
2.33 + return "%s-%s" % (prefix, kind == "<instance>" and "instance" or "type")
2.34 +
2.35 +def test_for_kinds(prefix, all_kinds):
2.36 +
2.37 + """
2.38 + Return identifiers describing test conditions incorporating the given
2.39 + 'prefix' and involving 'all_kinds', being a collection of object kinds.
2.40 + """
2.41 +
2.42 + return test_for_kind(prefix, first(all_kinds))
2.43 +
2.44 +def test_for_types(prefix, all_types):
2.45 +
2.46 + """
2.47 + Return identifiers describing test conditions incorporating the given
2.48 + 'prefix' and involving 'all_types', being a collection of references to
2.49 + program types.
2.50 + """
2.51 +
2.52 + return test_for_kind(prefix, first(all_types).get_kind())
2.53 +
2.54 +
2.55 +
2.56 # Output program encoding.
2.57
2.58 def encode_function_pointer(path):
2.59 @@ -112,6 +154,8 @@
2.60
2.61 return "__%s%s" % (symbol_type, path and "_%s" % encode_path(path) or "")
2.62
2.63 +
2.64 +
2.65 # Output language reserved words.
2.66
2.67 reserved_words = [