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

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

Issue 2669243009: Added CSSPropertyAPIMethods.json5 which defines all API methods. (Closed)
Patch Set: renames and formatting Created 3 years, 10 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 # 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 json5_generator 8 import json5_generator
9 import template_expander 9 import template_expander
10 import make_style_builder 10 import make_style_builder
11 11
12 from collections import namedtuple, defaultdict 12 from collections import namedtuple, defaultdict
13 from json5_generator import Json5File
14 from make_style_builder import StyleBuilderWriter
13 15
14 # Gets the classname for a given property. 16 # Gets the classname for a given property.
15 def get_classname(property): 17 def get_classname(property):
16 if property['api_class'] is True: 18 if property['api_class'] is True:
17 # This property had the generated_api_class flag set in CSSProperties.js on5. 19 # This property had the generated_api_class flag set in CSSProperties.js on5.
18 return 'CSSPropertyAPI' + property['upper_camel_name'] 20 return 'CSSPropertyAPI' + property['upper_camel_name']
19 # This property has a specified class name. 21 # This property has a specified class name.
20 assert isinstance(property['api_class'], str), \ 22 assert isinstance(property['api_class'], str), \
21 ("api_class value for " + property['api_class'] + " should be None, True or a string") 23 ("api_class value for " + property['api_class'] + " should be None, True or a string")
22 return property['api_class'] 24 return property['api_class']
23 25
24 26
25 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): 27 class CSSPropertyAPIWriter(json5_generator.Writer):
26 def __init__(self, json5_file_path): 28 def __init__(self, json5_file_paths):
27 super(CSSPropertyAPIWriter, self).__init__(json5_file_path) 29 super(CSSPropertyAPIWriter, self).__init__(None)
30 assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 inpu t json5 files files, got %d.' % len(json5_file_paths)
31
32 self.css_properties = StyleBuilderWriter([json5_file_paths[0]])
33 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa ths[1]], {}, {})
sashab 2017/02/09 04:57:51 #TODO(azzaam): Move the logic for loading CSSPrope
aazzam 2017/02/09 23:10:12 done :)
34
28 self._outputs = { 35 self._outputs = {
29 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, 36 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp,
30 } 37 }
31 38
39 # Stores a map of API method name -> (signature, function_ptr)
40 self.all_api_methods = {}
41 ApiMethod = namedtuple('ApiMethod', ('signature', 'function_ptr'))
42 for api_method in self.css_property_api_methods.name_dictionaries:
43 self.all_api_methods[api_method['name']] = ApiMethod(
44 signature=api_method['signature'],
45 function_ptr=api_method['function_ptr'],
46 )
47
48 # Stores an ORDERED list of all API method names. This must match the
49 # order they appear in the Descriptor object.
50 self.all_api_method_names = [api_method['name'] for api_method in self.c ss_property_api_methods.name_dictionaries]
sashab 2017/02/09 04:57:51 Build this up in the previous for loop, rather tha
aazzam 2017/02/09 23:10:12 done :)
51
32 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. 52 # Temporary map of API classname to list of propertyIDs that the API cla ss is for.
33 properties_for_class = defaultdict(list) 53 properties_for_class = defaultdict(list)
34 # Temporary map of API classname to set of method names this API class i mplements 54 # Map of API classname to list of methods implemented in the API.
sashab 2017/02/09 04:57:51 # Map of API classname to list of methods implemen
aazzam 2017/02/09 23:10:12 added :)
35 api_methods_for_class = defaultdict(set) 55 self.methods_for_classes = defaultdict(list)
36 for property in self._properties.values(): 56 for property in self.css_properties.properties().values():
37 if property['api_class'] is None: 57 if property['api_class'] is None:
38 continue 58 continue
39 classname = get_classname(property) 59 classname = get_classname(property)
40 api_methods_for_class[classname] = property['api_methods']
41 properties_for_class[classname].append(property['property_id']) 60 properties_for_class[classname].append(property['property_id'])
42 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, property['api_methods']) 61 self.methods_for_classes[classname] += property['api_methods']
62 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname)
43 63
44 # Stores a list of classes with elements (index, classname, [propertyIDs , ..], [api_methods, ...]). 64 # Stores a list of classes with elements (index, classname, [propertyIDs , ..], [api_methods, ...]).
45 self._api_classes = [] 65 self._api_classes = []
46 66 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids', 'methods_for_class'))
47 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids', 'api_methods'))
48 for i, classname in enumerate(properties_for_class.keys()): 67 for i, classname in enumerate(properties_for_class.keys()):
49 self._api_classes.append(ApiClass( 68 self._api_classes.append(ApiClass(
50 index=i + 1, 69 index=i + 1,
51 classname=classname, 70 classname=classname,
52 property_ids=properties_for_class[classname], 71 property_ids=properties_for_class[classname],
53 api_methods=api_methods_for_class[classname], 72 methods_for_class=self.methods_for_classes[classname]
54 )) 73 ))
55 74
56 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') 75 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl')
57 def generate_property_descriptor_cpp(self): 76 def generate_property_descriptor_cpp(self):
58 return { 77 return {
59 'api_classes': self._api_classes, 78 'api_classes': self._api_classes,
60 'api_methods': self.json5_file.parameters['api_methods']['valid_valu es'], 79 'all_api_method_names': self.all_api_method_names,
61 } 80 }
62 81
63 # Provides a function object given the classname of the property. 82 # Provides a function object given the classname of the property.
64 def generate_property_api_h_builder(self, api_classname, api_methods): 83 def generate_property_api_h_builder(self, api_classname):
65 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') 84 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl')
66 def generate_property_api_h(): 85 def generate_property_api_h():
67 return { 86 return {
68 'api_classname': api_classname, 87 'api_classname': api_classname,
69 'api_methods': api_methods, 88 'methods_for_class': self.methods_for_classes[api_classname],
89 'all_api_methods': self.all_api_methods,
70 } 90 }
71 return generate_property_api_h 91 return generate_property_api_h
72 92
73 if __name__ == '__main__': 93 if __name__ == '__main__':
74 json5_generator.Maker(CSSPropertyAPIWriter).main() 94 json5_generator.Maker(CSSPropertyAPIWriter).main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698