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