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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 assert len(kwargs) == 0, 'Unexpected arguments provided to Field: ' + st
r(kwargs) | 168 assert len(kwargs) == 0, 'Unexpected arguments provided to Field: ' + st
r(kwargs) |
169 | 169 |
170 | 170 |
171 def _get_include_paths(properties): | 171 def _get_include_paths(properties): |
172 """ | 172 """ |
173 Get a list of paths that need to be included for ComputedStyleBase. | 173 Get a list of paths that need to be included for ComputedStyleBase. |
174 """ | 174 """ |
175 include_paths = set() | 175 include_paths = set() |
176 for property_ in properties: | 176 for property_ in properties: |
177 if property_['field_type_path'] is not None: | 177 include_paths.update(property_['include_paths']) |
178 include_paths.add(property_['field_type_path'] + '.h') | |
179 return list(sorted(include_paths)) | 178 return list(sorted(include_paths)) |
180 | 179 |
181 | 180 |
182 def _group_fields(fields): | 181 def _group_fields(fields): |
183 """Groups a list of fields by their group_name and returns the root group.""
" | 182 """Groups a list of fields by their group_name and returns the root group.""
" |
184 groups = defaultdict(list) | 183 groups = defaultdict(list) |
185 for field in fields: | 184 for field in fields: |
186 groups[field.group_name].append(field) | 185 groups[field.group_name].append(field) |
187 | 186 |
188 no_group = groups.pop(None) | 187 no_group = groups.pop(None) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 diff_group.predicates.append(entry['predicate']) | 222 diff_group.predicates.append(entry['predicate']) |
224 return diff_group | 223 return diff_group |
225 | 224 |
226 | 225 |
227 def _create_enums(properties): | 226 def _create_enums(properties): |
228 """ | 227 """ |
229 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] |
230 """ | 229 """ |
231 enums = {} | 230 enums = {} |
232 for property_ in properties: | 231 for property_ in properties: |
233 # Only generate enums for keyword properties that use the default field_
type_path. | 232 # Only generate enums for keyword properties that do not require include
s. |
234 if property_['field_template'] == 'keyword' and property_['field_type_pa
th'] is None: | 233 if property_['field_template'] == 'keyword' and len(property_['include_p
aths']) == 0: |
235 enum_name = property_['type_name'] | 234 enum_name = property_['type_name'] |
236 enum_values = [enum_value_name(k) for k in property_['keywords']] | 235 enum_values = [enum_value_name(k) for k in property_['keywords']] |
237 | 236 |
238 if enum_name in enums: | 237 if enum_name in enums: |
239 # There's an enum with the same name, check if the enum values a
re the same | 238 # There's an enum with the same name, check if the enum values a
re the same |
240 assert set(enums[enum_name]) == set(enum_values), \ | 239 assert set(enums[enum_name]) == set(enum_values), \ |
241 ("'" + property_['name'] + "' can't have type_name '" + enum
_name + "' " | 240 ("'" + property_['name'] + "' can't have type_name '" + enum
_name + "' " |
242 "because it was used by a previous property, but with a dif
ferent set of keywords. " | 241 "because it was used by a previous property, but with a dif
ferent set of keywords. " |
243 "Either give it a different name or ensure the keywords are
the same.") | 242 "Either give it a different name or ensure the keywords are
the same.") |
244 | 243 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 extra_fields = json5_generator.Json5File.load_from_files( | 415 extra_fields = json5_generator.Json5File.load_from_files( |
417 [json5_file_paths[1]], | 416 [json5_file_paths[1]], |
418 default_parameters=self.json5_file.parameters | 417 default_parameters=self.json5_file.parameters |
419 ).name_dictionaries | 418 ).name_dictionaries |
420 | 419 |
421 for property_ in extra_fields: | 420 for property_ in extra_fields: |
422 make_style_builder.apply_property_naming_defaults(property_) | 421 make_style_builder.apply_property_naming_defaults(property_) |
423 | 422 |
424 all_properties = css_properties + extra_fields | 423 all_properties = css_properties + extra_fields |
425 | 424 |
426 # Override the type name when field_type_path is specified | |
427 for property_ in all_properties: | |
428 if property_['field_type_path']: | |
429 property_['type_name'] = property_['field_type_path'].split('/')
[-1] | |
430 | |
431 self._generated_enums = _create_enums(all_properties) | 425 self._generated_enums = _create_enums(all_properties) |
432 | 426 |
433 all_fields = _create_fields(all_properties) | 427 all_fields = _create_fields(all_properties) |
434 | 428 |
435 # Organise fields into a tree structure where the root group | 429 # Organise fields into a tree structure where the root group |
436 # is ComputedStyleBase. | 430 # is ComputedStyleBase. |
437 self._root_group = _group_fields(all_fields) | 431 self._root_group = _group_fields(all_fields) |
438 self._diff_functions_map = _create_diff_groups_map(json5_generator.Json5
File.load_from_files( | 432 self._diff_functions_map = _create_diff_groups_map(json5_generator.Json5
File.load_from_files( |
439 [json5_file_paths[2]] | 433 [json5_file_paths[2]] |
440 ).name_dictionaries, self._root_group) | 434 ).name_dictionaries, self._root_group) |
(...skipping 16 matching lines...) Expand all Loading... |
457 | 451 |
458 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 452 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
459 def generate_base_computed_style_constants(self): | 453 def generate_base_computed_style_constants(self): |
460 return { | 454 return { |
461 'properties': self._properties, | 455 'properties': self._properties, |
462 'enums': self._generated_enums, | 456 'enums': self._generated_enums, |
463 } | 457 } |
464 | 458 |
465 if __name__ == '__main__': | 459 if __name__ == '__main__': |
466 json5_generator.Maker(ComputedStyleBaseWriter).main() | 460 json5_generator.Maker(ComputedStyleBaseWriter).main() |
OLD | NEW |