OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import subprocess | 3 import subprocess |
4 import sys | 4 import sys |
5 | 5 |
6 import css_properties | 6 import css_properties |
7 import in_generator | 7 import in_generator |
8 import license | 8 import license |
9 | 9 |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 %%%% | 108 %%%% |
109 %(property_to_enum_map)s | 109 %(property_to_enum_map)s |
110 %%%% | 110 %%%% |
111 const Property* findProperty(register const char* str, register unsigned int len
) | 111 const Property* findProperty(register const char* str, register unsigned int len
) |
112 { | 112 { |
113 return %(class_name)sHash::findPropertyImpl(str, len); | 113 return %(class_name)sHash::findPropertyImpl(str, len); |
114 } | 114 } |
115 | 115 |
116 const char* getPropertyName(CSSPropertyID id) | 116 const char* getPropertyName(CSSPropertyID id) |
117 { | 117 { |
118 if (id < firstCSSProperty) | 118 ASSERT(id >= firstCSSProperty && id <= lastUnresolvedCSSProperty); |
119 return 0; | |
120 int index = id - firstCSSProperty; | 119 int index = id - firstCSSProperty; |
121 if (index >= numCSSProperties) | |
122 return 0; | |
123 return propertyNameStringsPool + propertyNameStringsOffsets[index]; | 120 return propertyNameStringsPool + propertyNameStringsOffsets[index]; |
124 } | 121 } |
125 | 122 |
126 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) | 123 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) |
127 { | 124 { |
128 if (id < firstCSSProperty) | 125 ASSERT(id >= firstCSSProperty && id <= lastUnresolvedCSSProperty); |
129 return nullAtom; | |
130 int index = id - firstCSSProperty; | 126 int index = id - firstCSSProperty; |
131 if (index >= numCSSProperties) | 127 static AtomicString* propertyStrings = new AtomicString[lastUnresolvedCSSPro
perty]; // Intentionally never destroyed. |
132 return nullAtom; | |
133 | |
134 static AtomicString* propertyStrings = new AtomicString[numCSSProperties]; /
/ Intentionally never destroyed. | |
135 AtomicString& propertyString = propertyStrings[index]; | 128 AtomicString& propertyString = propertyStrings[index]; |
136 if (propertyString.isNull()) { | 129 if (propertyString.isNull()) { |
137 const char* propertyName = propertyNameStringsPool + propertyNameStrings
Offsets[index]; | 130 const char* propertyName = propertyNameStringsPool + propertyNameStrings
Offsets[index]; |
138 propertyString = AtomicString(propertyName, strlen(propertyName), Atomic
String::ConstructFromLiteral); | 131 propertyString = AtomicString(propertyName, strlen(propertyName), Atomic
String::ConstructFromLiteral); |
139 } | 132 } |
140 return propertyString; | 133 return propertyString; |
141 } | 134 } |
142 | 135 |
143 String getPropertyNameString(CSSPropertyID id) | 136 String getPropertyNameString(CSSPropertyID id) |
144 { | 137 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 'class_name': self.class_name, | 183 'class_name': self.class_name, |
191 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties_including_aliases)), | 184 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties_including_aliases)), |
192 'first_property_id': self._first_enum_value, | 185 'first_property_id': self._first_enum_value, |
193 'properties_count': len(self._properties), | 186 'properties_count': len(self._properties), |
194 'last_property_id': self._first_enum_value + len(self._properties) -
1, | 187 'last_property_id': self._first_enum_value + len(self._properties) -
1, |
195 'last_unresolved_property_id': max(property["enum_value"] for proper
ty in self._properties_including_aliases), | 188 'last_unresolved_property_id': max(property["enum_value"] for proper
ty in self._properties_including_aliases), |
196 'max_name_length': max(map(len, self._properties)), | 189 'max_name_length': max(map(len, self._properties)), |
197 } | 190 } |
198 | 191 |
199 def generate_implementation(self): | 192 def generate_implementation(self): |
| 193 enum_value_to_name = {property['enum_value']: property['name'] for prope
rty in self._properties_including_aliases} |
200 property_offsets = [] | 194 property_offsets = [] |
| 195 property_names = [] |
201 current_offset = 0 | 196 current_offset = 0 |
202 for property in self._properties_including_aliases: | 197 for enum_value in range(1, max(enum_value_to_name) + 1): |
203 property_offsets.append(current_offset) | 198 property_offsets.append(current_offset) |
204 current_offset += len(property["name"]) + 1 | 199 if enum_value in enum_value_to_name: |
| 200 name = enum_value_to_name[enum_value] |
| 201 property_names.append(name) |
| 202 current_offset += len(name) + 1 |
205 | 203 |
206 css_name_and_enum_pairs = [(property['name'], property['property_id']) f
or property in self._properties_including_aliases] | 204 css_name_and_enum_pairs = [(property['name'], property['property_id']) f
or property in self._properties_including_aliases] |
207 | 205 |
208 gperf_input = GPERF_TEMPLATE % { | 206 gperf_input = GPERF_TEMPLATE % { |
209 'license': license.license_for_generated_cpp(), | 207 'license': license.license_for_generated_cpp(), |
210 'class_name': self.class_name, | 208 'class_name': self.class_name, |
211 'property_name_strings': '\n'.join(map(lambda property: ' "%(name
)s\\0"' % property, self._properties_including_aliases)), | 209 'property_name_strings': '\n'.join(' "%s\\0"' % name for name in
property_names), |
212 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of
fset, property_offsets)), | 210 'property_name_offsets': '\n'.join(' %d,' % offset for offset in
property_offsets), |
213 'property_to_enum_map': '\n'.join(map(lambda property: '%s, %s' % pr
operty, css_name_and_enum_pairs)), | 211 'property_to_enum_map': '\n'.join('%s, %s' % property for property i
n css_name_and_enum_pairs), |
214 } | 212 } |
215 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 213 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
216 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 214 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
217 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 215 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
218 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 216 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
219 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) | 217 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) |
220 return gperf.communicate(gperf_input)[0] | 218 return gperf.communicate(gperf_input)[0] |
221 | 219 |
222 | 220 |
223 if __name__ == "__main__": | 221 if __name__ == "__main__": |
224 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) | 222 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) |
OLD | NEW |