OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 def __init__(self, in_file_paths): | 57 def __init__(self, in_file_paths): |
58 super(MakeElementFactoryWriter, self).__init__(in_file_paths) | 58 super(MakeElementFactoryWriter, self).__init__(in_file_paths) |
59 | 59 |
60 # FIXME: When we start using these element factories, we'll want to | 60 # FIXME: When we start using these element factories, we'll want to |
61 # remove the "new" prefix and also have our base class generate | 61 # remove the "new" prefix and also have our base class generate |
62 # *Names.h and *Names.cpp. | 62 # *Names.h and *Names.cpp. |
63 self._outputs.update({ | 63 self._outputs.update({ |
64 (self.namespace + 'ElementFactory.h'): self.generate_factory_header, | 64 (self.namespace + 'ElementFactory.h'): self.generate_factory_header, |
65 (self.namespace + 'ElementFactory.cpp'): self.generate_factory_imple
mentation, | 65 (self.namespace + 'ElementFactory.cpp'): self.generate_factory_imple
mentation, |
66 ('V8' + self.namespace + 'ElementWrapperFactory.h'): self.generate_w
rapper_factory_header, | |
67 ('V8' + self.namespace + 'ElementWrapperFactory.cpp'): self.generate
_wrapper_factory_implementation, | |
68 }) | 66 }) |
69 | 67 |
70 fallback_interface = self.tags_in_file.parameters['fallbackInterfaceName
'].strip('"') | 68 fallback_interface = self.tags_in_file.parameters['fallbackInterfaceName
'].strip('"') |
71 fallback_js_interface = self.tags_in_file.parameters['fallbackJSInterfac
eName'].strip('"') or fallback_interface | 69 fallback_js_interface = self.tags_in_file.parameters['fallbackJSInterfac
eName'].strip('"') or fallback_interface |
72 | 70 |
73 interface_counts = defaultdict(int) | 71 interface_counts = defaultdict(int) |
74 tags = self._template_context['tags'] | 72 tags = self._template_context['tags'] |
75 for tag in tags: | 73 for tag in tags: |
76 tag['has_js_interface'] = self._has_js_interface(tag) | 74 tag['has_js_interface'] = self._has_js_interface(tag) |
77 tag['js_interface'] = self._js_interface(tag) | 75 tag['js_interface'] = self._js_interface(tag) |
78 tag['interface'] = self._interface(tag) | 76 tag['interface'] = self._interface(tag) |
79 interface_counts[tag['interface']] += 1 | 77 interface_counts[tag['interface']] += 1 |
80 | 78 |
81 for tag in tags: | 79 for tag in tags: |
82 tag['multipleTagNames'] = (interface_counts[tag['interface']] > 1 or
tag['interface'] == fallback_interface) | 80 tag['multipleTagNames'] = (interface_counts[tag['interface']] > 1 or
tag['interface'] == fallback_interface) |
83 | 81 |
84 self._template_context.update({ | 82 self._template_context.update({ |
85 'fallback_interface': fallback_interface, | 83 'fallback_interface': fallback_interface, |
86 'fallback_js_interface': fallback_js_interface, | 84 'fallback_js_interface': fallback_js_interface, |
87 }) | 85 }) |
88 | 86 |
89 @template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters) | 87 @template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters) |
90 def generate_factory_header(self): | 88 def generate_factory_header(self): |
91 return self._template_context | 89 return self._template_context |
92 | 90 |
93 @template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters) | 91 @template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters) |
94 def generate_factory_implementation(self): | 92 def generate_factory_implementation(self): |
95 return self._template_context | 93 return self._template_context |
96 | 94 |
97 @template_expander.use_jinja('ElementWrapperFactory.h.tmpl', filters=filters
) | |
98 def generate_wrapper_factory_header(self): | |
99 return self._template_context | |
100 | |
101 @template_expander.use_jinja('ElementWrapperFactory.cpp.tmpl', filters=filte
rs) | |
102 def generate_wrapper_factory_implementation(self): | |
103 return self._template_context | |
104 | |
105 def _interface(self, tag): | 95 def _interface(self, tag): |
106 if tag['interfaceName']: | 96 if tag['interfaceName']: |
107 return tag['interfaceName'] | 97 return tag['interfaceName'] |
108 name = name_utilities.upper_first(tag['name']) | 98 name = name_utilities.upper_first(tag['name']) |
109 # FIXME: We shouldn't hard-code HTML here. | 99 # FIXME: We shouldn't hard-code HTML here. |
110 if name == 'HTML': | 100 if name == 'HTML': |
111 name = 'Html' | 101 name = 'Html' |
112 dash = name.find('-') | 102 dash = name.find('-') |
113 while dash != -1: | 103 while dash != -1: |
114 name = name[:dash] + name[dash + 1].upper() + name[dash + 2:] | 104 name = name[:dash] + name[dash + 1].upper() + name[dash + 2:] |
115 dash = name.find('-') | 105 dash = name.find('-') |
116 return '%s%sElement' % (self.namespace, name) | 106 return '%s%sElement' % (self.namespace, name) |
117 | 107 |
118 def _js_interface(self, tag): | 108 def _js_interface(self, tag): |
119 if tag['JSInterfaceName']: | 109 if tag['JSInterfaceName']: |
120 return tag['JSInterfaceName'] | 110 return tag['JSInterfaceName'] |
121 return self._interface(tag) | 111 return self._interface(tag) |
122 | 112 |
123 def _has_js_interface(self, tag): | 113 def _has_js_interface(self, tag): |
124 return not tag['noConstructor'] and self._js_interface(tag) != ('%sEleme
nt' % self.namespace) | 114 return not tag['noConstructor'] and self._js_interface(tag) != ('%sEleme
nt' % self.namespace) |
125 | 115 |
126 | 116 |
127 if __name__ == "__main__": | 117 if __name__ == "__main__": |
128 in_generator.Maker(MakeElementFactoryWriter).main(sys.argv) | 118 in_generator.Maker(MakeElementFactoryWriter).main(sys.argv) |
OLD | NEW |