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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/generator.py

Issue 1517043004: [mojo] Add typemap and variant support to generators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pickle3
Patch Set: set proper upstream Created 5 years 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 | « mojo/public/tools/bindings/mojom_list_outputs.py ('k') | third_party/mojo/mojo_edk_tests.gyp » ('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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Code shared by the various language-specific code generators.""" 5 """Code shared by the various language-specific code generators."""
6 6
7 from functools import partial 7 from functools import partial
8 import os.path 8 import os.path
9 import re 9 import re
10 10
(...skipping 22 matching lines...) Expand all
33 full_dir = os.path.dirname(full_path) 33 full_dir = os.path.dirname(full_path)
34 fileutil.EnsureDirectoryExists(full_dir) 34 fileutil.EnsureDirectoryExists(full_dir)
35 35
36 # Dump the data to disk. 36 # Dump the data to disk.
37 with open(full_path, "w+") as f: 37 with open(full_path, "w+") as f:
38 f.write(contents) 38 f.write(contents)
39 39
40 class Generator(object): 40 class Generator(object):
41 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all 41 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all
42 # files to stdout. 42 # files to stdout.
43 def __init__(self, module, output_dir=None): 43 def __init__(self, module, output_dir=None, typemap={}, variant=None):
44 self.module = module 44 self.module = module
45 self.output_dir = output_dir 45 self.output_dir = output_dir
46 self.typemap = typemap
47 self.variant = variant
46 48
47 def GetStructsFromMethods(self): 49 def GetStructsFromMethods(self):
48 result = [] 50 result = []
49 for interface in self.module.interfaces: 51 for interface in self.module.interfaces:
50 for method in interface.methods: 52 for method in interface.methods:
51 result.append(self._GetStructFromMethod(method)) 53 result.append(self._GetStructFromMethod(method))
52 if method.response_parameters != None: 54 if method.response_parameters != None:
53 result.append(self._GetResponseStructFromMethod(method)) 55 result.append(self._GetResponseStructFromMethod(method))
54 return result 56 return result
55 57
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return self._AddStructComputedData(False, struct) 138 return self._AddStructComputedData(False, struct)
137 139
138 def _GetResponseStructFromMethod(self, method): 140 def _GetResponseStructFromMethod(self, method):
139 """Converts a method's response_parameters into the fields of a struct.""" 141 """Converts a method's response_parameters into the fields of a struct."""
140 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) 142 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name)
141 struct = mojom.Struct(params_class, module=method.interface.module) 143 struct = mojom.Struct(params_class, module=method.interface.module)
142 for param in method.response_parameters: 144 for param in method.response_parameters:
143 struct.AddField(param.name, param.kind, param.ordinal, 145 struct.AddField(param.name, param.kind, param.ordinal,
144 attributes=param.attributes) 146 attributes=param.attributes)
145 return self._AddStructComputedData(False, struct) 147 return self._AddStructComputedData(False, struct)
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/mojom_list_outputs.py ('k') | third_party/mojo/mojo_edk_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698