Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Side by Side Diff: lib/dom/scripts/systemfrog.py

Issue 10700006: Make per-interface generators an implementation detail of a system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 frog binding from the IDL database.""" 7 frog binding from the IDL database."""
8 8
9 import os 9 import os
10 from generator import * 10 from generator import *
(...skipping 11 matching lines...) Expand all
22 'HTMLIFrameElement.get:contentDocument', 22 'HTMLIFrameElement.get:contentDocument',
23 ]) 23 ])
24 24
25 class FrogSystem(System): 25 class FrogSystem(System):
26 26
27 def __init__(self, templates, database, emitters, output_dir): 27 def __init__(self, templates, database, emitters, output_dir):
28 super(FrogSystem, self).__init__( 28 super(FrogSystem, self).__init__(
29 templates, database, emitters, output_dir) 29 templates, database, emitters, output_dir)
30 self._impl_file_paths = [] 30 self._impl_file_paths = []
31 31
32 def InterfaceGenerator(self, 32 def ProcessInterface(self, interface):
33 interface,
34 common_prefix,
35 super_interface_name,
36 source_filter):
37 """.""" 33 """."""
38 if IsPureInterface(interface.id): 34 if IsPureInterface(interface.id):
39 return 35 return
40 template_file = 'impl_%s.darttemplate' % interface.id 36 template_file = 'impl_%s.darttemplate' % interface.id
41 template = self._templates.TryLoad(template_file) 37 template = self._templates.TryLoad(template_file)
42 if not template: 38 if not template:
43 template = self._templates.Load('frog_impl.darttemplate') 39 template = self._templates.Load('frog_impl.darttemplate')
44 40
45 dart_code = self._ImplFileEmitter(interface.id) 41 dart_code = self._ImplFileEmitter(interface.id)
46 return FrogInterfaceGenerator(self, interface, template, 42 generator = FrogInterfaceGenerator(self, interface, template, dart_code)
Anton Muhin 2012/06/27 18:13:55 nit: again, single line?
podivilov 2012/06/27 18:48:07 Done.
47 super_interface_name, dart_code) 43 generator.Generate()
48 44
49 def GenerateLibraries(self): 45 def GenerateLibraries(self):
50 self._GenerateLibFile( 46 self._GenerateLibFile(
51 'frog_dom.darttemplate', 47 'frog_dom.darttemplate',
52 os.path.join(self._output_dir, 'dom_frog.dart'), 48 os.path.join(self._output_dir, 'dom_frog.dart'),
53 (self._interface_system._dart_interface_file_paths + 49 (self._interface_system._dart_interface_file_paths +
54 self._interface_system._dart_callback_file_paths + 50 self._interface_system._dart_callback_file_paths +
55 self._impl_file_paths)) 51 self._impl_file_paths))
56 52
57 def Finish(self): 53 def Finish(self):
58 pass 54 pass
59 55
60 def _ImplFileEmitter(self, name): 56 def _ImplFileEmitter(self, name):
61 """Returns the file emitter of the Frog implementation file.""" 57 """Returns the file emitter of the Frog implementation file."""
62 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name) 58 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name)
63 self._impl_file_paths.append(path) 59 self._impl_file_paths.append(path)
64 return self._emitters.FileEmitter(path) 60 return self._emitters.FileEmitter(path)
65 61
66 # ------------------------------------------------------------------------------ 62 # ------------------------------------------------------------------------------
67 63
68 class FrogInterfaceGenerator(BaseGenerator): 64 class FrogInterfaceGenerator(BaseGenerator):
69 """Generates a Frog class for a DOM IDL interface.""" 65 """Generates a Frog class for a DOM IDL interface."""
70 66
71 def __init__(self, system, interface, template, super_interface, dart_code): 67 def __init__(self, system, interface, template, dart_code):
72 """Generates Dart code for the given interface. 68 """Generates Dart code for the given interface.
73 69
74 Args: 70 Args:
75 71
76 interface: an IDLInterface instance. It is assumed that all types have 72 interface: an IDLInterface instance. It is assumed that all types have
77 been converted to Dart types (e.g. int, String), unless they are in 73 been converted to Dart types (e.g. int, String), unless they are in
78 the same package as the interface. 74 the same package as the interface.
79 template: A string template. 75 template: A string template.
80 super_interface: A string or None, the name of the common interface that
81 this interface implements, if any.
82 dart_code: an Emitter for the file containing the Dart implementation 76 dart_code: an Emitter for the file containing the Dart implementation
83 class. 77 class.
84 """ 78 """
85 super(FrogInterfaceGenerator, self).__init__(system._database) 79 super(FrogInterfaceGenerator, self).__init__(system._database, interface)
86 self._system = system 80 self._system = system
87 self._interface = interface 81 self._interface = interface
88 self._template = template 82 self._template = template
89 self._super_interface = super_interface
90 self._dart_code = dart_code 83 self._dart_code = dart_code
91 self._current_secondary_parent = None 84 self._current_secondary_parent = None
92 85
93 86
94 def StartInterface(self): 87 def StartInterface(self):
95 interface = self._interface 88 interface = self._interface
96 interface_name = interface.id 89 interface_name = interface.id
97 self._class_name = self._ImplClassName(interface_name) 90 self._class_name = self._ImplClassName(interface_name)
98 91
99 base = None 92 base = None
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if native_body: 388 if native_body:
396 native_string = " '''" + native_body + "'''" 389 native_string = " '''" + native_body + "'''"
397 390
398 self._members_emitter.Emit( 391 self._members_emitter.Emit(
399 '\n' 392 '\n'
400 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', 393 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n',
401 TYPE=self._NarrowOutputType(info.type_name), 394 TYPE=self._NarrowOutputType(info.type_name),
402 NAME=info.name, 395 NAME=info.name,
403 PARAMS=params, 396 PARAMS=params,
404 NATIVESTRING=native_string) 397 NATIVESTRING=native_string)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698