OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 def _update_dependencies_include_paths(self, definition_name): | 134 def _update_dependencies_include_paths(self, definition_name): |
135 interface_info = self.info_provider.interfaces_info[definition_name] | 135 interface_info = self.info_provider.interfaces_info[definition_name] |
136 dependencies_include_paths = interface_info['dependencies_include_paths'
] | 136 dependencies_include_paths = interface_info['dependencies_include_paths'
] |
137 for include_path in self.additional_includes: | 137 for include_path in self.additional_includes: |
138 if include_path not in dependencies_include_paths: | 138 if include_path not in dependencies_include_paths: |
139 dependencies_include_paths.append(include_path) | 139 dependencies_include_paths.append(include_path) |
140 | 140 |
141 def _resolve_typedefs(self, typed_object): | 141 def _resolve_typedefs(self, typed_object): |
142 """Resolve typedefs to actual types in the object.""" | 142 """Resolve typedefs to actual types in the object.""" |
143 idl_type = typed_object.idl_type | 143 for attribute_name in typed_object.idl_type_attributes: |
144 if not idl_type: | 144 try: |
145 return | 145 idl_type = getattr(typed_object, attribute_name) |
146 resolved_idl_type = idl_type.resolve_typedefs(self.typedefs) | 146 except AttributeError: |
147 if resolved_idl_type.is_union_type: | 147 continue |
148 self.additional_includes.add( | 148 if not idl_type: |
149 self.info_provider.include_path_for_union_types) | 149 continue |
150 # Need to re-assign typed_object.idl_type, not just mutate idl_type, | 150 resolved_idl_type = idl_type.resolve_typedefs(self.typedefs) |
151 # since type(idl_type) may change. | 151 if resolved_idl_type.is_union_type: |
152 typed_object.idl_type = resolved_idl_type | 152 self.additional_includes.add( |
| 153 self.info_provider.include_path_for_union_types) |
| 154 # Need to re-assign the attribute, not just mutate idl_type, since |
| 155 # type(idl_type) may change. |
| 156 setattr(typed_object, attribute_name, resolved_idl_type) |
153 | 157 |
154 def visit_callback_function(self, callback_function): | 158 def visit_typed_object(self, typed_object): |
155 self._resolve_typedefs(callback_function) | 159 self._resolve_typedefs(typed_object) |
156 | |
157 def visit_attribute(self, attribute): | |
158 self._resolve_typedefs(attribute) | |
159 | |
160 def visit_constant(self, constant): | |
161 self._resolve_typedefs(constant) | |
162 | |
163 def visit_operation(self, operation): | |
164 self._resolve_typedefs(operation) | |
165 | |
166 def visit_argument(self, argument): | |
167 self._resolve_typedefs(argument) | |
168 | 160 |
169 | 161 |
170 class CodeGeneratorBase(object): | 162 class CodeGeneratorBase(object): |
171 """Base class for v8 bindings generator and IDL dictionary impl generator""" | 163 """Base class for v8 bindings generator and IDL dictionary impl generator""" |
172 | 164 |
173 def __init__(self, info_provider, cache_dir, output_dir): | 165 def __init__(self, info_provider, cache_dir, output_dir): |
174 self.info_provider = info_provider | 166 self.info_provider = info_provider |
175 self.jinja_env = initialize_jinja_env(cache_dir) | 167 self.jinja_env = initialize_jinja_env(cache_dir) |
176 self.output_dir = output_dir | 168 self.output_dir = output_dir |
177 self.typedef_resolver = TypedefResolver(info_provider) | 169 self.typedef_resolver = TypedefResolver(info_provider) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 438 |
447 # Create a dummy file as output for the build system, | 439 # Create a dummy file as output for the build system, |
448 # since filenames of individual cache files are unpredictable and opaque | 440 # since filenames of individual cache files are unpredictable and opaque |
449 # (they are hashes of the template path, which varies based on environment) | 441 # (they are hashes of the template path, which varies based on environment) |
450 with open(dummy_filename, 'w') as dummy_file: | 442 with open(dummy_filename, 'w') as dummy_file: |
451 pass # |open| creates or touches the file | 443 pass # |open| creates or touches the file |
452 | 444 |
453 | 445 |
454 if __name__ == '__main__': | 446 if __name__ == '__main__': |
455 sys.exit(main(sys.argv)) | 447 sys.exit(main(sys.argv)) |
OLD | NEW |