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

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_css_property_api.py

Issue 2578773002: Made a generator for .h files for implementations of CSSPropertyAPI.h (Closed)
Patch Set: Created 4 years 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 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import sys 6 import sys
7 7
8 import in_generator 8 import in_generator
9 import template_expander 9 import template_expander
10 import make_style_builder 10 import make_style_builder
(...skipping 16 matching lines...) Expand all
27 def __init__(self, in_file_path): 27 def __init__(self, in_file_path):
28 super(CSSPropertyAPIWriter, self).__init__(in_file_path) 28 super(CSSPropertyAPIWriter, self).__init__(in_file_path)
29 self._outputs = { 29 self._outputs = {
30 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, 30 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp,
31 } 31 }
32 32
33 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. 33 # Temporary map of API classname to list of propertyIDs that the API cla ss is for.
34 properties_for_class = defaultdict(list) 34 properties_for_class = defaultdict(list)
35 for property in self._properties.values(): 35 for property in self._properties.values():
36 if property['api_class'] is None: 36 if property['api_class'] is None:
37 continue 37 continue
sashab 2016/12/15 02:48:42 Small thing - in your CL description, avoid 'we',
aazzam 2016/12/15 04:35:07 done :)
38 classname = get_classname(property) 38 classname = get_classname(property)
sashab 2016/12/15 02:48:43 Also this file - because it generates both, maybe:
aazzam 2016/12/15 04:35:07 I've gone with make_css_property_apis.py, sounds O
39 properties_for_class[classname].append(property['property_id']) 39 properties_for_class[classname].append(property['property_id'])
40 self._outputs.update({classname + '.h': self.generate_property_api_h _builder(classname)})
sashab 2016/12/15 02:48:43 You don't need .update - you can just set [key] =
aazzam 2016/12/15 04:35:07 done :)
40 41
41 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]). 42 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]).
42 self._api_classes = [] 43 self._api_classes = []
43 44
44 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') ) 45 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') )
45 for i, classname in enumerate(properties_for_class.keys()): 46 for i, classname in enumerate(properties_for_class.keys()):
46 self._api_classes.append(ApiClass( 47 self._api_classes.append(ApiClass(
47 index=i + 1, 48 index=i + 1,
48 classname=classname, 49 classname=classname,
49 property_ids=properties_for_class[classname] 50 property_ids=properties_for_class[classname]
50 )) 51 ))
51 52
52 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') 53 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl')
53 def generate_property_descriptor_cpp(self): 54 def generate_property_descriptor_cpp(self):
54 return { 55 return {
55 'api_classes': self._api_classes, 56 'api_classes': self._api_classes,
56 } 57 }
57 58
59 # The self._outputs dict requires a function pointer to a generation functio n for
60 # each .h file. This generation function is different depending on which pro perty
61 # group we are generating a .h file for. Therefore we have generate_api_func tion
62 # which generates a new function pointer given the classname and property id s.
sashab 2016/12/15 02:48:42 Great comment, except one nit: 'function pointer'
aazzam 2016/12/15 04:35:07 re-worded it, does this sound better?
63 def generate_property_api_h_builder(self, api_classname):
64 @template_expander.use_jinja('CSSPropertyAPI.h.tmpl')
65 def generate_property_api_h():
66 return {
67 'api_classname': api_classname,
68 }
69 return generate_property_api_h
70
58 if __name__ == '__main__': 71 if __name__ == '__main__':
59 in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv) 72 in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698