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 from collections import namedtuple | 6 from collections import namedtuple |
7 import math | 7 import math |
8 import sys | 8 import sys |
9 | 9 |
10 import in_generator | 10 import in_generator |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 # A map of enum name -> list of enum values | 24 # A map of enum name -> list of enum values |
25 self._computed_enums = {} | 25 self._computed_enums = {} |
26 for property in self._properties.values(): | 26 for property in self._properties.values(): |
27 if property['keyword_only']: | 27 if property['keyword_only']: |
28 enum_name = property['type_name'] | 28 enum_name = property['type_name'] |
29 # From the Blink style guide: Enum members should use InterCaps
with an initial capital letter. [names-enum-members] | 29 # From the Blink style guide: Enum members should use InterCaps
with an initial capital letter. [names-enum-members] |
30 enum_values = [k.title() for k in property['keywords']] | 30 enum_values = [k.title() for k in property['keywords']] |
31 self._computed_enums[enum_name] = enum_values | 31 self._computed_enums[enum_name] = enum_values |
32 | 32 |
33 # A list of fields | 33 # A list of fields. |
34 Field = namedtuple('Field', [ | 34 Field = namedtuple('Field', [ |
35 # Name of field member variable | 35 # Name of field member variable |
36 'name', | 36 'name', |
| 37 # Name of field in method names |
| 38 'upper_camel_name', |
| 39 'lower_camel_name', |
37 # Property field is for | 40 # Property field is for |
38 'property', | 41 'property', |
39 # Field storage type | 42 # Field storage type |
40 'type', | 43 'type', |
41 # Bits needed for storage | 44 # Bits needed for storage |
42 'size', | 45 'size', |
43 # Default value for field | 46 # Default value for field |
44 'default_value', | 47 'default_value', |
| 48 # Which comparison functions to include this field in. |
| 49 'comparison_function_independent_inherited', |
| 50 'comparison_function_non_independent_inherited', |
| 51 'comparison_function_non_inherited', |
| 52 # Which copy functions to include this field in. |
| 53 'copy_function_inherit', |
| 54 'copy_function_non_inherited_cache', |
| 55 # If this field is independent, this is the field that stores the bi
t |
| 56 # for whether this field was inherited or not. |
| 57 'inherited_flag_field', |
45 ]) | 58 ]) |
46 self._fields = [] | 59 self._fields = [] |
| 60 # Property name -> [fields for this property]. |
| 61 self._fields_per_property = {} |
47 for property in self._properties.values(): | 62 for property in self._properties.values(): |
| 63 fields_for_property = [] |
| 64 # Only generate keyword-only properties for now. |
48 if property['keyword_only']: | 65 if property['keyword_only']: |
49 # From the Blink style guide: Other data members should be prefi
xed by "m_". [names-data-members] | 66 # From the Blink style guide: Other data members should be prefi
xed by "m_". [names-data-members] |
50 field_name = 'm_' + property['lower_camel_name'] | 67 field_name = 'm_' + property['lower_camel_name'] |
51 bits_needed = math.log(len(property['keywords']), 2) | 68 bits_needed = math.log(len(property['keywords']), 2) |
52 type_name = property['type_name'] | 69 type_name = property['type_name'] |
53 # For now, assume the default value is the first enum value. | 70 # For now, assume the default value is the first enum value. |
54 default_value = type_name + '::' + self._computed_enums[type_nam
e][0] | 71 default_value = type_name + '::' + self._computed_enums[type_nam
e][0] |
55 self._fields.append(Field( | 72 |
| 73 inherited_flag_field = None |
| 74 if property['independent']: |
| 75 inherited_flag_field = Field( |
| 76 name=field_name + 'IsInherited', |
| 77 upper_camel_name=property['upper_camel_name'] + 'IsInher
ited', |
| 78 lower_camel_name=property['lower_camel_name'] + 'IsInher
ited', |
| 79 property=property, |
| 80 type='bool', |
| 81 size=1, |
| 82 default_value='true', |
| 83 comparison_function_independent_inherited=False, |
| 84 comparison_function_non_independent_inherited=False, |
| 85 comparison_function_non_inherited=False, |
| 86 copy_function_inherit=False, |
| 87 copy_function_non_inherited_cache=True, |
| 88 inherited_flag_field=None, |
| 89 ) |
| 90 fields_for_property.append(inherited_flag_field) |
| 91 |
| 92 fields_for_property.append(Field( |
56 name=field_name, | 93 name=field_name, |
| 94 upper_camel_name=property['upper_camel_name'], |
| 95 lower_camel_name=property['lower_camel_name'], |
57 property=property, | 96 property=property, |
58 type=type_name, | 97 type=type_name, |
59 size=int(math.ceil(bits_needed)), | 98 size=int(math.ceil(bits_needed)), |
60 default_value=default_value, | 99 default_value=default_value, |
| 100 comparison_function_independent_inherited=property['inherite
d'] and property['independent'], |
| 101 comparison_function_non_independent_inherited=property['inhe
rited'] and not property['independent'], |
| 102 comparison_function_non_inherited=not property['inherited'], |
| 103 copy_function_inherit=property['inherited'], |
| 104 copy_function_non_inherited_cache=not property['inherited'], |
| 105 inherited_flag_field=inherited_flag_field |
61 )) | 106 )) |
| 107 self._fields += fields_for_property |
| 108 self._fields_per_property[property['name']] = fields_for_property |
62 | 109 |
63 @template_expander.use_jinja('ComputedStyleBase.h.tmpl') | 110 @template_expander.use_jinja('ComputedStyleBase.h.tmpl') |
64 def generate_base_computed_style_h(self): | 111 def generate_base_computed_style_h(self): |
65 return { | 112 return { |
66 'properties': self._properties, | 113 'properties': self._properties, |
67 'enums': self._computed_enums, | 114 'enums': self._computed_enums, |
68 'fields': self._fields, | 115 'fields': self._fields, |
| 116 'fields_per_property': self._fields_per_property, |
69 } | 117 } |
70 | 118 |
71 @template_expander.use_jinja('ComputedStyleBase.cpp.tmpl') | 119 @template_expander.use_jinja('ComputedStyleBase.cpp.tmpl') |
72 def generate_base_computed_style_cpp(self): | 120 def generate_base_computed_style_cpp(self): |
73 return { | 121 return { |
74 'properties': self._properties, | 122 'properties': self._properties, |
75 'enums': self._computed_enums, | 123 'enums': self._computed_enums, |
76 'fields': self._fields, | 124 'fields': self._fields, |
77 } | 125 } |
78 | 126 |
79 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') | 127 @template_expander.use_jinja('ComputedStyleBaseConstants.h.tmpl') |
80 def generate_base_computed_style_constants(self): | 128 def generate_base_computed_style_constants(self): |
81 return { | 129 return { |
82 'properties': self._properties, | 130 'properties': self._properties, |
83 'enums': self._computed_enums, | 131 'enums': self._computed_enums, |
84 'fields': self._fields, | 132 'fields': self._fields, |
85 } | 133 } |
86 | 134 |
87 if __name__ == '__main__': | 135 if __name__ == '__main__': |
88 in_generator.Maker(ComputedStyleBaseWriter).main(sys.argv) | 136 in_generator.Maker(ComputedStyleBaseWriter).main(sys.argv) |
OLD | NEW |