# HG changeset patch # User Paul Boddie # Date 1474406083 -7200 # Node ID df0fe187baa10a7a09a00b631809ff3e35b6d6bb # Parent 619717628963477fb7ec2aae7f2a3988270e9273 Moved test output encoder functions. diff -r 619717628963 -r df0fe187baa1 deducer.py --- a/deducer.py Fri Sep 09 22:42:31 2016 +0200 +++ b/deducer.py Tue Sep 20 23:14:43 2016 +0200 @@ -19,11 +19,12 @@ this program. If not, see . """ -from common import first, get_attrname_from_location, get_attrnames, \ +from common import get_attrname_from_location, get_attrnames, \ init_item, make_key, sorted_output, \ CommonOutput from encoders import encode_attrnames, encode_access_location, \ - encode_constrained, encode_location, encode_usage + encode_constrained, encode_location, encode_usage, \ + get_kinds, test_for_kinds, test_for_types from os.path import join from referencing import Reference @@ -246,14 +247,14 @@ if guard_test and guard_test.startswith("specific"): print >>f_guards, encode_location(location), guard_test, \ - self.get_kinds(all_types)[0], \ + get_kinds(all_types)[0], \ sorted_output(all_types) # Write common type guard details. elif guard_test and guard_test.startswith("common"): print >>f_guards, encode_location(location), guard_test, \ - self.get_kinds(all_general_types)[0], \ + get_kinds(all_general_types)[0], \ sorted_output(all_general_types) print >>f_type_summary, encode_location(location), encode_constrained(constrained), \ @@ -417,14 +418,14 @@ # Record specific type guard details. if len(all_types) == 1: - self.accessor_guard_tests[location] = self.test_for_types("specific", all_types) + self.accessor_guard_tests[location] = test_for_types("specific", all_types) elif self.is_single_class_type(all_types): self.accessor_guard_tests[location] = "specific-object" # Record common type guard details. elif len(all_general_types) == 1: - self.accessor_guard_tests[location] = self.test_for_types("common", all_types) + self.accessor_guard_tests[location] = test_for_types("common", all_types) elif self.is_single_class_type(all_general_types): self.accessor_guard_tests[location] = "common-object" @@ -533,11 +534,11 @@ if guarded and all_accessed_attrs.issubset(guard_attrs): if len(all_accessor_types) == 1: - self.reference_test_types[location] = self.test_for_types("guarded-specific", all_accessor_types) + self.reference_test_types[location] = test_for_types("guarded-specific", all_accessor_types) elif self.is_single_class_type(all_accessor_types): self.reference_test_types[location] = "guarded-specific-object" elif len(all_accessor_general_types) == 1: - self.reference_test_types[location] = self.test_for_types("guarded-common", all_accessor_general_types) + self.reference_test_types[location] = test_for_types("guarded-common", all_accessor_general_types) elif self.is_single_class_type(all_accessor_general_types): self.reference_test_types[location] = "guarded-common-object" @@ -550,9 +551,9 @@ if len(all_providers) == 1: provider = list(all_providers)[0] if provider != '__builtins__.object': - all_accessor_kinds = set(self.get_kinds(all_accessor_types)) + all_accessor_kinds = set(get_kinds(all_accessor_types)) if len(all_accessor_kinds) == 1: - test_type = self.test_for_kinds("specific", all_accessor_kinds) + test_type = test_for_kinds("specific", all_accessor_kinds) else: test_type = "specific-object" self.reference_test_types[location] = test_type @@ -561,9 +562,9 @@ elif len(all_general_providers) == 1: provider = list(all_general_providers)[0] if provider != '__builtins__.object': - all_accessor_kinds = set(self.get_kinds(all_accessor_general_types)) + all_accessor_kinds = set(get_kinds(all_accessor_general_types)) if len(all_accessor_kinds) == 1: - test_type = self.test_for_kinds("common", all_accessor_kinds) + test_type = test_for_kinds("common", all_accessor_kinds) else: test_type = "common-object" self.reference_test_types[location] = test_type @@ -591,42 +592,6 @@ l.append((attrtype, attrs)) return l - # Test generation methods. - - def get_kinds(self, all_types): - - """ - Return object kind details for 'all_types', being a collection of - references for program types. - """ - - return map(lambda ref: ref.get_kind(), all_types) - - def test_for_types(self, prefix, all_types): - - """ - Return identifiers describing test conditions incorporating the given - 'prefix' and involving 'all_types', being a collection of references to - program types. - """ - - return self.test_for_kind(prefix, first(all_types).get_kind()) - - def test_for_kinds(self, prefix, all_kinds): - - """ - Return identifiers describing test conditions incorporating the given - 'prefix' and involving 'all_kinds', being a collection of object kinds. - """ - - return self.test_for_kind(prefix, first(all_kinds)) - - def test_for_kind(self, prefix, kind): - - "Return a test condition identifier featuring 'prefix' and 'kind'." - - return "%s-%s" % (prefix, kind == "" and "instance" or "type") - # Type handling methods. def is_single_class_type(self, all_types): diff -r 619717628963 -r df0fe187baa1 encoders.py --- a/encoders.py Fri Sep 09 22:42:31 2016 +0200 +++ b/encoders.py Tue Sep 20 23:14:43 2016 +0200 @@ -19,6 +19,8 @@ this program. If not, see . """ +from common import first + # Output encoding and decoding for the summary files. def encode_attrnames(attrnames): @@ -83,6 +85,46 @@ return s == "A" + + +# Test generation functions. + +def get_kinds(all_types): + + """ + Return object kind details for 'all_types', being a collection of + references for program types. + """ + + return map(lambda ref: ref.get_kind(), all_types) + +def test_for_kind(prefix, kind): + + "Return a test condition identifier featuring 'prefix' and 'kind'." + + return "%s-%s" % (prefix, kind == "" and "instance" or "type") + +def test_for_kinds(prefix, all_kinds): + + """ + Return identifiers describing test conditions incorporating the given + 'prefix' and involving 'all_kinds', being a collection of object kinds. + """ + + return test_for_kind(prefix, first(all_kinds)) + +def test_for_types(prefix, all_types): + + """ + Return identifiers describing test conditions incorporating the given + 'prefix' and involving 'all_types', being a collection of references to + program types. + """ + + return test_for_kind(prefix, first(all_types).get_kind()) + + + # Output program encoding. def encode_function_pointer(path): @@ -112,6 +154,8 @@ return "__%s%s" % (symbol_type, path and "_%s" % encode_path(path) or "") + + # Output language reserved words. reserved_words = [