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 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): | 25 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): |
26 def __init__(self, json5_file_path): | 26 def __init__(self, json5_file_path): |
27 super(CSSPropertyAPIWriter, self).__init__(json5_file_path) | 27 super(CSSPropertyAPIWriter, self).__init__(json5_file_path) |
28 self._outputs = { | 28 self._outputs = { |
29 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, | 29 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, |
30 } | 30 } |
31 | 31 |
32 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. | 32 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. |
33 properties_for_class = defaultdict(list) | 33 properties_for_class = defaultdict(list) |
34 api_methods_for_class = defaultdict(set) | |
sashab
2017/02/01 17:50:19
# Temporary map of API classname -> list of method
aazzam
2017/02/01 22:33:15
done :)
| |
34 for property in self._properties.values(): | 35 for property in self._properties.values(): |
35 if property['api_class'] is None: | 36 if property['api_class'] is None: |
36 continue | 37 continue |
37 classname = get_classname(property) | 38 classname = get_classname(property) |
39 api_methods_for_class[classname].update(property['api_methods']) | |
sashab
2017/02/01 17:50:19
api_methods_for_class[classname] = property['api_m
aazzam
2017/02/01 22:33:15
done :)
| |
38 properties_for_class[classname].append(property['property_id']) | 40 properties_for_class[classname].append(property['property_id']) |
39 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, property['api_methods']) | 41 self._outputs[classname + '.h'] = self.generate_property_api_h_build er(classname, property['api_methods']) |
40 | 42 |
41 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]). | 43 # Stores a list of classes with elements (index, classname, [propertyIDs , ..], api_methods). |
sashab
2017/02/01 17:50:19
[api_methods, ...]
aazzam
2017/02/01 22:33:15
done :)
| |
42 self._api_classes = [] | 44 self._api_classes = [] |
43 | 45 |
44 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') ) | 46 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids', 'api_methods')) |
45 for i, classname in enumerate(properties_for_class.keys()): | 47 for i, classname in enumerate(properties_for_class.keys()): |
46 self._api_classes.append(ApiClass( | 48 self._api_classes.append(ApiClass( |
47 index=i + 1, | 49 index=i + 1, |
48 classname=classname, | 50 classname=classname, |
49 property_ids=properties_for_class[classname] | 51 property_ids=properties_for_class[classname], |
52 api_methods=api_methods_for_class[classname], | |
50 )) | 53 )) |
51 | 54 |
52 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | 55 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') |
53 def generate_property_descriptor_cpp(self): | 56 def generate_property_descriptor_cpp(self): |
54 return { | 57 return { |
55 'api_classes': self._api_classes, | 58 'api_classes': self._api_classes, |
59 'api_methods': self.json5_file.parameters["api_methods"]["valid_valu es"], | |
sashab
2017/02/01 17:50:19
Single quotes for strings
aazzam
2017/02/01 22:33:15
fixed :)
| |
56 } | 60 } |
57 | 61 |
58 # Provides a function object given the classname of the property. | 62 # Provides a function object given the classname of the property. |
59 # This returned function generates a .h file for the specified property. | |
60 def generate_property_api_h_builder(self, api_classname, api_methods): | 63 def generate_property_api_h_builder(self, api_classname, api_methods): |
61 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') | 64 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') |
62 def generate_property_api_h(): | 65 def generate_property_api_h(): |
63 return { | 66 return { |
64 'api_classname': api_classname, | 67 'api_classname': api_classname, |
65 'api_methods': api_methods, | 68 'api_methods': api_methods, |
66 } | 69 } |
67 return generate_property_api_h | 70 return generate_property_api_h |
68 | 71 |
69 if __name__ == '__main__': | 72 if __name__ == '__main__': |
70 json5_generator.Maker(CSSPropertyAPIWriter).main() | 73 json5_generator.Maker(CSSPropertyAPIWriter).main() |
OLD | NEW |