| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 def __hash__(self): | 168 def __hash__(self): |
| 169 if self.__cached_hash == None: | 169 if self.__cached_hash == None: |
| 170 initial_hash = hash((-1, TransitionKey.__upper_bound + 1)) | 170 initial_hash = hash((-1, TransitionKey.__upper_bound + 1)) |
| 171 f = lambda acc, r: acc ^ hash(r) | 171 f = lambda acc, r: acc ^ hash(r) |
| 172 self.__cached_hash = reduce(f, self.__ranges, initial_hash) | 172 self.__cached_hash = reduce(f, self.__ranges, initial_hash) |
| 173 return self.__cached_hash | 173 return self.__cached_hash |
| 174 | 174 |
| 175 def __eq__(self, other): | 175 def __eq__(self, other): |
| 176 return isinstance(other, self.__class__) and self.__ranges == other.__ranges | 176 return isinstance(other, self.__class__) and self.__ranges == other.__ranges |
| 177 | 177 |
| 178 def to_code(self): |
| 179 code = 'if (' |
| 180 first = True |
| 181 for r in self.__ranges: |
| 182 if not first: |
| 183 code += ' || ' |
| 184 if r[0] == r[1]: |
| 185 code += 'c == %s' % r[0] |
| 186 else: |
| 187 code += '(c >= %s && c <= %s)' % (r[0], r[1]) |
| 188 first = False |
| 189 code += ')' |
| 190 return code |
| 191 |
| 178 __printable_cache = { | 192 __printable_cache = { |
| 179 ord('\t') : '\\t', | 193 ord('\t') : '\\t', |
| 180 ord('\n') : '\\n', | 194 ord('\n') : '\\n', |
| 181 ord('\r') : '\\r', | 195 ord('\r') : '\\r', |
| 182 } | 196 } |
| 183 | 197 |
| 184 @staticmethod | 198 @staticmethod |
| 185 def __range_str(r): | 199 def __range_str(r): |
| 186 if TransitionKey.__is_class_range(r): | 200 if TransitionKey.__is_class_range(r): |
| 187 for name, v in TransitionKey.__class_bounds.items(): | 201 for name, v in TransitionKey.__class_bounds.items(): |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 if r[0] != TransitionKey.__lower_bound: | 306 if r[0] != TransitionKey.__lower_bound: |
| 293 inverted.append((TransitionKey.__lower_bound, r[0] - 1)) | 307 inverted.append((TransitionKey.__lower_bound, r[0] - 1)) |
| 294 elif last[1] + 1 < r[0]: | 308 elif last[1] + 1 < r[0]: |
| 295 inverted.append((last[1] + 1, r[0] - 1)) | 309 inverted.append((last[1] + 1, r[0] - 1)) |
| 296 last = r | 310 last = r |
| 297 upper_bound = TransitionKey.__class_bounds["latin_1"][1] | 311 upper_bound = TransitionKey.__class_bounds["latin_1"][1] |
| 298 if last != None and last[1] < upper_bound: | 312 if last != None and last[1] < upper_bound: |
| 299 inverted.append((last[1] + 1, upper_bound)) | 313 inverted.append((last[1] + 1, upper_bound)) |
| 300 inverted += list(classes) | 314 inverted += list(classes) |
| 301 return inverted | 315 return inverted |
| OLD | NEW |