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

Side by Side Diff: client/dom/scripts/systemnative.py

Issue 9565006: Add missing includes (spotted while splitting cpp derived sources). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 self._emitters.FileEmitter(cpp_impl_path), 52 self._emitters.FileEmitter(cpp_impl_path),
53 self._BaseDefines(interface), 53 self._BaseDefines(interface),
54 self._templates) 54 self._templates)
55 55
56 def ProcessCallback(self, interface, info): 56 def ProcessCallback(self, interface, info):
57 self._interface = interface 57 self._interface = interface
58 58
59 dart_interface_path = self._FilePathForDartInterface(self._interface.id) 59 dart_interface_path = self._FilePathForDartInterface(self._interface.id)
60 self._dom_public_files.append(dart_interface_path) 60 self._dom_public_files.append(dart_interface_path)
61 61
62 cpp_impl_includes = {}
62 cpp_header_handlers_emitter = emitter.Emitter() 63 cpp_header_handlers_emitter = emitter.Emitter()
63 cpp_impl_handlers_emitter = emitter.Emitter() 64 cpp_impl_handlers_emitter = emitter.Emitter()
64 class_name = 'Dart%s' % self._interface.id 65 class_name = 'Dart%s' % self._interface.id
65 for operation in interface.operations: 66 for operation in interface.operations:
66 if operation.type.id == 'void': 67 if operation.type.id == 'void':
67 return_type = 'void' 68 return_type = 'void'
68 return_prefix = '' 69 return_prefix = ''
69 else: 70 else:
70 return_type = 'bool' 71 return_type = 'bool'
71 return_prefix = 'return ' 72 return_prefix = 'return '
72 73
73 parameters = [] 74 parameters = []
74 arguments = [] 75 arguments = []
75 for argument in operation.arguments: 76 for argument in operation.arguments:
76 argument_type_info = GetIDLTypeInfo(argument.type) 77 argument_type_info = GetIDLTypeInfo(argument.type)
77 parameters.append('%s %s' % (argument_type_info.parameter_type(), 78 parameters.append('%s %s' % (argument_type_info.parameter_type(),
78 argument.id)) 79 argument.id))
79 arguments.append(argument.id) 80 arguments.append(argument.id)
81 if argument_type_info.conversion_include():
82 cpp_impl_includes[argument_type_info.conversion_include()] = 1
antonm 2012/03/01 14:25:31 why it's map? should we assign 1 or None?
podivilov 2012/03/01 15:36:56 Done.
80 83
81 cpp_header_handlers_emitter.Emit( 84 cpp_header_handlers_emitter.Emit(
82 '\n' 85 '\n'
83 ' virtual $TYPE handleEvent($PARAMETERS);\n', 86 ' virtual $TYPE handleEvent($PARAMETERS);\n',
84 TYPE=return_type, PARAMETERS=', '.join(parameters)) 87 TYPE=return_type, PARAMETERS=', '.join(parameters))
85 88
86 cpp_impl_handlers_emitter.Emit( 89 cpp_impl_handlers_emitter.Emit(
87 '\n' 90 '\n'
88 '$TYPE $CLASS_NAME::handleEvent($PARAMETERS)\n' 91 '$TYPE $CLASS_NAME::handleEvent($PARAMETERS)\n'
89 '{\n' 92 '{\n'
(...skipping 10 matching lines...) Expand all
100 cpp_header_emitter.Emit( 103 cpp_header_emitter.Emit(
101 self._templates.Load('cpp_callback_header.template'), 104 self._templates.Load('cpp_callback_header.template'),
102 INTERFACE=self._interface.id, 105 INTERFACE=self._interface.id,
103 HANDLERS=cpp_header_handlers_emitter.Fragments()) 106 HANDLERS=cpp_header_handlers_emitter.Fragments())
104 107
105 cpp_impl_path = self._FilePathForCppImplementation(self._interface.id) 108 cpp_impl_path = self._FilePathForCppImplementation(self._interface.id)
106 self._cpp_impl_files.append(cpp_impl_path) 109 self._cpp_impl_files.append(cpp_impl_path)
107 cpp_impl_emitter = self._emitters.FileEmitter(cpp_impl_path) 110 cpp_impl_emitter = self._emitters.FileEmitter(cpp_impl_path)
108 cpp_impl_emitter.Emit( 111 cpp_impl_emitter.Emit(
109 self._templates.Load('cpp_callback_implementation.template'), 112 self._templates.Load('cpp_callback_implementation.template'),
113 INCLUDES=_GenerateCPPIncludes(cpp_impl_includes.keys()),
110 INTERFACE=self._interface.id, 114 INTERFACE=self._interface.id,
111 HANDLERS=cpp_impl_handlers_emitter.Fragments()) 115 HANDLERS=cpp_impl_handlers_emitter.Fragments())
112 116
113 def GenerateLibraries(self, lib_dir): 117 def GenerateLibraries(self, lib_dir):
114 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) 118 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir)
115 119
116 # Generate dom_public.dart. 120 # Generate dom_public.dart.
117 self._GenerateLibFile( 121 self._GenerateLibFile(
118 'dom_public.darttemplate', 122 'dom_public.darttemplate',
119 os.path.join(self._output_dir, 'dom_public.dart'), 123 os.path.join(self._output_dir, 'dom_public.dart'),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' 157 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n'
154 ' return func;\n', 158 ' return func;\n',
155 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 159 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
156 160
157 cpp_resolver_emitter = self._emitters.FileEmitter(cpp_resolver_path) 161 cpp_resolver_emitter = self._emitters.FileEmitter(cpp_resolver_path)
158 cpp_resolver_emitter.Emit( 162 cpp_resolver_emitter.Emit(
159 self._templates.Load('cpp_resolver.template'), 163 self._templates.Load('cpp_resolver.template'),
160 INCLUDES=includes_emitter.Fragments(), 164 INCLUDES=includes_emitter.Fragments(),
161 RESOLVER_BODY=resolver_body_emitter.Fragments()) 165 RESOLVER_BODY=resolver_body_emitter.Fragments())
162 166
163 # Generate DartDerivedSourcesAll.cpp 167 # Generate DartDerivedSourcesXX.cpp.
164 cpp_all_in_one_path = os.path.join(self._output_dir, 168 partitions = 20 # FIXME: this should be configurable.
165 'DartDerivedSourcesAll.cpp') 169 sources_count = len(self._cpp_impl_files)
170 for i in range(0, partitions):
171 cpp_all_in_one_path = os.path.join(self._output_dir,
antonm 2012/03/01 14:25:31 cpp_all_in_one is now misleading
172 'DartDerivedSources%02i.cpp' % (i + 1))
166 173
167 includes_emitter = emitter.Emitter() 174 includes_emitter = emitter.Emitter()
168 for file in self._cpp_impl_files: 175 for j in range(i * sources_count / partitions, (i + 1) * sources_count / p artitions):
antonm 2012/03/01 14:25:31 for impl_file in self._cpp_impl_files[i * sources_
podivilov 2012/03/01 15:36:56 nice!
169 path = os.path.relpath(file, os.path.dirname(cpp_all_in_one_path)) 176 path = os.path.relpath(self._cpp_impl_files[j], os.path.dirname(cpp_al l_in_one_path))
170 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 177 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
171 178
172 cpp_all_in_one_emitter = self._emitters.FileEmitter(cpp_all_in_one_path) 179 cpp_all_in_one_emitter = self._emitters.FileEmitter(cpp_all_in_one_path)
173 cpp_all_in_one_emitter.Emit( 180 cpp_all_in_one_emitter.Emit(
174 self._templates.Load('cpp_all_in_one.template'), 181 self._templates.Load('cpp_all_in_one.template'),
175 INCLUDES=includes_emitter.Fragments()) 182 INCLUDES=includes_emitter.Fragments())
176 183
177 # Generate DartResolver.cpp 184 # Generate DartResolver.cpp.
178 cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp') 185 cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp')
179 186
180 includes_emitter = emitter.Emitter() 187 includes_emitter = emitter.Emitter()
181 resolver_body_emitter = emitter.Emitter() 188 resolver_body_emitter = emitter.Emitter()
182 for file in self._cpp_header_files: 189 for file in self._cpp_header_files:
183 path = os.path.relpath(file, os.path.dirname(cpp_resolver_path)) 190 path = os.path.relpath(file, os.path.dirname(cpp_resolver_path))
184 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 191 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
185 resolver_body_emitter.Emit( 192 resolver_body_emitter.Emit(
186 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n' 193 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu mentCount))\n'
187 ' return func;\n', 194 ' return func;\n',
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 create_function = 'create' 288 create_function = 'create'
282 if 'NamedConstructor' in self._interface.ext_attrs: 289 if 'NamedConstructor' in self._interface.ext_attrs:
283 raises_dart_exceptions = True 290 raises_dart_exceptions = True
284 parameter_definitions_emitter.Emit( 291 parameter_definitions_emitter.Emit(
285 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n' 292 ' DOMWindow* domWindow = DartUtilities::domWindowForCurrentIs olate();\n'
286 ' if (!domWindow) {\n' 293 ' if (!domWindow) {\n'
287 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n' 294 ' exception = Dart_NewString("Failed to fetch domWindow") ;\n'
288 ' goto fail;\n' 295 ' goto fail;\n'
289 ' }\n' 296 ' }\n'
290 ' Document* document = domWindow->document();\n') 297 ' Document* document = domWindow->document();\n')
298 self._cpp_impl_includes['DOMWindow'] = 1
291 arguments.append('document') 299 arguments.append('document')
292 create_function = 'createForJSConstructor' 300 create_function = 'createForJSConstructor'
293 if 'CallWith' in self._interface.ext_attrs: 301 if 'CallWith' in self._interface.ext_attrs:
294 call_with = self._interface.ext_attrs['CallWith'] 302 call_with = self._interface.ext_attrs['CallWith']
295 if call_with == 'ScriptExecutionContext': 303 if call_with == 'ScriptExecutionContext':
296 raises_dart_exceptions = True 304 raises_dart_exceptions = True
297 parameter_definitions_emitter.Emit( 305 parameter_definitions_emitter.Emit(
298 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n' 306 ' ScriptExecutionContext* context = DartUtilities::scriptExec utionContext();\n'
299 ' if (!context) {\n' 307 ' if (!context) {\n'
300 ' exception = Dart_NewString("Failed to create an object" );\n' 308 ' exception = Dart_NewString("Failed to create an object" );\n'
(...skipping 28 matching lines...) Expand all
329 self._dart_impl_emitter.Emit( 337 self._dart_impl_emitter.Emit(
330 self._templates.Load('dart_implementation.darttemplate'), 338 self._templates.Load('dart_implementation.darttemplate'),
331 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, 339 CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id,
332 MEMBERS=self._members_emitter.Fragments()) 340 MEMBERS=self._members_emitter.Fragments())
333 341
334 self._GenerateCppHeader() 342 self._GenerateCppHeader()
335 343
336 self._cpp_impl_emitter.Emit( 344 self._cpp_impl_emitter.Emit(
337 self._templates.Load('cpp_implementation.template'), 345 self._templates.Load('cpp_implementation.template'),
338 INTERFACE=self._interface.id, 346 INTERFACE=self._interface.id,
339 INCLUDES=''.join(['#include "%s.h"\n' % 347 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes.keys()),
340 k for k in self._cpp_impl_includes.keys()]),
341 CALLBACKS=self._cpp_definitions_emitter.Fragments(), 348 CALLBACKS=self._cpp_definitions_emitter.Fragments(),
342 RESOLVER=self._cpp_resolver_emitter.Fragments()) 349 RESOLVER=self._cpp_resolver_emitter.Fragments())
343 350
344 def _GenerateCppHeader(self): 351 def _GenerateCppHeader(self):
345 webcore_include = self._interface_type_info.webcore_include() 352 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes())
346 if webcore_include:
347 webcore_include = '#include "%s.h"\n' % webcore_include
348 else:
349 webcore_include = ''
350 353
351 if ('CustomToJS' in self._interface.ext_attrs or 354 if ('CustomToJS' in self._interface.ext_attrs or
352 'CustomToJSObject' in self._interface.ext_attrs or 355 'CustomToJSObject' in self._interface.ext_attrs or
353 'PureInterface' in self._interface.ext_attrs or 356 'PureInterface' in self._interface.ext_attrs or
354 'CPPPureInterface' in self._interface.ext_attrs or 357 'CPPPureInterface' in self._interface.ext_attrs or
355 self._interface_type_info.custom_to_dart()): 358 self._interface_type_info.custom_to_dart()):
356 to_dart_value_template = ( 359 to_dart_value_template = (
357 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') 360 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n')
358 else: 361 else:
359 to_dart_value_template = ( 362 to_dart_value_template = (
360 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' 363 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n'
361 '{\n' 364 '{\n'
362 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 365 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
363 '}\n') 366 '}\n')
364 to_dart_value_emitter = emitter.Emitter() 367 to_dart_value_emitter = emitter.Emitter()
365 to_dart_value_emitter.Emit( 368 to_dart_value_emitter.Emit(
366 to_dart_value_template, 369 to_dart_value_template,
367 INTERFACE=self._interface.id, 370 INTERFACE=self._interface.id,
368 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) 371 WEBCORE_CLASS_NAME=self._interface_type_info.native_type())
369 372
370 self._cpp_header_emitter.Emit( 373 self._cpp_header_emitter.Emit(
371 self._templates.Load('cpp_header.template'), 374 self._templates.Load('cpp_header.template'),
372 INTERFACE=self._interface.id, 375 INTERFACE=self._interface.id,
373 WEBCORE_INCLUDE=webcore_include, 376 WEBCORE_INCLUDES=webcore_includes,
374 ADDITIONAL_INCLUDES='',
375 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 377 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
376 TO_DART_VALUE=to_dart_value_emitter.Fragments(), 378 TO_DART_VALUE=to_dart_value_emitter.Fragments(),
377 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) 379 DECLARATIONS=self._cpp_declarations_emitter.Fragments())
378 380
379 def AddAttribute(self, getter, setter): 381 def AddAttribute(self, getter, setter):
380 # FIXME: Dartium does not support attribute event listeners. However, JS 382 # FIXME: Dartium does not support attribute event listeners. However, JS
381 # implementation falls back to them when addEventListener is not available. 383 # implementation falls back to them when addEventListener is not available.
382 # Make sure addEventListener is available in all EventTargets and remove 384 # Make sure addEventListener is available in all EventTargets and remove
383 # this check. 385 # this check.
384 if (getter or setter).type.id == 'EventListener': 386 if (getter or setter).type.id == 'EventListener':
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ' goto fail;\n' 785 ' goto fail;\n'
784 ' }\n', 786 ' }\n',
785 INVOCATION=invocation_template) 787 INVOCATION=invocation_template)
786 788
787 if 'ImplementedBy' in attributes: 789 if 'ImplementedBy' in attributes:
788 arguments.insert(0, 'receiver') 790 arguments.insert(0, 'receiver')
789 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 791 self._cpp_impl_includes[attributes['ImplementedBy']] = 1
790 792
791 return emitter.Format(invocation_template, 793 return emitter.Format(invocation_template,
792 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) 794 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
795
796 def _GenerateCPPIncludes(includes):
797 return ''.join(['#include "%s.h"\n' % i for i in includes])
antonm 2012/03/01 14:25:31 nit: i is usually for index :)
podivilov 2012/03/01 15:36:56 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698