Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 def __init__(self, json5_file_paths): | 28 def __init__(self, json5_file_paths): |
| 29 super(CSSPropertyAPIWriter, self).__init__(None) | 29 super(CSSPropertyAPIWriter, self).__init__(None) |
| 30 # TODO(aazzam): Move the logic for loading CSSPropertyAPIMethods.json5 i nto a new class APIMethodsWriter(). | 30 # TODO(aazzam): Move the logic for loading CSSPropertyAPIMethods.json5 i nto a new class APIMethodsWriter(). |
| 31 assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 inpu t json5 files files, got %d.' % len(json5_file_paths) | 31 assert len(json5_file_paths) == 2, 'CSSPropertyAPIWriter requires 2 inpu t json5 files files, got %d.' % len(json5_file_paths) |
| 32 | 32 |
| 33 self.css_properties = StyleBuilderWriter([json5_file_paths[0]]) | 33 self.css_properties = StyleBuilderWriter([json5_file_paths[0]]) |
| 34 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa ths[1]], {}, {}) | 34 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa ths[1]], {}, {}) |
| 35 | 35 |
| 36 self._outputs = { | 36 self._outputs = { |
| 37 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, | 37 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, |
| 38 'CSSPropertyAPI.h': self.generate_property_api, | |
| 38 } | 39 } |
| 39 | 40 |
| 40 # Stores a map of API method name -> (return_type, parameters) | 41 # Stores a map of API method name -> (return_type, parameters, comment) |
| 41 self.all_api_methods = {} | 42 self.all_api_methods = {} |
| 42 # Stores an ordered list of all API method names. This must match the | 43 # Stores an ordered list of all API method names. This must match the |
| 43 # order they appear in the Descriptor object. | 44 # order they appear in the Descriptor object. |
| 44 self.ordered_api_method_names = [] | 45 self.ordered_api_method_names = [] |
| 45 ApiMethod = namedtuple('ApiMethod', ('return_type', 'parameters')) | 46 ApiMethod = namedtuple('ApiMethod', ('return_type', 'parameters', 'comme nt')) |
| 46 for api_method in self.css_property_api_methods.name_dictionaries: | 47 for api_method in self.css_property_api_methods.name_dictionaries: |
| 47 self.ordered_api_method_names.append(api_method['name']) | 48 self.ordered_api_method_names.append(api_method['name']) |
| 48 self.all_api_methods[api_method['name']] = ApiMethod( | 49 self.all_api_methods[api_method['name']] = ApiMethod( |
|
sashab
2017/02/10 02:47:09
Add TODO - wrap comment to 72 chars, will do in fo
| |
| 49 return_type=api_method['return_type'], | 50 return_type=api_method['return_type'], |
| 50 parameters=api_method['parameters'], | 51 parameters=api_method['parameters'], |
| 52 comment=api_method['comment'], | |
| 51 ) | 53 ) |
| 52 | 54 |
| 53 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. | 55 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. |
| 54 properties_for_class = defaultdict(list) | 56 properties_for_class = defaultdict(list) |
| 55 # Map of API classname to list of methods implemented by that class. | 57 # Map of API classname to list of methods implemented by that class. |
| 56 self.methods_for_classes = defaultdict(list) | 58 self.methods_for_classes = defaultdict(list) |
| 57 for property in self.css_properties.properties().values(): | 59 for property in self.css_properties.properties().values(): |
| 58 if property['api_class'] is None: | 60 if property['api_class'] is None: |
| 59 continue | 61 continue |
| 60 classname = get_classname(property) | 62 classname = get_classname(property) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 76 methods_for_class=self.methods_for_classes[classname] | 78 methods_for_class=self.methods_for_classes[classname] |
| 77 )) | 79 )) |
| 78 | 80 |
| 79 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | 81 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') |
| 80 def generate_property_descriptor_cpp(self): | 82 def generate_property_descriptor_cpp(self): |
| 81 return { | 83 return { |
| 82 'api_classes': self._api_classes, | 84 'api_classes': self._api_classes, |
| 83 'ordered_api_method_names': self.ordered_api_method_names, | 85 'ordered_api_method_names': self.ordered_api_method_names, |
| 84 } | 86 } |
| 85 | 87 |
| 88 @template_expander.use_jinja('CSSPropertyAPI.h.tmpl') | |
| 89 def generate_property_api(self): | |
| 90 return { | |
| 91 'ordered_api_method_names': self.ordered_api_method_names, | |
| 92 'all_api_methods': self.all_api_methods, | |
| 93 } | |
| 94 | |
| 86 # Provides a function object given the classname of the property. | 95 # Provides a function object given the classname of the property. |
| 87 def generate_property_api_h_builder(self, api_classname): | 96 def generate_property_api_h_builder(self, api_classname): |
| 88 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') | 97 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') |
| 89 def generate_property_api_h(): | 98 def generate_property_api_h(): |
| 90 return { | 99 return { |
| 91 'api_classname': api_classname, | 100 'api_classname': api_classname, |
| 92 'methods_for_class': self.methods_for_classes[api_classname], | 101 'methods_for_class': self.methods_for_classes[api_classname], |
| 93 'all_api_methods': self.all_api_methods, | 102 'all_api_methods': self.all_api_methods, |
| 94 } | 103 } |
| 95 return generate_property_api_h | 104 return generate_property_api_h |
| 96 | 105 |
| 97 if __name__ == '__main__': | 106 if __name__ == '__main__': |
| 98 json5_generator.Maker(CSSPropertyAPIWriter).main() | 107 json5_generator.Maker(CSSPropertyAPIWriter).main() |
| OLD | NEW |