OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import os.path | 3 import os.path |
4 import re | 4 import re |
5 import subprocess | 5 import subprocess |
6 import sys | 6 import sys |
7 | 7 |
8 from in_file import InFile | 8 from in_file import InFile |
9 import in_generator | 9 import in_generator |
10 import license | 10 import license |
11 | 11 |
12 | 12 |
13 HEADER_TEMPLATE = """ | 13 HEADER_TEMPLATE = """ |
14 %(license)s | 14 %(license)s |
15 | 15 |
16 #ifndef %(class_name)s_h | 16 #ifndef %(class_name)s_h |
17 #define %(class_name)s_h | 17 #define %(class_name)s_h |
18 | 18 |
19 #include <string.h> | 19 #include "core/css/CSSParserMode.h" |
20 #include "wtf/HashFunctions.h" | 20 #include "wtf/HashFunctions.h" |
21 #include "wtf/HashTraits.h" | 21 #include "wtf/HashTraits.h" |
| 22 #include <string.h> |
22 | 23 |
23 namespace WTF { | 24 namespace WTF { |
24 class AtomicString; | 25 class AtomicString; |
25 class String; | 26 class String; |
26 } | 27 } |
27 | 28 |
28 namespace WebCore { | 29 namespace WebCore { |
29 | 30 |
30 enum CSSPropertyID { | 31 enum CSSPropertyID { |
31 CSSPropertyInvalid = 0, | 32 CSSPropertyInvalid = 0, |
32 CSSPropertyVariable = 1, | 33 CSSPropertyVariable = 1, |
33 %(property_enums)s | 34 %(property_enums)s |
34 }; | 35 }; |
35 | 36 |
36 const int firstCSSProperty = %(first_property_id)s; | 37 const int firstCSSProperty = %(first_property_id)s; |
37 const int numCSSProperties = %(properties_count)s; | 38 const int numCSSProperties = %(properties_count)s; |
38 const int lastCSSProperty = %(last_property_id)d; | 39 const int lastCSSProperty = %(last_property_id)d; |
39 const size_t maxCSSPropertyNameLength = %(max_name_length)d; | 40 const size_t maxCSSPropertyNameLength = %(max_name_length)d; |
40 | 41 |
41 const char* getPropertyName(CSSPropertyID); | 42 const char* getPropertyName(CSSPropertyID); |
42 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); | 43 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); |
43 WTF::String getPropertyNameString(CSSPropertyID); | 44 WTF::String getPropertyNameString(CSSPropertyID); |
44 WTF::String getJSPropertyName(CSSPropertyID); | 45 WTF::String getJSPropertyName(CSSPropertyID); |
| 46 bool isInternalProperty(CSSPropertyID id); |
45 | 47 |
46 inline CSSPropertyID convertToCSSPropertyID(int value) | 48 inline CSSPropertyID convertToCSSPropertyID(int value) |
47 { | 49 { |
48 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C
SSPropertyInvalid); | 50 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C
SSPropertyInvalid); |
49 return static_cast<CSSPropertyID>(value); | 51 return static_cast<CSSPropertyID>(value); |
50 } | 52 } |
51 | 53 |
52 } // namespace WebCore | 54 } // namespace WebCore |
53 | 55 |
54 namespace WTF { | 56 namespace WTF { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (!nextCharacter) | 158 if (!nextCharacter) |
157 break; | 159 break; |
158 character = (propertyNamePointer - 2 != cssPropertyName) ? toASCIIUp
per(nextCharacter) : nextCharacter; | 160 character = (propertyNamePointer - 2 != cssPropertyName) ? toASCIIUp
per(nextCharacter) : nextCharacter; |
159 } | 161 } |
160 *resultPointer++ = character; | 162 *resultPointer++ = character; |
161 } | 163 } |
162 *resultPointer = '\\0'; | 164 *resultPointer = '\\0'; |
163 return String(result); | 165 return String(result); |
164 } | 166 } |
165 | 167 |
| 168 bool isInternalProperty(CSSPropertyID id) |
| 169 { |
| 170 switch (id) { |
| 171 %(internal_properties)s |
| 172 return true; |
| 173 default: |
| 174 return false; |
| 175 } |
| 176 } |
| 177 |
166 } // namespace WebCore | 178 } // namespace WebCore |
167 """ | 179 """ |
168 | 180 |
169 | 181 |
170 class CSSPropertiesWriter(in_generator.Writer): | 182 class CSSPropertiesWriter(in_generator.Writer): |
171 class_name = "CSSPropertyNames" | 183 class_name = "CSSPropertyNames" |
172 defaults = { | 184 defaults = { |
173 'alias_for': None, | 185 'alias_for': None, |
174 'condition': None, | 186 'condition': None, |
| 187 'is_internal': False, |
175 } | 188 } |
176 | 189 |
177 def __init__(self, file_paths, enabled_conditions): | 190 def __init__(self, file_paths, enabled_conditions): |
178 in_generator.Writer.__init__(self, file_paths, enabled_conditions) | 191 in_generator.Writer.__init__(self, file_paths, enabled_conditions) |
179 self._outputs = {(self.class_name + ".h"): self.generate_header, | 192 self._outputs = {(self.class_name + ".h"): self.generate_header, |
180 (self.class_name + ".cpp"): self.generate_implementatio
n, | 193 (self.class_name + ".cpp"): self.generate_implementatio
n, |
181 } | 194 } |
182 | 195 |
183 all_properties = self.in_file.name_dictionaries | 196 all_properties = self.in_file.name_dictionaries |
184 self._aliases = filter(lambda property: property['alias_for'], all_prope
rties) | 197 self._aliases = filter(lambda property: property['alias_for'], all_prope
rties) |
185 for offset, property in enumerate(self._aliases): | 198 for offset, property in enumerate(self._aliases): |
186 # Aliases use the enum_name that they are an alias for. | 199 # Aliases use the enum_name that they are an alias for. |
187 property['enum_name'] = self._enum_name_from_property_name(property[
'alias_for']) | 200 property['enum_name'] = self._enum_name_from_property_name(property[
'alias_for']) |
188 # Aliases do not get an enum_value. | 201 # Aliases do not get an enum_value. |
189 | 202 |
190 self._properties = filter(lambda property: not property['alias_for'] and
not property['condition'] or property['condition'] in self._enabled_conditions,
all_properties) | 203 self._properties = filter(lambda property: not property['alias_for'] and
not property['condition'] or property['condition'] in self._enabled_conditions,
all_properties) |
191 if len(self._properties) > 1024: | 204 if len(self._properties) > 1024: |
192 print "ERROR : There is more than 1024 CSS Properties, you need to u
pdate CSSProperty.h/StylePropertyMetadata m_propertyID accordingly." | 205 print "ERROR : There is more than 1024 CSS Properties, you need to u
pdate CSSProperty.h/StylePropertyMetadata m_propertyID accordingly." |
193 exit(1) | 206 exit(1) |
194 self._first_property_id = 2 # We start after CSSPropertyInvalid and CSS
PropertyVariable. | 207 self._first_property_id = 2 # We start after CSSPropertyInvalid and CSS
PropertyVariable. |
195 property_id = self._first_property_id | 208 property_id = self._first_property_id |
196 for offset, property in enumerate(self._properties): | 209 for offset, property in enumerate(self._properties): |
197 property['enum_name'] = self._enum_name_from_property_name(property[
'name']) | 210 property['enum_name'] = self._enum_name_from_property_name(property[
'name']) |
198 property['enum_value'] = self._first_property_id + offset | 211 property['enum_value'] = self._first_property_id + offset |
| 212 if property['name'].startswith('-internal-'): |
| 213 property['is_internal'] = True |
199 | 214 |
200 def _enum_name_from_property_name(self, property_name): | 215 def _enum_name_from_property_name(self, property_name): |
201 return "CSSProperty" + re.sub(r'(^[^-])|-(.)', lambda match: (match.grou
p(1) or match.group(2)).upper(), property_name) | 216 return "CSSProperty" + re.sub(r'(^[^-])|-(.)', lambda match: (match.grou
p(1) or match.group(2)).upper(), property_name) |
202 | 217 |
203 def _enum_declaration(self, property): | 218 def _enum_declaration(self, property): |
204 return " %(enum_name)s = %(enum_value)s," % property | 219 return " %(enum_name)s = %(enum_value)s," % property |
205 | 220 |
206 def generate_header(self): | 221 def generate_header(self): |
207 return HEADER_TEMPLATE % { | 222 return HEADER_TEMPLATE % { |
208 'license': license.license_for_generated_cpp(), | 223 'license': license.license_for_generated_cpp(), |
209 'class_name': self.class_name, | 224 'class_name': self.class_name, |
210 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties)), | 225 'property_enums': "\n".join(map(self._enum_declaration, self._proper
ties)), |
211 'first_property_id': self._first_property_id, | 226 'first_property_id': self._first_property_id, |
212 'properties_count': len(self._properties), | 227 'properties_count': len(self._properties), |
213 'last_property_id': self._first_property_id + len(self._properties)
- 1, | 228 'last_property_id': self._first_property_id + len(self._properties)
- 1, |
214 'max_name_length': reduce(max, map(len, map(lambda property: propert
y['name'], self._properties))), | 229 'max_name_length': reduce(max, map(len, map(lambda property: propert
y['name'], self._properties))), |
215 } | 230 } |
216 | 231 |
| 232 def _case_properties(self, property): |
| 233 return "case %(enum_name)s:" % property |
| 234 |
217 def generate_implementation(self): | 235 def generate_implementation(self): |
218 property_offsets = [] | 236 property_offsets = [] |
219 current_offset = 0 | 237 current_offset = 0 |
220 for property in self._properties: | 238 for property in self._properties: |
221 property_offsets.append(current_offset) | 239 property_offsets.append(current_offset) |
222 current_offset += len(property["name"]) + 1 | 240 current_offset += len(property["name"]) + 1 |
223 | 241 |
224 gperf_input = GPERF_TEMPLATE % { | 242 gperf_input = GPERF_TEMPLATE % { |
225 'license': license.license_for_generated_cpp(), | 243 'license': license.license_for_generated_cpp(), |
226 'class_name': self.class_name, | 244 'class_name': self.class_name, |
227 'property_name_strings': '\n'.join(map(lambda property: ' "%(name
)s\\0"' % property, self._properties)), | 245 'property_name_strings': '\n'.join(map(lambda property: ' "%(name
)s\\0"' % property, self._properties)), |
228 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of
fset, property_offsets)), | 246 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of
fset, property_offsets)), |
229 'property_to_enum_map': '\n'.join(map(lambda property: '%(name)s, %(
enum_name)s' % property, self._properties + self._aliases)), | 247 'property_to_enum_map': '\n'.join(map(lambda property: '%(name)s, %(
enum_name)s' % property, self._properties + self._aliases)), |
| 248 'internal_properties': '\n'.join(map(self._case_properties, filter(l
ambda property: property['is_internal'], self._properties))), |
230 } | 249 } |
231 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 250 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
232 gperf_args = ['gperf', '--key-positions=*', '-P', '-D', '-n', '-s', '2'] | 251 gperf_args = ['gperf', '--key-positions=*', '-P', '-D', '-n', '-s', '2'] |
233 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE) | 252 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE) |
234 return gperf.communicate(gperf_input)[0] | 253 return gperf.communicate(gperf_input)[0] |
235 | 254 |
236 | 255 |
237 if __name__ == "__main__": | 256 if __name__ == "__main__": |
238 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) | 257 in_generator.Maker(CSSPropertiesWriter).main(sys.argv) |
OLD | NEW |