OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import math | 6 import math |
7 import sys | 7 import sys |
8 | 8 |
9 import json5_generator | 9 import json5_generator |
10 import template_expander | 10 import template_expander |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 for a function in ComputedStyle. | 79 for a function in ComputedStyle. |
80 | 80 |
81 Attributes: | 81 Attributes: |
82 subgroups: List of DiffGroup instances that are stored as subgroups unde r this group. | 82 subgroups: List of DiffGroup instances that are stored as subgroups unde r this group. |
83 expressions: List of expression that are on this group that need to be d iffed. | 83 expressions: List of expression that are on this group that need to be d iffed. |
84 """ | 84 """ |
85 def __init__(self, group_name): | 85 def __init__(self, group_name): |
86 self.group_name = group_name | 86 self.group_name = group_name |
87 self.subgroups = [] | 87 self.subgroups = [] |
88 self.expressions = [] | 88 self.expressions = [] |
89 self.predicates = [] | |
89 | 90 |
90 | 91 |
91 class Field(object): | 92 class Field(object): |
92 """ | 93 """ |
93 The generated ComputedStyle object is made up of a series of Fields. | 94 The generated ComputedStyle object is made up of a series of Fields. |
94 Each Field has a name, size, type, etc, and a bunch of attributes to | 95 Each Field has a name, size, type, etc, and a bunch of attributes to |
95 determine which methods it will be used in. | 96 determine which methods it will be used in. |
96 | 97 |
97 A Field also has enough information to use any storage type in C++, such as | 98 A Field also has enough information to use any storage type in C++, such as |
98 regular member variables, or more complex storage like vectors or hashmaps. | 99 regular member variables, or more complex storage like vectors or hashmaps. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 groups[field.group_name].append(field) | 186 groups[field.group_name].append(field) |
186 | 187 |
187 no_group = groups.pop(None) | 188 no_group = groups.pop(None) |
188 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name, fields in groups.items()] | 189 subgroups = [Group(group_name, [], _reorder_fields(fields)) for group_name, fields in groups.items()] |
189 return Group('', subgroups=subgroups, fields=_reorder_fields(no_group)) | 190 return Group('', subgroups=subgroups, fields=_reorder_fields(no_group)) |
190 | 191 |
191 | 192 |
192 def _create_diff_groups_map(diff_function_inputs, root_group): | 193 def _create_diff_groups_map(diff_function_inputs, root_group): |
193 diff_functions_map = {} | 194 diff_functions_map = {} |
194 for entry in diff_function_inputs: | 195 for entry in diff_function_inputs: |
195 diff_functions_map[entry['name']] = _create_diff_groups(entry['fields_to _diff'], entry['methods_to_diff'], root_group) | 196 diff_functions_map[entry['name']] = _create_diff_groups(entry['fields_to _diff'], |
197 entry['methods_t o_diff'], entry['predicates_to_test'], root_group) | |
196 return diff_functions_map | 198 return diff_functions_map |
197 | 199 |
198 | 200 |
199 def _list_field_dependencies(methods_to_diff): | 201 def _list_field_dependencies(entries_with_field_dependencies): |
200 field_dependencies = [] | 202 field_dependencies = [] |
201 for entry in methods_to_diff: | 203 for entry in entries_with_field_dependencies: |
202 field_dependencies += entry['field_dependencies'] | 204 field_dependencies += entry['field_dependencies'] |
203 return field_dependencies | 205 return field_dependencies |
204 | 206 |
205 | 207 |
206 def _create_diff_groups(fields_to_diff, methods_to_diff, root_group): | 208 def _create_diff_groups(fields_to_diff, methods_to_diff, predicates_to_test, roo t_group): |
207 diff_group = DiffGroup(root_group.member_name) | 209 diff_group = DiffGroup(root_group.member_name) |
208 field_dependencies = _list_field_dependencies(methods_to_diff) | 210 field_dependencies = _list_field_dependencies(methods_to_diff) + _list_field _dependencies(predicates_to_test) |
alancutter (OOO until 2018)
2017/05/24 07:43:18
The + can go inside the brackets instead if you wa
nainar
2017/05/24 08:01:45
Ooohh yeah good catch. Done.
| |
209 for subgroup in root_group.subgroups: | 211 for subgroup in root_group.subgroups: |
210 if any(field.property_name in (fields_to_diff + field_dependencies) for field in subgroup.all_fields): | 212 if any(field.property_name in (fields_to_diff + field_dependencies) for field in subgroup.all_fields): |
211 diff_group.subgroups.append(_create_diff_groups(fields_to_diff, meth ods_to_diff, subgroup)) | 213 diff_group.subgroups.append(_create_diff_groups(fields_to_diff, meth ods_to_diff, predicates_to_test, subgroup)) |
212 for field in root_group.fields: | 214 for field in root_group.fields: |
213 if field.property_name in fields_to_diff: | 215 if field.property_name in fields_to_diff: |
214 diff_group.expressions.append(field.getter_expression) | 216 diff_group.expressions.append(field.getter_expression) |
215 for entry in methods_to_diff: | 217 for entry in methods_to_diff: |
216 if field.property_name in entry['field_dependencies']: | 218 if field.property_name in entry['field_dependencies']: |
217 diff_group.expressions.append(entry['method']) | 219 diff_group.expressions.append(entry['method']) |
220 for entry in predicates_to_test: | |
221 if field.property_name in entry['field_dependencies']: | |
222 diff_group.predicates.append(entry['predicate']) | |
218 return diff_group | 223 return diff_group |
219 | 224 |
220 | 225 |
221 def _create_enums(properties): | 226 def _create_enums(properties): |
222 """ | 227 """ |
223 Returns an OrderedDict of enums to be generated, enum name -> [list of enum values] | 228 Returns an OrderedDict of enums to be generated, enum name -> [list of enum values] |
224 """ | 229 """ |
225 enums = {} | 230 enums = {} |
226 for property_ in properties: | 231 for property_ in properties: |
227 # Only generate enums for keyword properties that use the default field_ type_path. | 232 # Only generate enums for keyword properties that use the default field_ type_path. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 | 456 |
452 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 457 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
453 def generate_base_computed_style_constants(self): | 458 def generate_base_computed_style_constants(self): |
454 return { | 459 return { |
455 'properties': self._properties, | 460 'properties': self._properties, |
456 'enums': self._generated_enums, | 461 'enums': self._generated_enums, |
457 } | 462 } |
458 | 463 |
459 if __name__ == '__main__': | 464 if __name__ == '__main__': |
460 json5_generator.Maker(ComputedStyleBaseWriter).main() | 465 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |