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

Side by Side Diff: bindings/scripts/code_generator_v8.py

Issue 2786203002: Roll 50: Copied IDLs, PYTHON scripts from WebKit removed deleted files in WebCore (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 from idl_definitions import Visitor 73 from idl_definitions import Visitor
74 import idl_types 74 import idl_types
75 from idl_types import IdlType 75 from idl_types import IdlType
76 import v8_callback_interface 76 import v8_callback_interface
77 import v8_dictionary 77 import v8_dictionary
78 from v8_globals import includes, interfaces 78 from v8_globals import includes, interfaces
79 import v8_interface 79 import v8_interface
80 import v8_types 80 import v8_types
81 import v8_union 81 import v8_union
82 from v8_utilities import capitalize, cpp_name, conditional_string, v8_class_name 82 from v8_utilities import capitalize, cpp_name, v8_class_name
83 from utilities import KNOWN_COMPONENTS, idl_filename_to_component, is_valid_comp onent_dependency, is_testing_target 83 from utilities import KNOWN_COMPONENTS, idl_filename_to_component, is_valid_comp onent_dependency, is_testing_target
84 84
85 85
86 def normalize_and_sort_includes(include_paths):
87 normalized_include_paths = []
88 for include_path in include_paths:
89 match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path))
90 if match:
91 include_path = match.group(1)
92 normalized_include_paths.append(include_path)
93 return sorted(normalized_include_paths)
94
95
86 def render_template(include_paths, header_template, cpp_template, 96 def render_template(include_paths, header_template, cpp_template,
87 template_context, component=None): 97 template_context, component=None):
88 template_context['code_generator'] = module_pyname 98 template_context['code_generator'] = module_pyname
89 99
90 # Add includes for any dependencies 100 # Add includes for any dependencies
91 template_context['header_includes'] = sorted( 101 template_context['header_includes'] = normalize_and_sort_includes(
92 template_context['header_includes']) 102 template_context['header_includes'])
93 103
94 for include_path in include_paths: 104 for include_path in include_paths:
95 if component: 105 if component:
96 dependency = idl_filename_to_component(include_path) 106 dependency = idl_filename_to_component(include_path)
97 assert is_valid_component_dependency(component, dependency) 107 assert is_valid_component_dependency(component, dependency)
98 includes.add(include_path) 108 includes.add(include_path)
99 109
100 template_context['cpp_includes'] = sorted(includes) 110 template_context['cpp_includes'] = normalize_and_sort_includes(includes)
101 111
102 header_text = header_template.render(template_context) 112 header_text = header_template.render(template_context)
103 cpp_text = cpp_template.render(template_context) 113 cpp_text = cpp_template.render(template_context)
104 return header_text, cpp_text 114 return header_text, cpp_text
105 115
106 116
107 def set_global_type_info(info_provider): 117 def set_global_type_info(info_provider):
108 interfaces_info = info_provider.interfaces_info 118 interfaces_info = info_provider.interfaces_info
109 idl_types.set_ancestors(interfaces_info['ancestors']) 119 idl_types.set_ancestors(interfaces_info['ancestors'])
110 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces']) 120 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces'])
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 header_template_filename = 'partial_interface.h' 248 header_template_filename = 'partial_interface.h'
239 cpp_template_filename = 'partial_interface.cpp' 249 cpp_template_filename = 'partial_interface.cpp'
240 interface_name += 'Partial' 250 interface_name += 'Partial'
241 assert component == 'core' 251 assert component == 'core'
242 component = 'modules' 252 component = 'modules'
243 include_paths = interface_info.get('dependencies_other_component_inc lude_paths') 253 include_paths = interface_info.get('dependencies_other_component_inc lude_paths')
244 else: 254 else:
245 header_template_filename = 'interface.h' 255 header_template_filename = 'interface.h'
246 cpp_template_filename = 'interface.cpp' 256 cpp_template_filename = 'interface.cpp'
247 interface_context = v8_interface.interface_context 257 interface_context = v8_interface.interface_context
248 header_template = self.jinja_env.get_template(header_template_filename)
249 cpp_template = self.jinja_env.get_template(cpp_template_filename)
250 258
251 template_context = interface_context(interface) 259 template_context = interface_context(interface)
260 includes.update(interface_info.get('cpp_includes', {}).get(component, se t()))
252 if not interface.is_partial and not is_testing_target(full_path): 261 if not interface.is_partial and not is_testing_target(full_path):
253 template_context['header_includes'].add(self.info_provider.include_p ath_for_export) 262 template_context['header_includes'].add(self.info_provider.include_p ath_for_export)
254 template_context['exported'] = self.info_provider.specifier_for_expo rt 263 template_context['exported'] = self.info_provider.specifier_for_expo rt
255 # Add the include for interface itself 264 # Add the include for interface itself
256 if IdlType(interface_name).is_typed_array: 265 if IdlType(interface_name).is_typed_array:
257 template_context['header_includes'].add('core/dom/DOMTypedArray.h') 266 template_context['header_includes'].add('core/dom/DOMTypedArray.h')
258 elif interface_info['include_path']: 267 elif interface_info['include_path']:
259 template_context['header_includes'].add(interface_info['include_path ']) 268 template_context['header_includes'].add(interface_info['include_path '])
269
270 header_template = self.jinja_env.get_template(header_template_filename)
271 cpp_template = self.jinja_env.get_template(cpp_template_filename)
260 header_text, cpp_text = render_template( 272 header_text, cpp_text = render_template(
261 include_paths, header_template, cpp_template, template_context, 273 include_paths, header_template, cpp_template, template_context,
262 component) 274 component)
263 header_path, cpp_path = self.output_paths(interface_name) 275 header_path, cpp_path = self.output_paths(interface_name)
264 return ( 276 return (
265 (header_path, header_text), 277 (header_path, header_text),
266 (cpp_path, cpp_text), 278 (cpp_path, cpp_text),
267 ) 279 )
268 280
269 def generate_dictionary_code(self, definitions, dictionary_name, 281 def generate_dictionary_code(self, definitions, dictionary_name,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 375
364 # Add UnionTypesCore.h as a dependency when we generate modules union ty pes 376 # Add UnionTypesCore.h as a dependency when we generate modules union ty pes
365 # because we only generate union type containers which are used by both 377 # because we only generate union type containers which are used by both
366 # core and modules in UnionTypesCore.h. 378 # core and modules in UnionTypesCore.h.
367 # FIXME: This is an ad hoc workaround and we need a general way to 379 # FIXME: This is an ad hoc workaround and we need a general way to
368 # handle core <-> modules dependency. 380 # handle core <-> modules dependency.
369 if self.target_component == 'modules': 381 if self.target_component == 'modules':
370 additional_header_includes.append( 382 additional_header_includes.append(
371 'bindings/core/v8/UnionTypesCore.h') 383 'bindings/core/v8/UnionTypesCore.h')
372 384
373 template_context['header_includes'] = sorted( 385 template_context['header_includes'] = normalize_and_sort_includes(
374 template_context['header_includes'] + additional_header_includes) 386 template_context['header_includes'] + additional_header_includes)
375 387
376 header_text = header_template.render(template_context) 388 header_text = header_template.render(template_context)
377 cpp_text = cpp_template.render(template_context) 389 cpp_text = cpp_template.render(template_context)
378 header_path = posixpath.join(self.output_dir, 390 header_path = posixpath.join(self.output_dir,
379 'UnionTypes%s.h' % capitalized_component) 391 'UnionTypes%s.h' % capitalized_component)
380 cpp_path = posixpath.join(self.output_dir, 392 cpp_path = posixpath.join(self.output_dir,
381 'UnionTypes%s.cpp' % capitalized_component) 393 'UnionTypes%s.cpp' % capitalized_component)
382 return ( 394 return (
383 (header_path, header_text), 395 (header_path, header_text),
384 (cpp_path, cpp_text), 396 (cpp_path, cpp_text),
385 ) 397 )
386 398
387 399
388 def initialize_jinja_env(cache_dir): 400 def initialize_jinja_env(cache_dir):
389 jinja_env = jinja2.Environment( 401 jinja_env = jinja2.Environment(
390 loader=jinja2.FileSystemLoader(templates_dir), 402 loader=jinja2.FileSystemLoader(templates_dir),
391 # Bytecode cache is not concurrency-safe unless pre-cached: 403 # Bytecode cache is not concurrency-safe unless pre-cached:
392 # if pre-cached this is read-only, but writing creates a race condition. 404 # if pre-cached this is read-only, but writing creates a race condition.
393 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 405 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
394 keep_trailing_newline=True, # newline-terminate generated files 406 keep_trailing_newline=True, # newline-terminate generated files
395 lstrip_blocks=True, # so can indent control flow tags 407 lstrip_blocks=True, # so can indent control flow tags
396 trim_blocks=True) 408 trim_blocks=True)
397 jinja_env.filters.update({ 409 jinja_env.filters.update({
398 'blink_capitalize': capitalize, 410 'blink_capitalize': capitalize,
399 'conditional': conditional_if_endif,
400 'exposed': exposed_if, 411 'exposed': exposed_if,
401 'runtime_enabled': runtime_enabled_if, 412 'runtime_enabled': runtime_enabled_if,
402 }) 413 })
403 return jinja_env 414 return jinja_env
404 415
405 416
406 def generate_indented_conditional(code, conditional): 417 def generate_indented_conditional(code, conditional):
407 # Indent if statement to level of original code 418 # Indent if statement to level of original code
408 indent = re.match(' *', code).group(0) 419 indent = re.match(' *', code).group(0)
409 return ('%sif (%s) {\n' % (indent, conditional) + 420 return ('%sif (%s) {\n' % (indent, conditional) +
410 ' %s\n' % '\n '.join(code.splitlines()) + 421 ' %s\n' % '\n '.join(code.splitlines()) +
411 '%s}\n' % indent) 422 '%s}\n' % indent)
412 423
413 424
414 # [Conditional]
415 def conditional_if_endif(code, conditional_string):
416 # Jinja2 filter to generate if/endif directive blocks
417 if not conditional_string:
418 return code
419 return ('#if %s\n' % conditional_string +
420 code +
421 '#endif // %s\n' % conditional_string)
422
423
424 # [Exposed] 425 # [Exposed]
425 def exposed_if(code, exposed_test): 426 def exposed_if(code, exposed_test):
426 if not exposed_test: 427 if not exposed_test:
427 return code 428 return code
428 return generate_indented_conditional(code, 'context && (%s)' % exposed_test) 429 return generate_indented_conditional(code, 'executionContext && (%s)' % expo sed_test)
429 430
430 431
431 # [RuntimeEnabled] 432 # [RuntimeEnabled]
432 def runtime_enabled_if(code, runtime_enabled_function_name): 433 def runtime_enabled_if(code, runtime_enabled_function_name):
433 if not runtime_enabled_function_name: 434 if not runtime_enabled_function_name:
434 return code 435 return code
435 return generate_indented_conditional(code, '%s()' % runtime_enabled_function _name) 436 return generate_indented_conditional(code, '%s()' % runtime_enabled_function _name)
436 437
437 438
438 ################################################################################ 439 ################################################################################
(...skipping 17 matching lines...) Expand all
456 457
457 # Create a dummy file as output for the build system, 458 # Create a dummy file as output for the build system,
458 # since filenames of individual cache files are unpredictable and opaque 459 # since filenames of individual cache files are unpredictable and opaque
459 # (they are hashes of the template path, which varies based on environment) 460 # (they are hashes of the template path, which varies based on environment)
460 with open(dummy_filename, 'w') as dummy_file: 461 with open(dummy_filename, 'w') as dummy_file:
461 pass # |open| creates or touches the file 462 pass # |open| creates or touches the file
462 463
463 464
464 if __name__ == '__main__': 465 if __name__ == '__main__':
465 sys.exit(main(sys.argv)) 466 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « bindings/scripts/aggregate_generated_bindings.py ('k') | bindings/scripts/collect_idls_into_json.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698