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

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

Issue 735983002: IDL: Defer typedef resolution (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 In concrete classes: 84 In concrete classes:
85 * self.code_generator must be set, implementing generate_code() 85 * self.code_generator must be set, implementing generate_code()
86 (returning a list of output code), and 86 (returning a list of output code), and
87 * compile_file() must be implemented (handling output filenames). 87 * compile_file() must be implemented (handling output filenames).
88 """ 88 """
89 __metaclass__ = abc.ABCMeta 89 __metaclass__ = abc.ABCMeta
90 90
91 def __init__(self, output_directory, cache_directory=None, 91 def __init__(self, output_directory, cache_directory=None,
92 code_generator=None, interfaces_info=None, 92 code_generator=None, interfaces_info=None,
93 interfaces_info_filename='', only_if_changed=False, 93 interfaces_info_filename='', component_info=None,
94 target_component=None): 94 only_if_changed=False, target_component=None):
95 """ 95 """
96 Args: 96 Args:
97 interfaces_info: 97 interfaces_info:
98 interfaces_info dict 98 interfaces_info dict
99 (avoids auxiliary file in run-bindings-tests) 99 (avoids auxiliary file in run-bindings-tests)
100 interfaces_info_file: filename of pickled interfaces_info 100 interfaces_info_file: filename of pickled interfaces_info
101 """ 101 """
102 self.cache_directory = cache_directory 102 self.cache_directory = cache_directory
103 self.code_generator = code_generator 103 self.code_generator = code_generator
104 if interfaces_info_filename: 104 if interfaces_info_filename:
105 with open(interfaces_info_filename) as interfaces_info_file: 105 with open(interfaces_info_filename) as interfaces_info_file:
106 interfaces_info = pickle.load(interfaces_info_file) 106 interfaces_info = pickle.load(interfaces_info_file)
107 self.interfaces_info = interfaces_info 107 self.interfaces_info = interfaces_info
108 self.component_info = component_info
108 self.only_if_changed = only_if_changed 109 self.only_if_changed = only_if_changed
109 self.output_directory = output_directory 110 self.output_directory = output_directory
110 self.target_component = target_component 111 self.target_component = target_component
111 self.reader = IdlReader(interfaces_info, cache_directory) 112 self.reader = IdlReader(interfaces_info, cache_directory)
112 113
113 def compile_and_write(self, idl_filename): 114 def compile_and_write(self, idl_filename):
114 interface_name = idl_filename_to_interface_name(idl_filename) 115 interface_name = idl_filename_to_interface_name(idl_filename)
115 definitions = self.reader.read_idl_definitions(idl_filename) 116 definitions = self.reader.read_idl_definitions(idl_filename)
116 target_component = self.target_component or idl_filename_to_component(id l_filename) 117 target_component = self.target_component or idl_filename_to_component(id l_filename)
117 target_definitions = definitions[target_component] 118 target_definitions = definitions[target_component]
118 output_code_list = self.code_generator.generate_code( 119 output_code_list = self.code_generator.generate_code(
119 target_definitions, interface_name) 120 target_definitions, interface_name)
120 for output_path, output_code in output_code_list: 121 for output_path, output_code in output_code_list:
121 write_file(output_code, output_path, self.only_if_changed) 122 write_file(output_code, output_path, self.only_if_changed)
122 123
123 @abc.abstractmethod 124 @abc.abstractmethod
124 def compile_file(self, idl_filename): 125 def compile_file(self, idl_filename):
125 pass 126 pass
126 127
127 128
128 class IdlCompilerV8(IdlCompiler): 129 class IdlCompilerV8(IdlCompiler):
129 def __init__(self, *args, **kwargs): 130 def __init__(self, *args, **kwargs):
130 IdlCompiler.__init__(self, *args, **kwargs) 131 IdlCompiler.__init__(self, *args, **kwargs)
131 self.code_generator = CodeGeneratorV8(self.interfaces_info, 132 self.code_generator = CodeGeneratorV8(self.interfaces_info,
133 self.component_info,
132 self.cache_directory, 134 self.cache_directory,
133 self.output_directory) 135 self.output_directory)
134 136
135 def compile_file(self, idl_filename): 137 def compile_file(self, idl_filename):
136 self.compile_and_write(idl_filename) 138 self.compile_and_write(idl_filename)
137 139
138 140
139 class IdlCompilerDictionaryImpl(IdlCompiler): 141 class IdlCompilerDictionaryImpl(IdlCompiler):
140 def __init__(self, *args, **kwargs): 142 def __init__(self, *args, **kwargs):
141 IdlCompiler.__init__(self, *args, **kwargs) 143 IdlCompiler.__init__(self, *args, **kwargs)
142 self.code_generator = CodeGeneratorDictionaryImpl( 144 self.code_generator = CodeGeneratorDictionaryImpl(
143 self.interfaces_info, self.cache_directory, self.output_directory) 145 self.interfaces_info, self.component_info, self.cache_directory, sel f.output_directory)
144 146
145 def compile_file(self, idl_filename): 147 def compile_file(self, idl_filename):
146 self.compile_and_write(idl_filename) 148 self.compile_and_write(idl_filename)
147 149
148 150
149 def generate_bindings(options, input_filename): 151 def generate_bindings(options, input_filename):
152 with open(options.component_info_file) as component_info_file:
153 component_info = pickle.load(component_info_file)
150 idl_compiler = IdlCompilerV8( 154 idl_compiler = IdlCompilerV8(
151 options.output_directory, 155 options.output_directory,
152 cache_directory=options.cache_directory, 156 cache_directory=options.cache_directory,
153 interfaces_info_filename=options.interfaces_info_file, 157 interfaces_info_filename=options.interfaces_info_file,
158 component_info=component_info,
154 only_if_changed=options.write_file_only_if_changed, 159 only_if_changed=options.write_file_only_if_changed,
155 target_component=options.target_component) 160 target_component=options.target_component)
156 idl_compiler.compile_file(input_filename) 161 idl_compiler.compile_file(input_filename)
157 162
158 163
159 def generate_dictionary_impl(options, input_filename): 164 def generate_dictionary_impl(options, input_filename):
165 with open(options.component_info_file) as component_info_file:
166 component_info = pickle.load(component_info_file)
160 idl_compiler = IdlCompilerDictionaryImpl( 167 idl_compiler = IdlCompilerDictionaryImpl(
161 options.impl_output_directory, 168 options.impl_output_directory,
162 cache_directory=options.cache_directory, 169 cache_directory=options.cache_directory,
163 interfaces_info_filename=options.interfaces_info_file, 170 interfaces_info_filename=options.interfaces_info_file,
171 component_info=component_info,
164 only_if_changed=options.write_file_only_if_changed) 172 only_if_changed=options.write_file_only_if_changed)
165 173
166 idl_filenames = read_idl_files_list_from_file(input_filename) 174 idl_filenames = read_idl_files_list_from_file(input_filename)
167 for idl_filename in idl_filenames: 175 for idl_filename in idl_filenames:
168 idl_compiler.compile_file(idl_filename) 176 idl_compiler.compile_file(idl_filename)
169 177
170 178
171 def generate_union_type_containers(options): 179 def generate_union_type_containers(options):
172 if not (options.interfaces_info_file and options.component_info_file): 180 if not (options.interfaces_info_file and options.component_info_file):
173 raise Exception('Interfaces info is required to generate ' 181 raise Exception('Interfaces info is required to generate '
(...skipping 19 matching lines...) Expand all
193 # dictionary paths. 201 # dictionary paths.
194 generate_dictionary_impl(options, input_filename) 202 generate_dictionary_impl(options, input_filename)
195 generate_union_type_containers(options) 203 generate_union_type_containers(options)
196 else: 204 else:
197 # |input_filename| should be a path of an IDL file. 205 # |input_filename| should be a path of an IDL file.
198 generate_bindings(options, input_filename) 206 generate_bindings(options, input_filename)
199 207
200 208
201 if __name__ == '__main__': 209 if __name__ == '__main__':
202 sys.exit(main()) 210 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698