OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This module provides base functionality for systems to generate | 6 """This module provides base functionality for systems to generate |
7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
8 | 8 |
9 import os | 9 import os |
10 from generator import * | 10 from generator import * |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 # Helper methods used by several systems. | 49 # Helper methods used by several systems. |
50 | 50 |
51 def _ProcessCallback(self, interface, info, file_path): | 51 def _ProcessCallback(self, interface, info, file_path): |
52 """Generates a typedef for the callback interface.""" | 52 """Generates a typedef for the callback interface.""" |
53 self._dart_interface_file_paths.append(file_path) | 53 self._dart_interface_file_paths.append(file_path) |
54 code = self._emitters.FileEmitter(file_path) | 54 code = self._emitters.FileEmitter(file_path) |
55 | 55 |
56 code.Emit(self._templates.Load('callback.darttemplate')) | 56 code.Emit(self._templates.Load('callback.darttemplate')) |
57 code.Emit('typedef $TYPE $NAME($PARAMS);\n', | 57 code.Emit('typedef $TYPE $NAME($PARAMS);\n', |
58 NAME=interface.id, | 58 NAME=interface.id, |
59 TYPE=info.type_name, | 59 TYPE=DartType(info.type_name), |
60 PARAMS=info.ParametersImplementationDeclaration()) | 60 PARAMS=info.ParametersImplementationDeclaration(DartType)) |
61 | 61 |
62 | 62 |
63 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths, | 63 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths, |
64 **template_args): | 64 **template_args): |
65 """Generates a lib file from a template and a list of files. | 65 """Generates a lib file from a template and a list of files. |
66 | 66 |
67 Additional keyword arguments are passed to the template. | 67 Additional keyword arguments are passed to the template. |
68 Typically called from self.GenerateLibraries. | 68 Typically called from self.GenerateLibraries. |
69 """ | 69 """ |
70 # Load template. | 70 # Load template. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 result = [] | 216 result = [] |
217 if interface.parents: | 217 if interface.parents: |
218 parent = interface.parents[0] | 218 parent = interface.parents[0] |
219 if IsPureInterface(parent.type.id): | 219 if IsPureInterface(parent.type.id): |
220 walk(interface.parents) | 220 walk(interface.parents) |
221 else: | 221 else: |
222 walk(interface.parents[1:]) | 222 walk(interface.parents[1:]) |
223 return result | 223 return result |
224 | 224 |
| 225 def _DartType(self, type_name): |
| 226 return self._system._type_registry.DartType(type_name) |
| 227 |
| 228 |
225 class GeneratorContext(object): | 229 class GeneratorContext(object): |
226 def __init__(self, templates, database, emitters, type_registry, output_dir): | 230 def __init__(self, templates, database, emitters, type_registry, output_dir): |
227 self.templates = templates | 231 self.templates = templates |
228 self.database = database | 232 self.database = database |
229 self.emitters = emitters | 233 self.emitters = emitters |
230 self.type_registry = type_registry | 234 self.type_registry = type_registry |
231 self.output_dir = output_dir | 235 self.output_dir = output_dir |
232 | 236 |
233 | 237 |
234 def IsReadOnly(attribute): | 238 def IsReadOnly(attribute): |
235 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs | 239 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs |
OLD | NEW |