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

Side by Side Diff: lib/html/scripts/dartdomgenerator.py

Issue 10986048: Get rid of System classes for backend generators. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
« no previous file with comments | « no previous file | lib/html/scripts/dartgenerator.py » ('j') | lib/html/scripts/systembase.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, 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 is the entry point to create Dart APIs from the IDL database.""" 6 """This is the entry point to create Dart APIs from the IDL database."""
7 7
8 import dartgenerator 8 import dartgenerator
9 import database 9 import database
10 import logging.config 10 import logging.config
11 import multiemitter 11 import multiemitter
12 import optparse 12 import optparse
13 import os 13 import os
14 import shutil 14 import shutil
15 import subprocess 15 import subprocess
16 import sys 16 import sys
17 from generator import TypeRegistry 17 from generator import TypeRegistry
18 from htmlrenamer import HtmlRenamer 18 from htmlrenamer import HtmlRenamer
19 from systembase import GeneratorOptions 19 from systembase import GeneratorOptions
20 from systemdart2js import Dart2JSSystem 20 from systemdart2js import Dart2JSSystem
21 from systemhtml import DartLibraryEmitter, HtmlInterfacesSystem,\ 21 from systemhtml import DartLibraryEmitter, HtmlInterfacesSystem,\
22 HtmlDart2JSSystem 22 Dart2JSGeneratorBackend
23 from systeminterface import InterfacesSystem 23 from systeminterface import InterfacesSystem
24 from systemnative import CPPLibraryEmitter, NativeImplementationSystem 24 from systemnative import CPPLibraryEmitter, DartiumGeneratorBackend
25 from templateloader import TemplateLoader 25 from templateloader import TemplateLoader
26 26
27 _logger = logging.getLogger('dartdomgenerator') 27 _logger = logging.getLogger('dartdomgenerator')
28 28
29 _webkit_renames = { 29 _webkit_renames = {
30 # W3C -> WebKit name conversion 30 # W3C -> WebKit name conversion
31 # TODO(vsm): Maybe Store these renames in the IDLs. 31 # TODO(vsm): Maybe Store these renames in the IDLs.
32 'ApplicationCache': 'DOMApplicationCache', 32 'ApplicationCache': 'DOMApplicationCache',
33 'BarProp': 'BarInfo', 33 'BarProp': 'BarInfo',
34 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', 34 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext',
(...skipping 27 matching lines...) Expand all
62 exclude_displaced = ['WebKit'], 62 exclude_displaced = ['WebKit'],
63 exclude_suppressed = ['WebKit', 'Dart']) 63 exclude_suppressed = ['WebKit', 'Dart'])
64 generator.RenameTypes(webkit_database, _webkit_renames, True) 64 generator.RenameTypes(webkit_database, _webkit_renames, True)
65 generator.FixEventTargets(webkit_database) 65 generator.FixEventTargets(webkit_database)
66 generator.AddMissingArguments(webkit_database) 66 generator.AddMissingArguments(webkit_database)
67 67
68 emitters = multiemitter.MultiEmitter() 68 emitters = multiemitter.MultiEmitter()
69 renamer = HtmlRenamer(webkit_database) 69 renamer = HtmlRenamer(webkit_database)
70 type_registry = TypeRegistry(webkit_database, renamer) 70 type_registry = TypeRegistry(webkit_database, renamer)
71 71
72 def RunGenerator(dart_library_template, dart_output_dir, dart_library_path, 72 def RunGenerator(dart_library_template, dart_output_dir, dart_library_path,
Anton Muhin 2012/09/26 14:20:36 overall logic becomes rather complicated, so, sorr
73 backend): 73 create_generator_backend):
Anton Muhin 2012/09/26 14:20:36 I'd rather name it generator_backend_factory.
Anton Muhin 2012/09/26 14:20:36 generator backend sounds somewhat too much, can it
podivilov 2012/09/26 15:02:04 Done.
podivilov 2012/09/26 15:02:04 Renamed to FooBackend. Backends should not extend
74 template_loader = TemplateLoader( 74 template_loader = TemplateLoader(
Anton Muhin 2012/09/26 14:20:36 cannot we lift template_loader creation out of thi
podivilov 2012/09/26 15:02:04 Done.
75 template_dir, ['html/interface', 'html/impl', 'html', ''], {}) 75 template_dir, ['html/interface', 'html/impl', 'html', ''], {})
76 options = GeneratorOptions( 76 options = GeneratorOptions(
Anton Muhin 2012/09/26 14:20:36 cannot we lift options creation out of this functi
77 template_loader, webkit_database, type_registry, renamer) 77 template_loader, webkit_database, type_registry, renamer)
78 dart_library_emitter = DartLibraryEmitter( 78 dart_library_emitter = DartLibraryEmitter(
79 emitters, dart_library_template, dart_output_dir) 79 emitters, dart_library_template, dart_output_dir)
80 html_system = HtmlInterfacesSystem(options, dart_library_emitter, backend) 80 html_system = HtmlInterfacesSystem(
81 options, dart_library_emitter, create_generator_backend)
81 generator.Generate( 82 generator.Generate(
82 webkit_database, html_system, common_database, _webkit_renames) 83 webkit_database, html_system, common_database, _webkit_renames)
83 dart_library_emitter.EmitLibrary(dart_library_path, auxiliary_dir) 84 dart_library_emitter.EmitLibrary(dart_library_path, auxiliary_dir)
84 85
85 if dart2js_output_dir: 86 if dart2js_output_dir:
86 template_loader = TemplateLoader(template_dir, 87 template_loader = TemplateLoader(template_dir,
87 ['html/dart2js', 'html/impl', 'html', ''], 88 ['html/dart2js', 'html/impl', 'html', ''],
88 {'DARTIUM': False, 'DART2JS': True}) 89 {'DARTIUM': False, 'DART2JS': True})
89 backend_options = GeneratorOptions( 90 backend_options = GeneratorOptions(
90 template_loader, webkit_database, type_registry, renamer) 91 template_loader, webkit_database, type_registry, renamer)
91 backend = HtmlDart2JSSystem(backend_options) 92 def create_generator_backend(interface):
Anton Muhin 2012/09/26 14:20:36 that might be a perfect case for lambda, esp. if y
podivilov 2012/09/26 15:02:04 Done.
93 return Dart2JSGeneratorBackend(interface, backend_options)
92 94
93 dart_library_template = template_loader.Load('html_dart2js.darttemplate') 95 dart_library_template = template_loader.Load('html_dart2js.darttemplate')
94 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') 96 dart_output_dir = os.path.join(dart2js_output_dir, 'dart')
95 dart_library_path = os.path.join(dart2js_output_dir, 'html_dart2js.dart') 97 dart_library_path = os.path.join(dart2js_output_dir, 'html_dart2js.dart')
96 98
97 RunGenerator( 99 RunGenerator(dart_library_template, dart_output_dir, dart_library_path,
98 dart_library_template, dart_output_dir, dart_library_path, backend) 100 create_generator_backend)
99 101
100 if dartium_output_dir: 102 if dartium_output_dir:
101 template_loader = TemplateLoader(template_dir, 103 template_loader = TemplateLoader(template_dir,
102 ['html/dartium', 'html/impl', ''], 104 ['html/dartium', 'html/impl', ''],
103 {'DARTIUM': True, 'DART2JS': False}) 105 {'DARTIUM': True, 'DART2JS': False})
104 backend_options = GeneratorOptions( 106 backend_options = GeneratorOptions(
105 template_loader, webkit_database, type_registry, renamer) 107 template_loader, webkit_database, type_registry, renamer)
106 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') 108 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp')
107 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) 109 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir)
108 backend = NativeImplementationSystem(backend_options, cpp_library_emitter) 110 def create_generator_backend(interface):
111 return DartiumGeneratorBackend(
112 interface, cpp_library_emitter, backend_options)
109 113
110 dart_library_template = template_loader.Load('html_dartium.darttemplate') 114 dart_library_template = template_loader.Load('html_dartium.darttemplate')
111 dart_output_dir = os.path.join(dartium_output_dir, 'dart') 115 dart_output_dir = os.path.join(dartium_output_dir, 'dart')
112 dart_library_path = os.path.join(dartium_output_dir, 'html_dartium.dart') 116 dart_library_path = os.path.join(dartium_output_dir, 'html_dartium.dart')
113 117
114 RunGenerator( 118 RunGenerator(dart_library_template, dart_output_dir, dart_library_path,
115 dart_library_template, dart_output_dir, dart_library_path, backend) 119 create_generator_backend)
116 cpp_library_emitter.EmitDerivedSources( 120 cpp_library_emitter.EmitDerivedSources(
117 template_loader.Load('cpp_derived_sources.template'), 121 template_loader.Load('cpp_derived_sources.template'),
118 dartium_output_dir) 122 dartium_output_dir)
119 cpp_library_emitter.EmitResolver( 123 cpp_library_emitter.EmitResolver(
120 template_loader.Load('cpp_resolver.template'), dartium_output_dir) 124 template_loader.Load('cpp_resolver.template'), dartium_output_dir)
121 125
122 _logger.info('Flush...') 126 _logger.info('Flush...')
123 emitters.Flush() 127 emitters.Flush()
124 128
125 def GenerateSingleFile(library_path, output_dir): 129 def GenerateSingleFile(library_path, output_dir):
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 _logger.info('Copy html_dart2js to dart2js/') 172 _logger.info('Copy html_dart2js to dart2js/')
169 GenerateSingleFile(os.path.join(dart2js_output_dir, 'html_dart2js.dart'), 173 GenerateSingleFile(os.path.join(dart2js_output_dir, 'html_dart2js.dart'),
170 '../dart2js') 174 '../dart2js')
171 if 'htmldartium' in systems: 175 if 'htmldartium' in systems:
172 _logger.info('Copy html_dartium to dartium/') 176 _logger.info('Copy html_dartium to dartium/')
173 GenerateSingleFile(os.path.join(dartium_output_dir, 'html_dartium.dart'), 177 GenerateSingleFile(os.path.join(dartium_output_dir, 'html_dartium.dart'),
174 '../dartium') 178 '../dartium')
175 179
176 if __name__ == '__main__': 180 if __name__ == '__main__':
177 sys.exit(main()) 181 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | lib/html/scripts/dartgenerator.py » ('j') | lib/html/scripts/systembase.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698