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

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

Issue 10542036: Use original WebKit IDL database for dart:html generation. (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
« no previous file with comments | « no previous file | lib/dom/scripts/dartgenerator.py » ('j') | no next file with comments »
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
(...skipping 16 matching lines...) Expand all
27 # TODO(vsm): Maybe Store these renames in the IDLs. 27 # TODO(vsm): Maybe Store these renames in the IDLs.
28 'ApplicationCache': 'DOMApplicationCache', 28 'ApplicationCache': 'DOMApplicationCache',
29 'BarProp': 'BarInfo', 29 'BarProp': 'BarInfo',
30 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', 30 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext',
31 'FormData': 'DOMFormData', 31 'FormData': 'DOMFormData',
32 'Selection': 'DOMSelection', 32 'Selection': 'DOMSelection',
33 'SharedWorkerGlobalScope': 'SharedWorkerContext', 33 'SharedWorkerGlobalScope': 'SharedWorkerContext',
34 'Window': 'DOMWindow', 34 'Window': 'DOMWindow',
35 'WorkerGlobalScope': 'WorkerContext'} 35 'WorkerGlobalScope': 'WorkerContext'}
36 36
37 _html_strip_webkit_prefix_classes = [
38 'Animation',
39 'AnimationEvent',
40 'AnimationList',
41 'BlobBuilder',
42 'CSSKeyframeRule',
43 'CSSKeyframesRule',
44 'CSSMatrix',
45 'CSSTransformValue',
46 'Flags',
47 'LoseContext',
48 'Point',
49 'TransitionEvent']
50
51 def HasAncestor(interface, names_to_match, database):
52 for parent in interface.parents:
53 if (parent.type.id in names_to_match or
54 (database.HasInterface(parent.type.id) and
55 HasAncestor(database.GetInterface(parent.type.id), names_to_match,
56 database))):
57 return True
58 return False
59
60 def _MakeHtmlRenames(common_database):
61 html_renames = {}
62
63 for interface in common_database.GetInterfaces():
64 if (interface.id.startswith("HTML") and
65 HasAncestor(interface, ['Element', 'Document'], common_database)):
66 html_renames[interface.id] = interface.id[4:]
67
68 for subclass in _html_strip_webkit_prefix_classes:
69 html_renames['WebKit' + subclass] = subclass
70
71 # TODO(jacobr): we almost want to add this commented out line back.
72 # html_renames['HTMLCollection'] = 'ElementList'
73 # html_renames['NodeList'] = 'ElementList'
74 # html_renames['HTMLOptionsCollection'] = 'ElementList'
75 html_renames['DOMWindow'] = 'Window'
76
77 return html_renames
78
79 def Generate(systems, database_dir, use_database_cache, dom_output_dir, 37 def Generate(systems, database_dir, use_database_cache, dom_output_dir,
80 html_output_dir): 38 html_output_dir):
81 current_dir = os.path.dirname(__file__) 39 current_dir = os.path.dirname(__file__)
82 auxiliary_dir = os.path.join(current_dir, '..', 'src') 40 auxiliary_dir = os.path.join(current_dir, '..', 'src')
83 template_dir = os.path.join(current_dir, '..', 'templates') 41 template_dir = os.path.join(current_dir, '..', 'templates')
84 42
85 generator = dartgenerator.DartGenerator() 43 generator = dartgenerator.DartGenerator()
86 generator.LoadAuxiliary(auxiliary_dir) 44 generator.LoadAuxiliary(auxiliary_dir)
87 45
88 common_database = database.Database(database_dir) 46 common_database = database.Database(database_dir)
89 if use_database_cache: 47 if use_database_cache:
90 common_database.LoadFromCache() 48 common_database.LoadFromCache()
91 else: 49 else:
92 common_database.Load() 50 common_database.Load()
93 51
94 generator.FilterMembersWithUnidentifiedTypes(common_database) 52 generator.FilterMembersWithUnidentifiedTypes(common_database)
95 dom_database = common_database.Clone() 53 webkit_database = common_database.Clone()
96 54
97 # Generate Dart interfaces for the WebKit DOM. 55 # Generate Dart interfaces for the WebKit DOM.
98 generator.FilterInterfaces(database = dom_database, 56 generator.FilterInterfaces(database = webkit_database,
99 or_annotations = ['WebKit', 'Dart'], 57 or_annotations = ['WebKit', 'Dart'],
100 exclude_displaced = ['WebKit'], 58 exclude_displaced = ['WebKit'],
101 exclude_suppressed = ['WebKit', 'Dart']) 59 exclude_suppressed = ['WebKit', 'Dart'])
102 generator.RenameTypes(dom_database, _webkit_renames, True) 60 generator.RenameTypes(webkit_database, _webkit_renames, True)
103 generator.FixEventTargets(dom_database) 61 generator.FixEventTargets(webkit_database)
104 62
105 emitters = multiemitter.MultiEmitter() 63 emitters = multiemitter.MultiEmitter()
106 html_renames = _MakeHtmlRenames(common_database)
107
108 html_database = None
109 if set(systems) & set(['htmlfrog', 'htmldartium']):
110 html_database = dom_database.Clone()
111 generator.RenameTypes(html_database, html_renames, False)
112 64
113 for system in systems: 65 for system in systems:
114 if system in ['htmlfrog', 'htmldartium']: 66 if system in ['htmlfrog', 'htmldartium']:
115 target_database = html_database 67
116 output_dir = html_output_dir 68 output_dir = html_output_dir
117 interface_system = HtmlInterfacesSystem( 69 interface_system = HtmlInterfacesSystem(
118 TemplateLoader(template_dir, ['html/interface', 'html', '']), 70 TemplateLoader(template_dir, ['html/interface', 'html', '']),
119 target_database, emitters, output_dir) 71 webkit_database, emitters, output_dir)
120 else: 72 else:
121 target_database = dom_database
122 output_dir = dom_output_dir 73 output_dir = dom_output_dir
123 interface_system = InterfacesSystem( 74 interface_system = InterfacesSystem(
124 TemplateLoader(template_dir, ['dom/interface', 'dom', '']), 75 TemplateLoader(template_dir, ['dom/interface', 'dom', '']),
125 target_database, emitters, output_dir) 76 webkit_database, emitters, output_dir)
126 77
127 if system == 'dummy': 78 if system == 'dummy':
128 implementation_system = dartgenerator.DummyImplementationSystem( 79 implementation_system = dartgenerator.DummyImplementationSystem(
129 TemplateLoader(template_dir, ['dom/dummy', 'dom', '']), 80 TemplateLoader(template_dir, ['dom/dummy', 'dom', '']),
130 target_database, emitters, output_dir) 81 webkit_database, emitters, output_dir)
131 elif system == 'frog': 82 elif system == 'frog':
132 implementation_system = FrogSystem( 83 implementation_system = FrogSystem(
133 TemplateLoader(template_dir, ['dom/frog', 'dom', '']), 84 TemplateLoader(template_dir, ['dom/frog', 'dom', '']),
134 target_database, emitters, output_dir) 85 webkit_database, emitters, output_dir)
135 elif system == 'htmlfrog': 86 elif system == 'htmlfrog':
136 implementation_system = HtmlFrogSystem( 87 implementation_system = HtmlFrogSystem(
137 TemplateLoader(template_dir, 88 TemplateLoader(template_dir,
138 ['html/frog', 'html/impl', 'html', ''], 89 ['html/frog', 'html/impl', 'html', ''],
139 {'DARTIUM': False, 'FROG': True}), 90 {'DARTIUM': False, 'FROG': True}),
140 target_database, emitters, output_dir) 91 webkit_database, emitters, output_dir)
141 elif system == 'htmldartium': 92 elif system == 'htmldartium':
142 # Generate native wrappers. 93 # Generate native wrappers.
143 native_system = NativeImplementationSystem( 94 native_system = NativeImplementationSystem(
144 TemplateLoader(template_dir, ['dom/native', 'html/dartium', 95 TemplateLoader(template_dir, ['dom/native', 'html/dartium',
145 'html/impl', ''], 96 'html/impl', ''],
146 {'DARTIUM': True, 'FROG': False}), 97 {'DARTIUM': True, 'FROG': False}),
147 dom_database, html_database, html_renames, emitters, output_dir) 98 webkit_database, emitters, output_dir)
148 generator.Generate(dom_database, native_system, 99 generator.Generate(webkit_database, native_system,
149 source_filter=['WebKit', 'Dart'], 100 source_filter=['WebKit', 'Dart'],
150 super_database=common_database, 101 super_database=common_database,
151 common_prefix='common', 102 common_prefix='common',
152 webkit_renames=_webkit_renames, 103 webkit_renames=_webkit_renames)
153 html_renames=html_renames)
154 dom_implementation_classes = native_system.DartImplementationFiles() 104 dom_implementation_classes = native_system.DartImplementationFiles()
155 implementation_system = HtmlDartiumSystem( 105 implementation_system = HtmlDartiumSystem(
156 TemplateLoader(template_dir, 106 TemplateLoader(template_dir,
157 ['html/dartium', 'html/impl', 'html', ''], 107 ['html/dartium', 'html/impl', 'html', ''],
158 {'DARTIUM': True, 'FROG': False}), 108 {'DARTIUM': True, 'FROG': False}),
159 target_database, emitters, auxiliary_dir, dom_implementation_classes, 109 webkit_database, emitters, auxiliary_dir, dom_implementation_classes,
160 output_dir) 110 output_dir)
161 else: 111 else:
162 raise Exception('Unsupported system %s' % system) 112 raise Exception('Unsupported system %s' % system)
163 113
164 # Makes interface files available for listing in the library for the 114 # Makes interface files available for listing in the library for the
165 # implementation system. 115 # implementation system.
166 implementation_system._interface_system = interface_system 116 implementation_system._interface_system = interface_system
167 117
168 for system in [interface_system, implementation_system]: 118 for system in [interface_system, implementation_system]:
169 generator.Generate(target_database, system, 119 generator.Generate(webkit_database, system,
170 source_filter=['WebKit', 'Dart'], 120 source_filter=['WebKit', 'Dart'],
171 super_database=common_database, 121 super_database=common_database,
172 common_prefix='common', 122 common_prefix='common',
173 webkit_renames=_webkit_renames, 123 webkit_renames=_webkit_renames)
174 html_renames=html_renames)
175 124
176 _logger.info('Flush...') 125 _logger.info('Flush...')
177 emitters.Flush() 126 emitters.Flush()
178 127
179 def GenerateSingleFile(systems): 128 def GenerateSingleFile(systems):
180 if 'frog' in systems: 129 if 'frog' in systems:
181 _logger.info('Copy dom_frog to frog/') 130 _logger.info('Copy dom_frog to frog/')
182 subprocess.call(['cd ../generated ; ' 131 subprocess.call(['cd ../generated ; '
183 '../../../tools/copy_dart.py ../frog dom_frog.dart'], 132 '../../../tools/copy_dart.py ../frog dom_frog.dart'],
184 shell=True); 133 shell=True);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 dom_output_dir = options.output_dir or os.path.join(current_dir, 178 dom_output_dir = options.output_dir or os.path.join(current_dir,
230 '../generated') 179 '../generated')
231 html_output_dir = options.output_dir or os.path.join(current_dir, 180 html_output_dir = options.output_dir or os.path.join(current_dir,
232 '../../html/generated') 181 '../../html/generated')
233 Generate(systems, database_dir, options.use_database_cache, 182 Generate(systems, database_dir, options.use_database_cache,
234 dom_output_dir, html_output_dir) 183 dom_output_dir, html_output_dir)
235 GenerateSingleFile(systems) 184 GenerateSingleFile(systems)
236 185
237 if __name__ == '__main__': 186 if __name__ == '__main__':
238 sys.exit(main()) 187 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/dartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698