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

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

Issue 10532027: Move interface members traverse logic to BaseGenerator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 pass 58 pass
59 59
60 def _ImplFileEmitter(self, name): 60 def _ImplFileEmitter(self, name):
61 """Returns the file emitter of the Frog implementation file.""" 61 """Returns the file emitter of the Frog implementation file."""
62 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name) 62 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name)
63 self._impl_file_paths.append(path) 63 self._impl_file_paths.append(path)
64 return self._emitters.FileEmitter(path) 64 return self._emitters.FileEmitter(path)
65 65
66 # ------------------------------------------------------------------------------ 66 # ------------------------------------------------------------------------------
67 67
68 class FrogInterfaceGenerator(object): 68 class FrogInterfaceGenerator(BaseGenerator):
69 """Generates a Frog class for a DOM IDL interface.""" 69 """Generates a Frog class for a DOM IDL interface."""
70 70
71 def __init__(self, system, interface, template, super_interface, dart_code): 71 def __init__(self, system, interface, template, super_interface, dart_code):
72 """Generates Dart code for the given interface. 72 """Generates Dart code for the given interface.
73 73
74 Args: 74 Args:
75 75
76 interface: an IDLInterface instance. It is assumed that all types have 76 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 77 been converted to Dart types (e.g. int, String), unless they are in
78 the same package as the interface. 78 the same package as the interface.
79 template: A string template. 79 template: A string template.
80 super_interface: A string or None, the name of the common interface that 80 super_interface: A string or None, the name of the common interface that
81 this interface implements, if any. 81 this interface implements, if any.
82 dart_code: an Emitter for the file containing the Dart implementation 82 dart_code: an Emitter for the file containing the Dart implementation
83 class. 83 class.
84 """ 84 """
85 super(FrogInterfaceGenerator, self).__init__(system._database)
85 self._system = system 86 self._system = system
86 self._interface = interface 87 self._interface = interface
87 self._template = template 88 self._template = template
88 self._super_interface = super_interface 89 self._super_interface = super_interface
89 self._dart_code = dart_code 90 self._dart_code = dart_code
90 self._current_secondary_parent = None 91 self._current_secondary_parent = None
91 92
92 93
93 def StartInterface(self): 94 def StartInterface(self):
94 interface = self._interface 95 interface = self._interface
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' 347 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n'
347 ' }\n', 348 ' }\n',
348 TYPE=self._NarrowInputType(element_type)) 349 TYPE=self._NarrowInputType(element_type))
349 350
350 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 351 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
351 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 352 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
352 template_file = 'immutable_list_mixin.darttemplate' 353 template_file = 'immutable_list_mixin.darttemplate'
353 template = self._system._templates.Load(template_file) 354 template = self._system._templates.Load(template_file)
354 self._members_emitter.Emit(template, E=DartType(element_type)) 355 self._members_emitter.Emit(template, E=DartType(element_type))
355 356
356 def AmendIndexer(self, element_type):
357 pass
358
359 def AddOperation(self, info): 357 def AddOperation(self, info):
360 """ 358 """
361 Arguments: 359 Arguments:
362 info: An OperationInfo object. 360 info: An OperationInfo object.
363 """ 361 """
364 # TODO(vsm): Handle overloads. 362 # TODO(vsm): Handle overloads.
365 params = info.ParametersImplementationDeclaration( 363 params = info.ParametersImplementationDeclaration(
366 lambda type_name: self._NarrowInputType(type_name)) 364 lambda type_name: self._NarrowInputType(type_name))
367 365
368 native_string = '' 366 native_string = ''
369 if info.declared_name != info.name: 367 if info.declared_name != info.name:
370 native_string = " '%s'" % info.declared_name 368 native_string = " '%s'" % info.declared_name
371 369
372 native_body = dom_frog_native_bodies.get( 370 native_body = dom_frog_native_bodies.get(
373 self._interface.id + '.' + info.name, '') 371 self._interface.id + '.' + info.name, '')
374 if native_body: 372 if native_body:
375 native_string = " '''" + native_body + "'''" 373 native_string = " '''" + native_body + "'''"
376 374
377 self._members_emitter.Emit( 375 self._members_emitter.Emit(
378 '\n' 376 '\n'
379 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', 377 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n',
380 TYPE=self._NarrowOutputType(info.type_name), 378 TYPE=self._NarrowOutputType(info.type_name),
381 NAME=info.name, 379 NAME=info.name,
382 PARAMS=params, 380 PARAMS=params,
383 NATIVESTRING=native_string) 381 NATIVESTRING=native_string)
384
385 def AddStaticOperation(self, info):
386 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698