Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: Source/build/scripts/make_css_property_names.py

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ToTed Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 namespace WTF { 22 namespace WTF {
23 class AtomicString; 23 class AtomicString;
24 class String; 24 class String;
25 } 25 }
26 26
27 namespace blink { 27 namespace blink {
28 28
29 enum CSSPropertyID { 29 enum CSSPropertyID {
30 CSSPropertyInvalid = 0, 30 CSSPropertyInvalid = 0,
31 %(property_enums)s 31 %(property_enums)s
32 CSSPropertyVariable = %(properties_count)s,
32 }; 33 };
33 34
34 const int firstCSSProperty = %(first_property_id)s; 35 const int firstCSSProperty = %(first_property_id)s;
35 const int numCSSProperties = %(properties_count)s; 36 const int numCSSProperties = %(properties_count)s;
36 const int lastCSSProperty = %(last_property_id)d; 37 const int lastCSSProperty = %(last_property_id)d;
37 const int lastUnresolvedCSSProperty = %(last_unresolved_property_id)d; 38 const int lastUnresolvedCSSProperty = %(last_unresolved_property_id)d;
38 const size_t maxCSSPropertyNameLength = %(max_name_length)d; 39 const size_t maxCSSPropertyNameLength = %(max_name_length)d;
39 40
40 const char* getPropertyName(CSSPropertyID); 41 const char* getPropertyName(CSSPropertyID);
41 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); 42 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 186
186 def _enum_declaration(self, property): 187 def _enum_declaration(self, property):
187 return " %(property_id)s = %(enum_value)s," % property 188 return " %(property_id)s = %(enum_value)s," % property
188 189
189 def generate_header(self): 190 def generate_header(self):
190 return HEADER_TEMPLATE % { 191 return HEADER_TEMPLATE % {
191 'license': license.license_for_generated_cpp(), 192 'license': license.license_for_generated_cpp(),
192 'class_name': self.class_name, 193 'class_name': self.class_name,
193 'property_enums': "\n".join(map(self._enum_declaration, self._proper ties_including_aliases)), 194 'property_enums': "\n".join(map(self._enum_declaration, self._proper ties_including_aliases)),
194 'first_property_id': self._first_enum_value, 195 'first_property_id': self._first_enum_value,
195 'properties_count': len(self._properties), 196 'properties_count': len(self._properties) + 1,
alancutter (OOO until 2018) 2015/08/25 01:59:08 Add comment here stating the +1 is for CSSProperty
Timothy Loh 2015/08/25 09:21:09 Err.. this is a bit weird. numCSSProperties now ac
196 'last_property_id': self._first_enum_value + len(self._properties) - 1, 197 'last_property_id': self._first_enum_value + len(self._properties),
197 'last_unresolved_property_id': max(property["enum_value"] for proper ty in self._properties_including_aliases), 198 'last_unresolved_property_id': max(property["enum_value"] for proper ty in self._properties_including_aliases),
198 'max_name_length': max(map(len, self._properties)), 199 'max_name_length': max(map(len, self._properties)),
199 } 200 }
200 201
201 def generate_implementation(self): 202 def generate_implementation(self):
202 enum_value_to_name = {property['enum_value']: property['name'] for prope rty in self._properties_including_aliases} 203 enum_value_to_name = {property['enum_value']: property['name'] for prope rty in self._properties_including_aliases}
203 property_offsets = [] 204 property_offsets = []
204 property_names = [] 205 property_names = []
205 current_offset = 0 206 current_offset = 0
206 for enum_value in range(1, max(enum_value_to_name) + 1): 207 for enum_value in range(1, max(enum_value_to_name) + 1):
(...skipping 15 matching lines...) Expand all
222 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output 223 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output
223 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] 224 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n']
224 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. 225 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts.
225 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. 226 gperf_args.append('-D') # Allow duplicate hashes -> More compact code.
226 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr ocess.PIPE, universal_newlines=True) 227 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr ocess.PIPE, universal_newlines=True)
227 return gperf.communicate(gperf_input)[0] 228 return gperf.communicate(gperf_input)[0]
228 229
229 230
230 if __name__ == "__main__": 231 if __name__ == "__main__":
231 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) 232 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698