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

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

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | « Source/bindings/core/idl.gypi ('k') | Source/bindings/scripts/scripts.gypi » ('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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 import idl_types 73 import idl_types
74 from idl_types import IdlType 74 from idl_types import IdlType
75 import v8_callback_interface 75 import v8_callback_interface
76 from v8_globals import includes, interfaces 76 from v8_globals import includes, interfaces
77 import v8_interface 77 import v8_interface
78 import v8_private_script_interface
78 import v8_types 79 import v8_types
79 from v8_utilities import capitalize, cpp_name, conditional_string, v8_class_name 80 from v8_utilities import capitalize, cpp_name, conditional_string, v8_class_name
80 81
81 82
82 class CodeGeneratorV8(object): 83 class CodeGeneratorV8(object):
83 def __init__(self, interfaces_info, cache_dir): 84 def __init__(self, interfaces_info, cache_dir):
84 interfaces_info = interfaces_info or {} 85 interfaces_info = interfaces_info or {}
85 self.interfaces_info = interfaces_info 86 self.interfaces_info = interfaces_info
86 self.jinja_env = initialize_jinja_env(cache_dir) 87 self.jinja_env = initialize_jinja_env(cache_dir)
87 88
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 # Set local type info 124 # Set local type info
124 IdlType.set_callback_functions(definitions.callback_functions.keys()) 125 IdlType.set_callback_functions(definitions.callback_functions.keys())
125 IdlType.set_enums((enum.name, enum.values) 126 IdlType.set_enums((enum.name, enum.values)
126 for enum in definitions.enumerations.values()) 127 for enum in definitions.enumerations.values())
127 128
128 # Select appropriate Jinja template and contents function 129 # Select appropriate Jinja template and contents function
129 if interface.is_callback: 130 if interface.is_callback:
130 header_template_filename = 'callback_interface.h' 131 header_template_filename = 'callback_interface.h'
131 cpp_template_filename = 'callback_interface.cpp' 132 cpp_template_filename = 'callback_interface.cpp'
132 generate_contents = v8_callback_interface.generate_callback_interfac e 133 generate_contents = v8_callback_interface.generate_callback_interfac e
134 # Currently private scripts don't have dependencies. Once private script s have dependencies,
135 # we should add them to interface_info.
136 elif 'PrivateScriptInterface' in interface.extended_attributes:
137 header_template_filename = 'private_script_interface.h'
138 cpp_template_filename = 'private_script_interface.cpp'
139 generate_contents = v8_private_script_interface.generate_private_scr ipt_interface
133 else: 140 else:
134 header_template_filename = 'interface.h' 141 header_template_filename = 'interface.h'
135 cpp_template_filename = 'interface.cpp' 142 cpp_template_filename = 'interface.cpp'
136 generate_contents = v8_interface.generate_interface 143 generate_contents = v8_interface.generate_interface
137 header_template = self.jinja_env.get_template(header_template_filename) 144 header_template = self.jinja_env.get_template(header_template_filename)
138 cpp_template = self.jinja_env.get_template(cpp_template_filename) 145 cpp_template = self.jinja_env.get_template(cpp_template_filename)
139 146
140 # Generate contents (input parameters for Jinja) 147 # Generate contents (input parameters for Jinja)
141 template_contents = generate_contents(interface) 148 template_contents = generate_contents(interface)
142 template_contents['code_generator'] = module_pyname 149 template_contents['code_generator'] = module_pyname
143 150
144 # Add includes for interface itself and any dependencies 151 # Add includes for interface itself and any dependencies
145 interface_info = self.interfaces_info[interface_name] 152 interface_info = self.interfaces_info[interface_name]
146 template_contents['header_includes'].add(interface_info['include_path']) 153 if 'PrivateScriptInterface' not in interface.extended_attributes:
154 template_contents['header_includes'].add(interface_info['include_pat h'])
147 template_contents['header_includes'] = sorted(template_contents['header_ includes']) 155 template_contents['header_includes'] = sorted(template_contents['header_ includes'])
148 includes.update(interface_info.get('dependencies_include_paths', [])) 156 includes.update(interface_info.get('dependencies_include_paths', []))
149 template_contents['cpp_includes'] = sorted(includes) 157 template_contents['cpp_includes'] = sorted(includes)
150 158
151 # Render Jinja templates 159 # Render Jinja templates
152 header_text = header_template.render(template_contents) 160 header_text = header_template.render(template_contents)
153 cpp_text = cpp_template.render(template_contents) 161 cpp_text = cpp_template.render(template_contents)
154 return header_text, cpp_text 162 return header_text, cpp_text
155 163
156 164
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 221
214 # Create a dummy file as output for the build system, 222 # Create a dummy file as output for the build system,
215 # since filenames of individual cache files are unpredictable and opaque 223 # since filenames of individual cache files are unpredictable and opaque
216 # (they are hashes of the template path, which varies based on environment) 224 # (they are hashes of the template path, which varies based on environment)
217 with open(dummy_filename, 'w') as dummy_file: 225 with open(dummy_filename, 'w') as dummy_file:
218 pass # |open| creates or touches the file 226 pass # |open| creates or touches the file
219 227
220 228
221 if __name__ == '__main__': 229 if __name__ == '__main__':
222 sys.exit(main(sys.argv)) 230 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « Source/bindings/core/idl.gypi ('k') | Source/bindings/scripts/scripts.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698