| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 3 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 | 7 |
| 8 """ | 8 """ |
| 9 Responsible for generating the testing decoders based on | 9 Responsible for generating the testing decoders based on |
| 10 parsed table representations. | 10 parsed table representations. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 # Note: DECODER will be replaced by 'actual' and 'baseline', defining | 176 # Note: DECODER will be replaced by 'actual' and 'baseline', defining |
| 177 # how both types of symbols are generated. | 177 # how both types of symbols are generated. |
| 178 | 178 |
| 179 CLASS = '%(DECODER)s_%(rule)s' | 179 CLASS = '%(DECODER)s_%(rule)s' |
| 180 NAMED_CLASS = 'Named%(DECODER)s_%(rule)s' | 180 NAMED_CLASS = 'Named%(DECODER)s_%(rule)s' |
| 181 INSTANCE = '%(DECODER_class)s_instance_' | 181 INSTANCE = '%(DECODER_class)s_instance_' |
| 182 BASE_TESTER='%(decoder_base)sTester%(base_test_case)s' | 182 BASE_TESTER='%(decoder_base)sTester%(base_test_case)s' |
| 183 BASE_BASE_TESTER='%(decoder_base)sTester%(qualifier)s' | 183 BASE_BASE_TESTER='%(decoder_base)sTester%(qualifier)s' |
| 184 DECODER_TESTER='%(baseline)sTester_%(test_case)s' | 184 DECODER_TESTER='%(baseline)sTester_%(test_case)s' |
| 185 | 185 |
| 186 def _negated_constraint(constraint): | |
| 187 """Returns the negated pattern for the pattern text passed in.""" | |
| 188 if constraint[0] == '~': | |
| 189 return constraint[1:] | |
| 190 else: | |
| 191 return '~' + constraint | |
| 192 | |
| 193 def _safety_to_check(safety): | 186 def _safety_to_check(safety): |
| 194 return [s for s in safety if not isinstance(s, str)] | 187 return [s for s in safety if not isinstance(s, str)] |
| 195 | 188 |
| 196 def _interesting_patterns(patterns): | 189 def _interesting_patterns(patterns): |
| 197 """ Filters out non-interesting patterns.""" | 190 """ Filters out non-interesting patterns.""" |
| 198 # Only include rows not corresponding to rule pattern, | 191 # Only include rows not corresponding to rule pattern, |
| 199 # and not always true. | 192 # and not always true. |
| 200 return [ p for p in patterns if ( | 193 return [ p for p in patterns if ( |
| 201 (not p.column or p.column.name() != '$pattern') | 194 (not p.column or p.column.name() != '$pattern') |
| 202 and not p.matches_any())] | 195 and not p.matches_any())] |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 if row.patterns or action.constraints().restrictions: | 907 if row.patterns or action.constraints().restrictions: |
| 915 out.write(CONSTRAINT_TESTER_PARSE_HEADER % values) | 908 out.write(CONSTRAINT_TESTER_PARSE_HEADER % values) |
| 916 if row.patterns: | 909 if row.patterns: |
| 917 out.write(ROW_CONSTRAINTS_HEADER % values); | 910 out.write(ROW_CONSTRAINTS_HEADER % values); |
| 918 for p in row.patterns: | 911 for p in row.patterns: |
| 919 out.write(CONSTRAINT_CHECK % p.negate().to_commented_bool()) | 912 out.write(CONSTRAINT_CHECK % p.negate().to_commented_bool()) |
| 920 if action.constraints().restrictions: | 913 if action.constraints().restrictions: |
| 921 out.write(PATTERN_CONSTRAINT_RESTRICTIONS_HEADER) | 914 out.write(PATTERN_CONSTRAINT_RESTRICTIONS_HEADER) |
| 922 for c in action.constraints().restrictions: | 915 for c in action.constraints().restrictions: |
| 923 out.write(CONSTRAINT_CHECK % | 916 out.write(CONSTRAINT_CHECK % |
| 924 dgen_core.BitPattern.parse( | 917 c.negate().to_commented_bool()) |
| 925 _negated_constraint(c), | |
| 926 dgen_core.BitField('constraint', 31, 0)) | |
| 927 .to_commented_bool()) | |
| 928 out.write(CONSTRAINT_TESTER_CLASS_FOOTER % values) | 918 out.write(CONSTRAINT_TESTER_CLASS_FOOTER % values) |
| 929 if safety_to_check: | 919 if safety_to_check: |
| 930 out.write(SAFETY_TESTER_HEADER % values) | 920 out.write(SAFETY_TESTER_HEADER % values) |
| 931 for check in safety_to_check: | 921 for check in safety_to_check: |
| 932 out.write(SAFETY_TESTER_CHECK % | 922 out.write(SAFETY_TESTER_CHECK % |
| 933 check.to_commented_bool()); | 923 check.to_commented_bool()); |
| 934 out.write(SAFETY_TESTER_FOOTER % values) | 924 out.write(SAFETY_TESTER_FOOTER % values) |
| 935 | 925 |
| 936 def _generate_rule_testers(decoder, values, out): | 926 def _generate_rule_testers(decoder, values, out): |
| 937 """Generates the testers that tests the rule associated with | 927 """Generates the testers that tests the rule associated with |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 values, to its corresponding index. This is done to reduce the | 968 values, to its corresponding index. This is done to reduce the |
| 979 number of compares to find the index, speeding up code | 969 number of compares to find the index, speeding up code |
| 980 generation. | 970 generation. |
| 981 """ | 971 """ |
| 982 map = {} | 972 map = {} |
| 983 index = 0 | 973 index = 0 |
| 984 for v in values: | 974 for v in values: |
| 985 map[dgen_core.neutral_repr(v)] = index | 975 map[dgen_core.neutral_repr(v)] = index |
| 986 index += 1 | 976 index += 1 |
| 987 return map | 977 return map |
| OLD | NEW |