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

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

Issue 1096963002: Make UseCounters work on aliased properties (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
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 16 matching lines...) Expand all
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 }; 32 };
33 33
34 const int firstCSSProperty = %(first_property_id)s; 34 const int firstCSSProperty = %(first_property_id)s;
35 const int numCSSProperties = %(properties_count)s; 35 const int numCSSProperties = %(properties_count)s;
36 const int lastCSSProperty = %(last_property_id)d; 36 const int lastCSSProperty = %(last_property_id)d;
37 const int lastUnresolvedCSSProperty = %(last_unresolved_property_id)d;
37 const size_t maxCSSPropertyNameLength = %(max_name_length)d; 38 const size_t maxCSSPropertyNameLength = %(max_name_length)d;
38 39
39 const char* getPropertyName(CSSPropertyID); 40 const char* getPropertyName(CSSPropertyID);
40 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); 41 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID);
41 WTF::String getPropertyNameString(CSSPropertyID); 42 WTF::String getPropertyNameString(CSSPropertyID);
42 WTF::String getJSPropertyName(CSSPropertyID); 43 WTF::String getJSPropertyName(CSSPropertyID);
43 44
44 inline CSSPropertyID convertToCSSPropertyID(int value) 45 inline CSSPropertyID convertToCSSPropertyID(int value)
45 { 46 {
46 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C SSPropertyInvalid); 47 ASSERT((value >= firstCSSProperty && value <= lastCSSProperty) || value == C SSPropertyInvalid);
47 return static_cast<CSSPropertyID>(value); 48 return static_cast<CSSPropertyID>(value);
48 } 49 }
49 50
51 inline CSSPropertyID resolveCSSPropertyID(CSSPropertyID id)
52 {
53 return convertToCSSPropertyID(id & ~512);
54 }
55
56 inline bool isPropertyAlias(CSSPropertyID id) { return id & 512; }
57
50 } // namespace blink 58 } // namespace blink
51 59
52 namespace WTF { 60 namespace WTF {
53 template<> struct DefaultHash<blink::CSSPropertyID> { typedef IntHash<unsigned> Hash; }; 61 template<> struct DefaultHash<blink::CSSPropertyID> { typedef IntHash<unsigned> Hash; };
54 template<> struct HashTraits<blink::CSSPropertyID> : GenericHashTraits<blink::CS SPropertyID> { 62 template<> struct HashTraits<blink::CSSPropertyID> : GenericHashTraits<blink::CS SPropertyID> {
55 static const bool emptyValueIsZero = true; 63 static const bool emptyValueIsZero = true;
56 static void constructDeletedValue(blink::CSSPropertyID& slot, bool) { slot = static_cast<blink::CSSPropertyID>(blink::lastCSSProperty + 1); } 64 static void constructDeletedValue(blink::CSSPropertyID& slot, bool) { slot = static_cast<blink::CSSPropertyID>(blink::lastUnresolvedCSSProperty + 1); }
57 static bool isDeletedValue(blink::CSSPropertyID value) { return value == (bl ink::lastCSSProperty + 1); } 65 static bool isDeletedValue(blink::CSSPropertyID value) { return value == (bl ink::lastUnresolvedCSSProperty + 1); }
58 }; 66 };
59 } 67 }
60 68
61 #endif // %(class_name)s_h 69 #endif // %(class_name)s_h
62 """ 70 """
63 71
64 GPERF_TEMPLATE = """ 72 GPERF_TEMPLATE = """
65 %%{ 73 %%{
66 %(license)s 74 %(license)s
67 75
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 (self.class_name + ".cpp"): self.generate_implementatio n, 181 (self.class_name + ".cpp"): self.generate_implementatio n,
174 } 182 }
175 183
176 def _enum_declaration(self, property): 184 def _enum_declaration(self, property):
177 return " %(property_id)s = %(enum_value)s," % property 185 return " %(property_id)s = %(enum_value)s," % property
178 186
179 def generate_header(self): 187 def generate_header(self):
180 return HEADER_TEMPLATE % { 188 return HEADER_TEMPLATE % {
181 'license': license.license_for_generated_cpp(), 189 'license': license.license_for_generated_cpp(),
182 'class_name': self.class_name, 190 'class_name': self.class_name,
183 'property_enums': "\n".join(map(self._enum_declaration, self._proper ties_list)), 191 'property_enums': "\n".join(map(self._enum_declaration, self._proper ties_including_aliases)),
184 'first_property_id': self._first_enum_value, 192 'first_property_id': self._first_enum_value,
185 'properties_count': len(self._properties), 193 'properties_count': len(self._properties),
186 'last_property_id': self._first_enum_value + len(self._properties) - 1, 194 '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),
187 'max_name_length': max(map(len, self._properties)), 196 'max_name_length': max(map(len, self._properties)),
188 } 197 }
189 198
190 def generate_implementation(self): 199 def generate_implementation(self):
191 property_offsets = [] 200 property_offsets = []
192 current_offset = 0 201 current_offset = 0
193 for property in self._properties_list: 202 for property in self._properties_including_aliases:
194 property_offsets.append(current_offset) 203 property_offsets.append(current_offset)
195 current_offset += len(property["name"]) + 1 204 current_offset += len(property["name"]) + 1
196 205
197 css_name_and_enum_pairs = [(property['name'], property_id) for property_ id, property in self._properties.items()] 206 css_name_and_enum_pairs = [(property['name'], property['property_id']) f or property in self._properties_including_aliases]
198 for name, aliased_name in self._aliases.items():
199 css_name_and_enum_pairs.append((name, css_properties.css_name_to_enu m(aliased_name)))
200 207
201 gperf_input = GPERF_TEMPLATE % { 208 gperf_input = GPERF_TEMPLATE % {
202 'license': license.license_for_generated_cpp(), 209 'license': license.license_for_generated_cpp(),
203 'class_name': self.class_name, 210 'class_name': self.class_name,
204 'property_name_strings': '\n'.join(map(lambda property: ' "%(name )s\\0"' % property, self._properties_list)), 211 'property_name_strings': '\n'.join(map(lambda property: ' "%(name )s\\0"' % property, self._properties_including_aliases)),
205 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of fset, property_offsets)), 212 'property_name_offsets': '\n'.join(map(lambda offset: ' %d,' % of fset, property_offsets)),
206 'property_to_enum_map': '\n'.join(map(lambda property: '%s, %s' % pr operty, css_name_and_enum_pairs)), 213 'property_to_enum_map': '\n'.join(map(lambda property: '%s, %s' % pr operty, css_name_and_enum_pairs)),
207 } 214 }
208 # 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
209 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] 216 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n']
210 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. 217 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts.
211 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. 218 gperf_args.append('-D') # Allow duplicate hashes -> More compact code.
212 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)
213 return gperf.communicate(gperf_input)[0] 220 return gperf.communicate(gperf_input)[0]
214 221
215 222
216 if __name__ == "__main__": 223 if __name__ == "__main__":
217 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) 224 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « Source/build/scripts/css_properties.py ('k') | Source/build/scripts/templates/CSSPropertyMetadata.cpp.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698