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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/code_generator_v8.py

Issue 2029423002: Clean up V8 bindings template code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_attributes.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 # 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 # jinja2 is in chromium's third_party directory. 67 # jinja2 is in chromium's third_party directory.
68 # Insert at 1 so at front to override system libraries, and 68 # Insert at 1 so at front to override system libraries, and
69 # after path[0] == invoking script dir 69 # after path[0] == invoking script dir
70 sys.path.insert(1, third_party_dir) 70 sys.path.insert(1, third_party_dir)
71 import jinja2 71 import jinja2
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 from v8_attributes import attribute_filters
76 import v8_callback_interface 77 import v8_callback_interface
77 import v8_dictionary 78 import v8_dictionary
78 from v8_globals import includes, interfaces 79 from v8_globals import includes, interfaces
79 import v8_interface 80 import v8_interface
80 import v8_types 81 import v8_types
81 import v8_union 82 import v8_union
82 from v8_utilities import capitalize, cpp_name, v8_class_name 83 from v8_utilities import capitalize, cpp_name, unique_by, v8_class_name
83 from utilities import KNOWN_COMPONENTS, idl_filename_to_component, is_valid_comp onent_dependency, is_testing_target, shorten_union_name 84 from utilities import KNOWN_COMPONENTS, idl_filename_to_component, is_valid_comp onent_dependency, is_testing_target, shorten_union_name
84 85
85 86
86 def normalize_and_sort_includes(include_paths): 87 def normalize_and_sort_includes(include_paths):
87 normalized_include_paths = [] 88 normalized_include_paths = []
88 for include_path in include_paths: 89 for include_path in include_paths:
89 match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path)) 90 match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path))
90 if match: 91 if match:
91 include_path = match.group(1) 92 include_path = match.group(1)
92 normalized_include_paths.append(include_path) 93 normalized_include_paths.append(include_path)
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 # Bytecode cache is not concurrency-safe unless pre-cached: 414 # Bytecode cache is not concurrency-safe unless pre-cached:
414 # if pre-cached this is read-only, but writing creates a race condition. 415 # if pre-cached this is read-only, but writing creates a race condition.
415 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 416 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
416 keep_trailing_newline=True, # newline-terminate generated files 417 keep_trailing_newline=True, # newline-terminate generated files
417 lstrip_blocks=True, # so can indent control flow tags 418 lstrip_blocks=True, # so can indent control flow tags
418 trim_blocks=True) 419 trim_blocks=True)
419 jinja_env.filters.update({ 420 jinja_env.filters.update({
420 'blink_capitalize': capitalize, 421 'blink_capitalize': capitalize,
421 'exposed': exposed_if, 422 'exposed': exposed_if,
422 'runtime_enabled': runtime_enabled_if, 423 'runtime_enabled': runtime_enabled_if,
424 'unique_by': unique_by,
423 }) 425 })
426 jinja_env.filters.update(attribute_filters())
424 return jinja_env 427 return jinja_env
425 428
426 429
427 def generate_indented_conditional(code, conditional): 430 def generate_indented_conditional(code, conditional):
428 # Indent if statement to level of original code 431 # Indent if statement to level of original code
429 indent = re.match(' *', code).group(0) 432 indent = re.match(' *', code).group(0)
430 return ('%sif (%s) {\n' % (indent, conditional) + 433 return ('%sif (%s) {\n' % (indent, conditional) +
431 ' %s\n' % '\n '.join(code.splitlines()) + 434 ' %s\n' % '\n '.join(code.splitlines()) +
432 '%s}\n' % indent) 435 '%s}\n' % indent)
433 436
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 470
468 # Create a dummy file as output for the build system, 471 # Create a dummy file as output for the build system,
469 # since filenames of individual cache files are unpredictable and opaque 472 # since filenames of individual cache files are unpredictable and opaque
470 # (they are hashes of the template path, which varies based on environment) 473 # (they are hashes of the template path, which varies based on environment)
471 with open(dummy_filename, 'w') as dummy_file: 474 with open(dummy_filename, 'w') as dummy_file:
472 pass # |open| creates or touches the file 475 pass # |open| creates or touches the file
473 476
474 477
475 if __name__ == '__main__': 478 if __name__ == '__main__':
476 sys.exit(main(sys.argv)) 479 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_attributes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698